Cmake “添加\自定义\目标源”选项将依赖项添加到主\依赖项自定义命令
给定以下CMakeLists.txt和一些任意的hello.c:Cmake “添加\自定义\目标源”选项将依赖项添加到主\依赖项自定义命令,cmake,Cmake,给定以下CMakeLists.txt和一些任意的hello.c: cmake_minimum_required(VERSION 2.6) get_filename_component(debug_rpath ${CMAKE_CURRENT_BINARY_DIR}/hello-debug.exe REALPATH) message(STATUS "debug exe: ${debug_rpath}") get_filename_component(release_rpath ${CMAKE_CU
cmake_minimum_required(VERSION 2.6)
get_filename_component(debug_rpath ${CMAKE_CURRENT_BINARY_DIR}/hello-debug.exe REALPATH)
message(STATUS "debug exe: ${debug_rpath}")
get_filename_component(release_rpath ${CMAKE_CURRENT_BINARY_DIR}/hello-release.exe REALPATH)
message(STATUS "release exe: ${release_rpath}")
add_custom_command(
OUTPUT hello-release.exe
COMMAND clang ${CMAKE_SOURCE_DIR}/hello.c -O3 -o ${release_rpath}
MAIN_DEPENDENCY hello.c
# DEPENDS hello.c
IMPLICIT_DEPENDS hello.c
COMMENT "Compiling release..."
VERBATIM)
add_custom_command(
OUTPUT ${debug_rpath}
COMMAND clang ${CMAKE_SOURCE_DIR}/hello.c -g -DNDEBUG -o ${debug_rpath}
MAIN_DEPENDENCY hello.c
# DEPENDS hello.c
IMPLICIT_DEPENDS hello.c
COMMENT "Compiling debug..."
VERBATIM)
add_custom_target(hello-release ALL
DEPENDS ${release_rpath}
SOURCES hello.c
VERBATIM)
add_custom_target(hello-debug ALL
DEPENDS ${debug_rpath}
SOURCES hello.c
VERBATIM)
debug/release和clangas编译器都是例子,我知道cmake有自己的机制。重要的细节是,我有两个自定义命令使用相同的主输入文件
执行hello调试目标输出:
> mingw32-make hello-debug
[ 50%] Compiling release...
[100%] Compiling debug...
[100%] Built target hello-debug
为什么它还构建发布
取消对源或主依赖项选项的注释只会生成所选的目标。我理解文档,就像这两个选项只影响VisualStudio项目生成一样。我同时使用mingwmakefiles和visualstudio生成器,因此保留SOURCES选项实际上很好。Bug还是我在监督什么?发现了可能相关的问题: