CMake - 检查子目录中的CMakeLists.txt是否已成功构建

时间:2016-01-25 12:21:47

标签: build cmake

假设我有一个像这样的简单项目:

main
|-- CMakeLists.txt
|-- sub1
|------ CMakeLists.txt
|------ sub1.cpp
|------ sub1.h
|-- sub2
|------ CMakeLists.txt
|------ sub2.cpp
|------ sub2.h

然后在main/CMakeLists.txt我有

add_subdirectory(sub1) # Build an executable file called exec1
add_subdirectory(sub2) # Build an executable file called exec2
add_custom_target(exec_all DEPENDS exec1 exec2)

如果make exec_allexec1尚未成功构建,是否允许exec2运行?为了更清楚,我希望能够make exec_all,但如果make exec1失败,它仍然会运行并打印出消息说

ERROR: exec1 was not successfully built. exec_all will only run exec2

这在当前的CMake中是否可行,还是相当长的?

1 个答案:

答案 0 :(得分:1)

如果您不想要scrict依赖,那么您不需要使用$('#vendoridpopupp').popup({ history: false }).popup('open'); } 选项。只需创建执行所需操作的脚本并通过DEPENDS选项传递它:

<强> run.sh

COMMAND

<强>的CMakeLists.txt

# Usage: run.sh target [target ...]

for target in $@; do
    if make ${target}; then
        bin/${target} # Expect executables under bin/ directory.
    else
        echo "ERROR: ${target} was not succeffully built. Do not run it"
    fi
done