如何使用CMake一次构建多个配置? [英] How to build several configurations at once with CMake?

查看:186
本文介绍了如何使用CMake一次构建多个配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我应该如何构建发布和调试版本在同一时间?我想答案使用缓存变量和某种收集他们。
是从缓存参数获取配置参数的常见方法,isn'it?如果答案是肯定的,我应该如何以最好的方式使用它们的几个集合?
非常感谢!

E.g. how should I build release and debug version at the same time? I guess the answer make use of cache variables and some kind of "collection" of them. Is it common way to get configuration params from cache params, isn'it ? If the answer is yes, how should I use several "collections" of them in a best way ? Thanks a lot!

推荐答案

您不指定您正在讨论的平台。基于Makefile的生成器将仅一次构建一个配置,并且构建多个配置的正常方式是使用单独的构建树,例如。一个用于64位Linux在Intel上,一个用于32位Windows等。大多数CMake项目建议源代码构建,并假设你正确地写你的CMakeLists文件,你可以有〜/ src / YourProject和〜/ build / YourProject -release,〜/ build / YourProject-Debug。

You don't specify the platform you are talking about. The Makefiles based generators will only build one configuration at a time, and the normal way to build several configurations is to use separate build trees, e.g. one for 64-bit Linux on Intel, one for 32-bit Windows, etc. Most CMake projects advise out of source builds, and assuming you wrote your CMakeLists files correctly you could have ~/src/YourProject, and ~/build/YourProject-Release, ~/build/YourProject-Debug.

这是建议的方法,假设你的源代码树没有任何CMakeCache.txt等。然后,您可以在调试目录中运行cmake -DCMAKE_BUILD_TYPE:STRING = Debug〜/ src / YourProject,并且发行版也类似。这有一个优点,你可以指向相关的项目在适当的配置。

This is the advised way to do it, assuming your source tree does not have any CMakeCache.txt etc in it. You can then run cmake -DCMAKE_BUILD_TYPE:STRING=Debug ~/src/YourProject in the debug directory, and similar for the release. This has the advantage that you can point dependent projects at the appropriate configuration.

Boost CMake项目还探索了使用库名称修整构建同一个构建树中的所有配置区分。这可能值得看看是否必须在同一个构建树中构建所有配置。

The Boost CMake project has also explored building all configurations in the same build tree using library name mangling to differentiate. This may be worth looking at if you must build all configurations in the same build tree.

这篇关于如何使用CMake一次构建多个配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆