如何使用另一个块作为构建步骤?

时间:2015-01-18 12:30:02

标签: c++ cmake biicode

当我执行" bii cpp:build"时,我希望bii首先构建块B,然后它必须使用一些参数调用块B生成的二进制文件,并且当二进制文件完成时,bii我应该继续构建块A.我不希望块A从块B #include任何东西。本质上我想在块A的构建过程中在cmake add_custom_command中使用块B的输出。这怎么可能是实现?

1 个答案:

答案 0 :(得分: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 Makefile”生成器):

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

然后,再次删除并创建它并构建以下blockA:

your_project/build$ cmake -G "MinGW Makefiles" -DBUILD_BLOCK_A=1 ../cmake
your_project/build$ cmake --build .
your_project/build$ ../bin/your_blockA_executable

我希望它可以帮到你! ;)