CMake: Difference between revisions
holy fucking shit cmake sucks ass what the fuck |
|||
| (4 intermediate revisions by the same user not shown) | |||
| Line 9: | Line 9: | ||
* Release -- optimized, no symbols | * Release -- optimized, no symbols | ||
* MinSizeRel -- optimized for size | * MinSizeRel -- optimized for size | ||
If <tt>CMAKE_BUILD_TYPE</tt> is not provided, none of these is used -- no debugging flags are set, and no optimization flags are set, in a somewhat stunning bit of unexpected behavior. The following snippet will ensure a default, and allow the value to be selected from a set in the gui: | If <tt>CMAKE_BUILD_TYPE</tt> is not provided, none of these is used -- no debugging flags are set, and no optimization flags are set, in a somewhat stunning bit of unexpected behavior. The following snippet will ensure a default of RelWithDebInfo, and allow the value to be selected from a set in the gui: | ||
<pre> | <pre> | ||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") | |||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) | ||
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose build mode." FORCE) | |||
set(CMAKE_BUILD_TYPE " | |||
endif() | endif() | ||
message(STATUS "Requested build mode: ${CMAKE_BUILD_TYPE}") | |||
</pre> | |||
Build types can be added. I thought this might be useful for a <tt>Coverage</tt> target, but I ended up stuffing the coverage flags into <tt>CMAKE_C_FLAGS_DEBUG</tt>/<tt>CMAKE_CXX_FLAGS_DEBUG</tt>. | |||
==Debugging== | |||
Dump all current variables with: | |||
<pre> | |||
get_cmake_property(_variableNames VARIABLES) | |||
list (SORT _variableNames) | |||
foreach (_variableName ${_variableNames}) | |||
message(STATUS "${_variableName}=${${_variableName}}") | |||
endforeach() | |||
</pre> | </pre> | ||
Better yet, <tt>include(CMakePrintHelpers)</tt> to get the useful commands <tt>cmake_print_properties()</tt> and <tt>cmake_print_variables()</tt>. | |||