How to build several configurations at once with CMake?

前端 未结 2 1361
独厮守ぢ
独厮守ぢ 2020-12-16 18:43

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

相关标签:
2条回答
  • 2020-12-16 19:22

    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.

    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.

    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.

    0 讨论(0)
  • 2020-12-16 19:43

    (for fellow googlers)

    Be careful of not confusing build types and build configurations.

    If you really mean "build types" such as debug and release and want to build them at the same time, then Cmake FAQ gives an answer : How can I build multiple modes without switching

    Basically it involves using several out-of-source builds.

    0 讨论(0)
提交回复
热议问题