Browse Source
Generator expressions are the only way to distinguish between build types in multi-configuration builds (Visual Studio). This adds generator expressions for some of build type dependent values as a starting point. See a more detailed explanation at: https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#build-specification-with-generator-expressions Notably: > Some buildsystems generated by cmake(1) have a predetermined build-configuration set in the CMAKE_BUILD_TYPE variable. The buildsystem for the IDEs such as Visual Studio and Xcode are generated independent of the build-configuration, and the actual build configuration is not known until build-time. Therefore, code such as > > string(TOLOWER ${CMAKE_BUILD_TYPE} _type) > if (_type STREQUAL debug) > target_compile_definitions(exe1 PRIVATE DEBUG_BUILD) > endif() > > may appear to work for Makefile Generators and Ninja generators, but is not portable to IDE generators.pull/695/head
6 changed files with 90 additions and 60 deletions
@ -0,0 +1,34 @@
|
||||
# Generator expression helpers |
||||
|
||||
macro(GENEX_OPTION name default description) |
||||
set(${name} ${default} CACHE STRING ${description}) |
||||
set_property(CACHE ${name} PROPERTY STRINGS FOR_DEBUG FOR_RELEASE ON OFF) |
||||
endmacro() |
||||
|
||||
# Provide an option that defaults to ON in debug builds. |
||||
macro(DEBUG_OPTION name description) |
||||
GENEX_OPTION(${name} FOR_DEBUG ${description}) |
||||
endmacro() |
||||
|
||||
# Provide an option that defaults to ON in non-debug builds. |
||||
# Note that this applies to Release, RelWithDebInfo, and MinSizeRel. |
||||
macro(RELEASE_OPTION name description) |
||||
GENEX_OPTION(${name} FOR_RELEASE ${description}) |
||||
endmacro() |
||||
|
||||
# Generate a generator expression for the given variable's current value. |
||||
# |
||||
# Supported variable values and what the resulting generator expression will evaluate to: |
||||
# * FOR_DEBUG - 1 in Debug config. |
||||
# * FOR_RELEASE - 1 in non-Debug config (Release, RelWithDebInfo). |
||||
# * Boolean value (TRUE, FALSE, ON, 1, etc) - that value as 0 or 1. |
||||
# |
||||
# Result is set on ${option}_GENEX in the calling scope. |
||||
function(genex_for_option name) |
||||
set(value ${${name}}) |
||||
set( |
||||
${name}_GENEX |
||||
$<IF:$<STREQUAL:${value},FOR_DEBUG>,$<CONFIG:Debug>,$<IF:$<STREQUAL:${value},FOR_RELEASE>,$<NOT:$<CONFIG:Debug>>,$<BOOL:${value}>>> |
||||
PARENT_SCOPE |
||||
) |
||||
endfunction() |
||||
@ -1,4 +0,0 @@
|
||||
#pragma once |
||||
|
||||
#define PROJECT_NAME "@PROJECT_NAME@" |
||||
#define PROJECT_VERSION "@PROJECT_VERSION@@GIT_COMMIT_HASH@" |
||||
Loading…
Reference in new issue