使用 cmake 编译组
compilation groups with cmake
我有一个项目,其中编译会产生许多可执行文件。我使用 cmake 来生成生成文件。然后当我说make
,它们都被编译了。我知道我可以使用make target1
来编译所需的目标。但是我想将所有目标分成几组,并能够使用make group_A
来编译目标的子集。如何实现这一点?
该项目是用C++编写的,并在Linux和OSX下开发。
请查看 CMake 文档中的add_custom_target
和add_dependencies
。可以将组添加为自定义目标,并将要构建的目标作为组的依赖项。
http://www.cmake.org/cmake/help/v3.2/command/add_custom_target.htmlhttp://www.cmake.org/cmake/help/v3.2/command/add_dependencies.html
编辑(在@m.s.的评论之后)
你可以做
add_custom_target(<group-name> DEPENDS <target1> <target2> ...)
这里有一个小例子
你好1.cpp
#include <stdio.h>
int main() {
printf("Hello World 1n");
return 0;
}
你好2.cpp
#include <stdio.h>
int main() {
printf("Hello World 2n");
return 0;
}
你好3.cpp
#include <stdio.h>
int main() {
printf("Hello World 3n");
return 0;
}
CMakeList.txt
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(groups_demo)
add_executable(hello1 hello1.cpp)
add_executable(hello2 hello2.cpp)
add_executable(hello3 hello3.cpp)
add_custom_target(hello12 DEPENDS hello1 hello2)
add_custom_target(hello23 DEPENDS hello3 hello2)
add_custom_target(hello13 DEPENDS hello1 hello3)
现在,您可以使用make hello12
来构建hello1
和hello2
相关文章:
- 如何使用CMake编译.proto文件来生成.grpcp.pb.cc和.grpc.pb.h文件
- 用于交叉编译和CMake的预处理器宏的单元测试
- MinGw 无法从 cmake 编译测试文件
- 使用 Makefile 中的头文件编译 Pybind (不使用 cmake)
- GCC,CMake,预编译标头和维护依赖项
- 当我尝试通过 mingw 使用 CMake 和 SFML 库编译项目时出错
- 如何在 CMake 中添加预编译标头用于 Visual Studio 生成器
- C++CMake编译指令与
- 在 CMake 中添加全局编译标志
- 使用 CMake 和 Visual Studio 2019 编译 GLEW?
- 如何使用 CMake 在 android 构建上编译和共享两个 c++ 库
- 在 armhf 上使用 cmake 在 qt 上的编译问题 "Syntax error: wird unexpected (expecting " ) " "
- 使用 cmake 交叉编译 libwebsockets
- CMake 在编译 Google 的 protobuf 示例时找不到 protobuf
- CMake 不编译具有非标准扩展名的文件
- 如何获得CMake Tools以在Visual Studio Code中编译具有C++11(或更高版本)功能的程序?
- 使用cmake交叉编译gRPC
- Microsoft Visual Studio 2019交叉编译CMake库 - 有效,但存在SEG错误
- 如何使用cmake和Visual Studio 2019编译简单的Windows应用程序?
- 编译 cmake 代码时获取"ld: symbol(s) not found for architecture x86_64"