Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Build types in CMake

📅 2015-May-14 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 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.

$ cmake -D CMAKE_BUILD_TYPE=Debug ..
    set(CMAKE_BUILD_TYPE Release)

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 and Ubuntu 14.04