How to use a static library created by a custom task?
-
26-06-2021 - |
Question
I want use waf to trigger a makefile to build an other library. For this I created the following task:
def build(bld):
def run(self):
bld_dir = self.generator.bld.path.get_bld()
src_dir = self.inputs[0].parent
tgt = self.outputs[0]
tgt_dir = bld_dir.make_node(os.path.splitext(tgt.name)[0])
cmd = 'BUILDDIR="{tgt_dir}" make config gdb=1 debug=1 cc={cc} && BUILDDIR=" {tgt_dir}" make'.format(
tgt_dir = tgt_dir.abspath(),
cc = self.env.get_flat("CC"))
self.exec_command(cmd, cwd=src_dir.abspath())
return self.exec_command(['cp', lib.abspath(), tgt.abspath()],
cwd=tgt_dir.abspath())
bld(
rule = run,
source = "Makefile",
target = 'metis',
)
How can I tell waf that the task created a static library, so that I can use "metis" in a use keyword:
bld(
features = "cxx cxxprogramm"
source = "main.cpp",
target = 'main',
use = 'metis'
)
Solution
To finally solve the problem I created a on link_task, that basicly does notthing (similar to the fake_lib in ccroot.py):
from waflib.TaskGen import feature, after_method
from waflib.Tools.ccroot import stlink_task
class custom_stlib(stlink_task):
""" Dummy link task """
pass
@feature("custom_stlib")
def custom_lib(self):
self.env['custom_stlib_PATTERN'] = 'lib%s.a'
self.link_task = self.create_task('custom_stlib', [])
self.link_task.add_target(self.target)
def build(bld):
# ...
bld(
features = "cxx custom_stlib",
target = 'metis',
after = "metis_bld",
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow