From 10865c8e5f0854699b898a4c9066856906b7a6a6 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Sun, 1 May 2022 18:40:19 +1000 Subject: FetchContent: Hard-code a config for the sub-build If the main project overrides CMAKE_CONFIGURATION_TYPES such that there is no Debug configuration, some multi-config generators can fail because they might assume Debug by default (Visual Studio might do this). Always specify the configuration for multi-config generators so that we don't rely on any such defaults. Fixes: #23177 --- Modules/FetchContent.cmake | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'Modules/FetchContent.cmake') diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake index 7e14756010..e0295373af 100644 --- a/Modules/FetchContent.cmake +++ b/Modules/FetchContent.cmake @@ -1016,6 +1016,14 @@ ExternalProject_Add_Step(${contentName}-populate copyfile list(APPEND subCMakeOpts "-DCMAKE_MAKE_PROGRAM:FILEPATH=${CMAKE_MAKE_PROGRAM}") endif() + # Override the sub-build's configuration types for multi-config generators. + # This ensures we are not affected by any custom setting from the project + # and can always request a known configuration further below. + get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(is_multi_config) + list(APPEND subCMakeOpts "-DCMAKE_CONFIGURATION_TYPES:STRING=Release") + endif() + else() # Likely we've been invoked via CMake's script mode where no # generator is set (and hence CMAKE_MAKE_PROGRAM could not be @@ -1060,7 +1068,8 @@ set_property(GLOBAL PROPERTY _CMAKE_FindGit_GIT_EXECUTABLE_VERSION # If we've already previously done these steps, they will not cause # anything to be updated, so extra rebuilds of the project won't occur. # Make sure to pass through CMAKE_MAKE_PROGRAM in case the main project - # has this set to something not findable on the PATH. + # has this set to something not findable on the PATH. We also ensured above + # that the Release config will be defined for multi-config generators. configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/FetchContent/CMakeLists.cmake.in" "${ARG_SUBBUILD_DIR}/CMakeLists.txt") execute_process( @@ -1076,7 +1085,7 @@ set_property(GLOBAL PROPERTY _CMAKE_FindGit_GIT_EXECUTABLE_VERSION message(FATAL_ERROR "CMake step for ${contentName} failed: ${result}") endif() execute_process( - COMMAND ${CMAKE_COMMAND} --build . + COMMAND ${CMAKE_COMMAND} --build . --config Release RESULT_VARIABLE result ${outputOptions} WORKING_DIRECTORY "${ARG_SUBBUILD_DIR}" -- cgit v1.2.1