📅 2015-May-14 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ assert, build type, cmake, debug, release ⬩ 📚 Archive
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 /usr/share/cmake-2.8/Modules/Compiler
directory.
For C++ code compiled using GNU C++ compiler, see the files /usr/share/cmake-2.8/Modules/Compiler/GNU.cmake
for the options used during compilation.
When no build type is provided, I found the compilation string to be: g++ /your/code.cpp
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.txt
file. For example:
set(CMAKE_BUILD_TYPE Release)
$ cmake -D CMAKE_BUILD_TYPE=Debug ..
CMakeLists.txt
: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 CMakeLists.txt
using 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 2.8.12.2 and Ubuntu 14.04