CMake build multiple targets in different build directories(CMake 在不同的构建目录中构建多个目标)
问题描述
我有以下 CMake 结构:
I have the following CMake structure:
CMakelists.txt
toolchain.cmake
folder1
----CMakelists.txt
folder2
----CMakelists.txt
etc..
我的一级 CMakelists.txt 文件包括其他子目录.现在我想为不同的目标构建我的代码.
My first-level CMakelists.txt file includes the other subdirectories. Now I want to build my code for a different target.
手动方式是:
1.
mkdir hostBuild
cd hostBuild
cmake ..
make
2.
mkdir crossBuild
cd crossBuild
cmake .. --DCMAKE_TOOLCHAIN_FILE=toolchain.cmake
make
这个进程有可能自动运行吗?
Is it possible that this process can run automatically?
例如,我只需要在我的第一级运行 cmake .
.
For example, I just have to run cmake .
at my first level.
这样的事情有可能吗?
推荐答案
没有.建议是将您的手动步骤放入 shell 脚本中.
No. The recommendation would be to just put your manual steps into a shell script.
CMake 一次只能处理一个编译器/make 环境(如果你切换编译器你需要一个不同的二进制输出目录).
CMake can only handle one compiler/make environment at a time (if you switch the compiler you need a different binary output directory).
特别是包含 SET(CMAKE_SYSTEM_NAME ...)
的工具链文件确实改变了配置/生成过程的整个结果.
Especially a toolchain file that does contain SET(CMAKE_SYSTEM_NAME ...)
does change the whole outcome of the configuration/generation process.
有关 CMake 所见的详细信息:CMake:在解析文件的顺序是什么(缓存、工具链……)?
For details on what CMake does see: CMake: In which Order are Files parsed (Cache, Toolchain, …)?
你可以在你的 shell 脚本中使用一些 CMake 命令行选项:
And you could make use of some CMake command line options in your shell script:
if [ ! -d hostBuild ]; then
cmake -E make_directory hostBuild
cmake -E chdir hostBuild cmake ..
fi
cmake --build hostBuild
...
这篇关于CMake 在不同的构建目录中构建多个目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CMake 在不同的构建目录中构建多个目标


基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- CString 到 char* 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01