A build type indicates a set of compile-time decisions used while compiling your code. For example, whether or not to optimize or to include debug information. A build type or build mode or configuration is popular in Visual Studio, where C++ projects typically have at least two types: Release and Debug.
CMake has build types and follows similar rules. For compiling C++, there are at least 4 build types in CMake: Release, Debug, MinSizeRel and RelWithDebInfo.
- The compile options or rules associated with a build type for a source file of a particular language can be found in
/usr/share/cmake-2.8/Modules/Find*.cmake. For compiled languages like C++, look for the matching compiler in
For C++ code compiled using GNU C++ compiler, see the files
/usr/share/cmake-2.8/Modules/Compiler/GNU.cmakefor the options used during compilation.
When no build type is provided, I found the compilation string to be:
For Release build type, I found the compilation string to be:
g++ -O3 -DNDEBUG /your/code.cpp. Note that assert will be disabled with this build type.
For Debug build type, I found the compilation string to be:
g++ -g /your/code.cpp
You can specify a build type in the
CMakeLists.txtfile. For example:
- You can also specify a build type at the shell. For example:
$ cmake -D CMAKE_BUILD_TYPE=Debug ..
- You can make one of the build types as default, when no build type is provided. For example, to make Release build type as default, add this to
if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif(NOT CMAKE_BUILD_TYPE)
Note: Build types for Visual Studio cannot be set in
CMAKE_BUILD_TYPE or any other method. It can only be set when CMake is invoked or later in the Visual Studio solution.
Tried with: CMake 220.127.116.11 and Ubuntu 14.04