- CMake Cookbook
- Radovan Bast Roberto Di Remigio
- 164字
- 2025-04-04 16:17:17
Switching the build type
The code for this recipe is available at https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-01/recipe-07 and has a C++/C example. The recipe is valid with CMake version 3.5 (and higher) and has been tested on GNU/Linux, macOS, and Windows.
CMake has the notion of build types or configurations, such as Debug, Release, and so forth. Within one configuration, one can collect related options or properties, such as compiler and linker flags, for a Debug or Release build. The variable governing the configuration to be used when generating the build system is CMAKE_BUILD_TYPE. This variable is empty by default, and the values recognized by CMake are:
- Debug for building your library or executable without optimization and with debug symbols,
- Release for building your library or executable with optimization and without debug symbols,
- RelWithDebInfo for building your library or executable with less aggressive optimizations and with debug symbols,
- MinSizeRel for building your library or executable with optimizations that do not increase object code size.