build - 如何选择哪个 CMake 可执行目标将是默认目标?

我编写了一个 CMakeLists.txt 文件,其中包括 2 个可执行文件(target1target2):

ADD_EXECUTABLE(target1 ${CXX_FILES})
TARGET_LINK_LIBRARIES(target1 ${requiredlibs})

ADD_EXECUTABLE(target2 ${CXX_FILES} ${OTHER_CXX_FILES})
TARGET_LINK_LIBRARIES(target2 ${requiredlibs})

现在每次我在没有任何参数的情况下运行 make 时,都会重建两个目标。但我想将 target1 定义为默认可执行文件,以便在没有任何参数的情况下运行 make 只会构建 target1。为了构建 target2 我会运行 make target2.

这可能吗?

在 CMake 创建的 Makefile 中有如下定义: default_target: 全部

我想我需要一种方法来将此 default_target 设置为 target1

我遇到的另一个问题是 make 总是重建目标,即使没有更改源文件。

最佳答案

执行您要求的示例 CMakeLists.txt:

ADD_EXECUTABLE(target1 a.c)

ADD_EXECUTABLE(target2 EXCLUDE_FROM_ALL b.c)

对我来说,如果源文件未更改(或修改时间未更改),它不会重建目标。我得到的输出:

$ make -f Makefile 
Scanning dependencies of target target1
[100%] Building C object CMakeFiles/target1.dir/a.c.o
Linking C executable target1
[100%] Built target target1
[$ make -f Makefile 
[100%] Built target target1

请注意,第二个 make 不会重建任何内容。

(您可以阅读 CMake manual 了解此类信息)

https://stackoverflow.com/questions/10248342/

相关文章:

build - 在下游项目之前触发上游项目构建

build - 如何自动运行参数化的 Jenkins 作业

ios - 此构建在 https ://itunesconnect. apple.com 上无效

ios - Xcode 4 - 专用配置设置 : build settings and scheme

ant - 如何在项目之间最好地共享 Ant 目标?

iphone - Xcode:为不同的构建配置设置 GCC_PREPROCESSOR_DEFINIT

build - 有人有使用 Gradle 构建 Eclipse RCP 应用程序的经验吗?

android - 构建错误 : Ice cream sandwich emulator on Ub

java - 无法解析不同风格android studio的方法 'getAllUserGroupB

.net - 同时面向 .NET 3.5 和 Silverlight