Modern CMake is moving towards a target-centric approach, specifying settings using build targets and their properties instead of global settings. Note, however, that what I suggested is in line with that approach. CMAKE_DEBUG_POSTFIX
is not a global setting; it’s an initialiser of a per-target property, simply a shorthand for setting the propeties on many related targets (those in the given subdir tree) at the same time. Its use would look like this:
set(CMAKE_DEBUG_POSTFIX D)
set(CMAKE_RELEASE_POSTFIX R)
set(CMAKE_RELWITHDEBINFO_POSTFIX RD)
add_subdirectory(the3rdPartyLib)
unset(CMAKE_DEBUG_POSTFIX)
unset(CMAKE_RELEASE_POSTFIX)
unset(CMAKE_RELWITHDEBINFO_POSTFIX)
Contrast this with a truly global setting such as CMAKE_CXX_FLAGS
. That is a variable which affects the build directly; its final value affects all targets for which it is in scope, regardless of the value it had when such targets were created. Global settings such as these is what modern CMake is moving away from, and I wholeheartedly support this move to a target-centric approach.