Closed
Description
This is incorrect behaviour because the Fmt CMakeList.txt could be called as a part of another CMakeLists.txt from parent directory and CMAKE_BUILD_TYPE is shared resource in that case.
You should not change globally visible variables from project potentially called from cmake add_subdirectory
function because it is the task only for the most top level project (the root), but not a child project.
I suggest instead of this:
Line 33 in c21c6b8
# Set the default CMAKE_BUILD_TYPE to Release.
# This should be done before the project command since the latter can set
# CMAKE_BUILD_TYPE itself (it does so for nmake).
if (NOT CMAKE_BUILD_TYPE)
join(doc "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or "
"CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
set(CMAKE_BUILD_TYPE Release CACHE STRING ${doc})
endif ()
Use this:
function(check_CMAKE_BUILD_TYPE_vs_multiconfig)
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT DEFINED GENERATOR_IS_MULTI_CONFIG)
message(FATAL_ERROR "GENERATOR_IS_MULTI_CONFIG must be defined")
endif()
if((NOT GENERATOR_IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE) OR
(GENERATOR_IS_MULTI_CONFIG AND CMAKE_BUILD_TYPE))
message(FATAL_ERROR "CMAKE_BUILD_TYPE variable must not be set in case of a multiconfig generator presence and must be set if not: GENERATOR_IS_MULTI_CONFIG=`${GENERATOR_IS_MULTI_CONFIG}` CMAKE_BUILD_TYPE=`${CMAKE_BUILD_TYPE}`")
endif()
endfunction()
As long as it calls only from the configure step, then it is enough.
The GENERATOR_IS_MULTI_CONFIG
property is available from cmake 3.9+:
https://cmake.org/cmake/help/v3.9/prop_gbl/GENERATOR_IS_MULTI_CONFIG.html
Metadata
Metadata
Assignees
Labels
No labels