From a31816c03991d2958d1dcb7b906abfedb066e5c2 Mon Sep 17 00:00:00 2001 From: Gustavo Jose de Sousa Date: Thu, 10 Dec 2015 17:18:27 -0200 Subject: [PATCH] waf: gbenchmark: move cmake configuration to a separate function --- Tools/ardupilotwaf/gbenchmark.py | 72 +++++++++++++++++++------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/Tools/ardupilotwaf/gbenchmark.py b/Tools/ardupilotwaf/gbenchmark.py index 814ce70cb6..831de76c83 100644 --- a/Tools/ardupilotwaf/gbenchmark.py +++ b/Tools/ardupilotwaf/gbenchmark.py @@ -9,6 +9,34 @@ from waflib import Build, Context, Task from waflib.TaskGen import feature, before_method, after_method from waflib.Errors import WafError +def _configure_cmake(ctx, bldnode): + env = ctx.env + my_build_node = bldnode.find_dir(env.GBENCHMARK_BUILD_REL) + if not my_build_node: + bldnode.make_node(env.GBENCHMARK_BUILD_REL).mkdir() + + prefix_node = bldnode.make_node(env.GBENCHMARK_PREFIX_REL) + + cmake_vars = { + 'CMAKE_BUILD_TYPE': 'Release', + 'CMAKE_INSTALL_PREFIX:PATH': prefix_node.abspath(), + } + + cmake_vars = ' '.join("-D%s='%s'" % v for v in cmake_vars.items()) + + cmd = '%s %s %s %s' % ( + env.CMAKE[0], + env.GBENCHMARK_SRC, + cmake_vars, + env.GBENCHMARK_GENERATOR_OPTION + ) + + ctx.cmd_and_log( + cmd, + cwd=env.GBENCHMARK_BUILD, + quiet=Context.BOTH, + ) + def configure(cfg): env = cfg.env env.HAS_GBENCHMARK = False @@ -76,36 +104,22 @@ class gbenchmark_build(Task.Task): if not cmake_lists: bld.fatal('Submodule gbenchmark not initialized, please run configure again') - # Generate build system first, if necessary - my_build_node = bld.bldnode.find_dir(self.env.GBENCHMARK_BUILD_REL) - if not (my_build_node and my_build_node.find_resource('CMakeCache.txt')): - if not my_build_node: - bld.bldnode.make_node(self.env.GBENCHMARK_BUILD_REL).mkdir() - - cmake_vars = { - 'CMAKE_BUILD_TYPE': 'Release', - 'CMAKE_INSTALL_PREFIX:PATH': bld.bldnode.make_node(self.env.GBENCHMARK_PREFIX_REL).abspath(), - } - cmake_vars = ' '.join("-D%s='%s'" % v for v in cmake_vars.items()) - - cmds.append('%s %s %s %s' % ( - self.env.CMAKE[0], - self.env.GBENCHMARK_SRC, - cmake_vars, - self.env.GBENCHMARK_GENERATOR_OPTION - )) - - cmds.append('%s --build %s --target install' % ( - self.env.CMAKE[0], - self.env.GBENCHMARK_BUILD - )) try: - for cmd in cmds: - bld.cmd_and_log( - cmd, - cwd=self.env.GBENCHMARK_BUILD, - quiet=Context.BOTH, - ) + # Generate build system first, if necessary + my_build_node = bld.bldnode.find_dir(self.env.GBENCHMARK_BUILD_REL) + if not (my_build_node and my_build_node.find_resource('CMakeCache.txt')): + _configure_cmake(bld, bld.bldnode) + + # Build gbenchmark + cmd = '%s --build %s --target install' % ( + self.env.CMAKE[0], + self.env.GBENCHMARK_BUILD + ) + bld.cmd_and_log( + cmd, + cwd=self.env.GBENCHMARK_BUILD, + quiet=Context.BOTH, + ) return 0 except WafError as e: print(e)