scripts: waifulib: cmake: add limited subst feature support
This commit is contained in:
parent
6d00aef398
commit
5516180ed8
1 changed files with 29 additions and 5 deletions
|
@ -70,7 +70,7 @@ as shown below::
|
|||
|
||||
|
||||
from waflib.Build import BuildContext
|
||||
from waflib import Utils, Logs, Context, Errors
|
||||
from waflib import Utils, Logs, Context, Errors, TaskGen
|
||||
|
||||
|
||||
def get_deps(bld, target):
|
||||
|
@ -204,7 +204,7 @@ def export(bld):
|
|||
continue
|
||||
if getattr(tgen, 'cmake_skip', False):
|
||||
continue
|
||||
if set(('c', 'cxx')) & set(getattr(tgen, 'features', [])):
|
||||
if set(('c', 'cxx', 'subst')) & set(getattr(tgen, 'features', [])):
|
||||
loc = tgen.path.relpath().replace('\\', '/')
|
||||
if loc not in cmakes:
|
||||
cmake = CMake(bld, loc)
|
||||
|
@ -215,6 +215,11 @@ def export(bld):
|
|||
for cmake in cmakes.values():
|
||||
cmake.export()
|
||||
|
||||
@TaskGen.feature('subst')
|
||||
@TaskGen.before_method('process_subst')
|
||||
def backup_sources(self):
|
||||
# process_subst removes source list to avoid further processing but we need it
|
||||
self.srces = self.to_nodes(self.source)
|
||||
|
||||
def cleanup(bld):
|
||||
'''Removes all generated makefiles from the *waf* build environment.
|
||||
|
@ -234,7 +239,7 @@ def cleanup(bld):
|
|||
continue
|
||||
if getattr(tgen, 'cmake_skip', False):
|
||||
continue
|
||||
if set(('c', 'cxx')) & set(getattr(tgen, 'features', [])):
|
||||
if set(('c', 'cxx', 'subst')) & set(getattr(tgen, 'features', [])):
|
||||
loc = tgen.path.relpath().replace('\\', '/')
|
||||
CMake(bld, loc).cleanup()
|
||||
|
||||
|
@ -333,6 +338,26 @@ class CMake(object):
|
|||
content = ''
|
||||
name = tgen.get_name()
|
||||
|
||||
# this only covers simple subst case when we have
|
||||
# direct source and target files
|
||||
if 'subst' in tgen.features:
|
||||
if getattr(tgen, 'subst_fun', None):
|
||||
return
|
||||
encoding = getattr(tgen, 'encoding', 'latin-1')
|
||||
re_m4 = getattr(tgen, 're_m4', TaskGen.re_m4)
|
||||
|
||||
targets = Utils.to_list(tgen.target)
|
||||
for x, y in zip(tgen.srces, targets):
|
||||
code = x.read(encoding=encoding)
|
||||
matches = re_m4.findall(code)
|
||||
for var in matches:
|
||||
p = getattr(tgen, var, None)
|
||||
if p is not None:
|
||||
content += 'set(%s \"%s\")\n' % (var, p)
|
||||
content += 'configure_file(%s %s @ONLY)\n\n' % (x.path_from(tgen.path).replace('\\', '/'), y)
|
||||
|
||||
return content
|
||||
|
||||
content += 'set(%s_SRC' % (name.upper())
|
||||
for src in tgen.source:
|
||||
content += '\n %s' % (src.path_from(tgen.path).replace('\\', '/'))
|
||||
|
@ -359,8 +384,7 @@ class CMake(object):
|
|||
content += 'add_executable(%s WIN32 ${%s_SRC})\n' % (
|
||||
name, name.upper())
|
||||
else:
|
||||
content += 'add_executable(%s ${%s_SRC})\n' % (name,
|
||||
name.upper())
|
||||
content += 'add_executable(%s ${%s_SRC})\n' % (name, name.upper())
|
||||
|
||||
elif set(('cshlib', 'cxxshlib')) & set(tgen.features):
|
||||
content += 'add_library(%s SHARED ${%s_SRC})\n\n' % (
|
||||
|
|
Loading…
Add table
Reference in a new issue