当我执行“bii cpp:build”时,我希望 bii 首先构建块 B,然后它必须使用一些参数调用块 B 生成的二进制文件,当二进制完成时,bii 应该继续构建块 A。不希望块 A #include 块 B 中的任何内容。本质上,我想在块 A 的构建过程中在 cmake add_custom_command 中使用块 B 的输出。如何实现?
问问题
166 次
1 回答
0
目前,“bii”只允许在同一编译时间构建项目中的所有块,但您可以使用技巧,手动执行修改后的根 CMakeLists.txt。
我假设您的项目布局如下所示:
your_project
|- bii
|- blocks
|- build
|- cmake
| |- CMakeLists.txt # root CMakeLists.txt
|- deps
然后你应该修改那个 CMakeLists.txt:
原始代码
PROJECT( my_project )
cmake_minimum_required(VERSION 3.0)
# inclusion of general biicode macros, biicode.cmake
set(CMAKE_MODULE_PATH "${CMAKE_HOME_DIRECTORY}/cmake"
"${CMAKE_HOME_DIRECTORY}/../blocks"
"${CMAKE_HOME_DIRECTORY}/../deps")
INCLUDE(biicode.cmake)
ADD_DEFINITIONS(-DBIICODE)
SET(BIICODE_ENV_DIR C:/Users/Usuario/.biicode)
#artifact to allow upstream configurations
BII_PREBUILD_STEP(blocks/fenix/blockA)
BII_PREBUILD_STEP(blocks/fenix/blockB)
enable_testing()
# Inclusion of the blocks affected by the build
BII_INCLUDE_BLOCK(blocks/fenix/blockA)
BII_INCLUDE_BLOCK(blocks/fenix/blockB)
用这个替换它:
新代码
PROJECT( my_project )
cmake_minimum_required(VERSION 3.0)
# inclusion of general biicode macros, biicode.cmake
set(CMAKE_MODULE_PATH "${CMAKE_HOME_DIRECTORY}/cmake"
"${CMAKE_HOME_DIRECTORY}/../blocks"
"${CMAKE_HOME_DIRECTORY}/../deps")
INCLUDE(biicode.cmake)
ADD_DEFINITIONS(-DBIICODE)
SET(BIICODE_ENV_DIR C:/Users/Usuario/.biicode)
enable_testing()
IF(BUILD_BLOCK_A)
BII_PREBUILD_STEP(blocks/fenix/blockA)
BII_INCLUDE_BLOCK(blocks/fenix/blockA)
ELSEIF(BUILD_BLOCK_B)
BII_PREBUILD_STEP(blocks/fenix/blockB)
BII_INCLUDE_BLOCK(blocks/fenix/blockB)
ENDIF()
因此,删除your_project/build文件夹,创建一个新的空文件夹并执行(我的操作系统是 Windows,我正在使用“MinGW Makefiles”生成器):
your_project$ cd build
your_project/build$ cmake -G "MinGW Makefiles" -DBUILD_BLOCK_B=1 ../cmake
your_project/build$ cmake --build .
your_project/build$ ../bin/your_blockB_executable -your_additional_flags
然后,删除并再次创建它并构建以下块A:
your_project/build$ cmake -G "MinGW Makefiles" -DBUILD_BLOCK_A=1 ../cmake
your_project/build$ cmake --build .
your_project/build$ ../bin/your_blockA_executable
我希望它对你有帮助!;)
于 2015-01-18T17:11:24.820 回答