Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build several configurations at once with CMake?

Tags:

cmake

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!

like image 333
Alexander K. Avatar asked Mar 05 '11 13:03

Alexander K.


People also ask

What is Cmake_build_type?

Specifies the build type on single-configuration generators (e.g. Makefile Generators or Ninja ). Typical values include Debug , Release , RelWithDebInfo and MinSizeRel , but custom build types can also be defined.

What is CMake default build type?

Build typesDebug (the default build type) Release. RelWithDebInfo (Release with debugging information) MinSizeRel (Release optimized for size)

How do I build and run with CMake?

To build with just cmake change directory into where you want the binaries to be placed. For an in-place build you then run cmake and it will produce a CMakeCache. txt file that contains build options that you can adjust using any text editor.

Is CMake a build system?

CMake is not a build system itself; it generates another system's build files. It supports directory hierarchies and applications that depend on multiple libraries. It is used in conjunction with native build environments such as Make, Qt Creator, Ninja, Android Studio, Apple's Xcode, and Microsoft Visual Studio.


2 Answers

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.

like image 125
Marcus D. Hanwell Avatar answered Sep 27 '22 22:09

Marcus D. Hanwell


(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.

like image 22
Offirmo Avatar answered Sep 27 '22 21:09

Offirmo