From 3c413e2a31b4fcb6a99dba04669c6a6517b97832 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Sat, 30 Dec 2017 07:33:11 +1100 Subject: GENERATOR_IS_MULTI_CONFIG: Use for multi-config checks in Modules --- Modules/CMakeExpandImportedTargets.cmake | 4 ++++ Modules/CTestTargets.cmake | 3 ++- Modules/DeployQt4.cmake | 6 ++++-- Modules/ExternalProject.cmake | 11 +++++++---- Modules/FindBoost.cmake | 11 ++++++----- Modules/FindCUDA.cmake | 15 +++++++++------ Modules/FindQt4.cmake | 11 ++++++----- Modules/SelectLibraryConfigurations.cmake | 7 ++++--- 8 files changed, 42 insertions(+), 26 deletions(-) diff --git a/Modules/CMakeExpandImportedTargets.cmake b/Modules/CMakeExpandImportedTargets.cmake index ad065f0..21a3065 100644 --- a/Modules/CMakeExpandImportedTargets.cmake +++ b/Modules/CMakeExpandImportedTargets.cmake @@ -50,6 +50,10 @@ function(CMAKE_EXPAND_IMPORTED_TARGETS _RESULT ) endif() if(NOT CEIT_CONFIGURATION) + # Would be better to test GENERATOR_IS_MULTI_CONFIG global property, + # but the documented behavior specifically says we check + # CMAKE_CONFIGURATION_TYPES and fall back to CMAKE_BUILD_TYPE if no + # config types are defined. if(CMAKE_CONFIGURATION_TYPES) list(GET CMAKE_CONFIGURATION_TYPES 0 CEIT_CONFIGURATION) else() diff --git a/Modules/CTestTargets.cmake b/Modules/CTestTargets.cmake index ff9aada..da9bcb0 100644 --- a/Modules/CTestTargets.cmake +++ b/Modules/CTestTargets.cmake @@ -38,7 +38,8 @@ endif() # set(__conf_types "") -if(CMAKE_CONFIGURATION_TYPES) +get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(_isMultiConfig) # We need to pass the configuration type on the test command line. set(__conf_types -C "${CMAKE_CFG_INTDIR}") endif() diff --git a/Modules/DeployQt4.cmake b/Modules/DeployQt4.cmake index 8ada451..28054f8 100644 --- a/Modules/DeployQt4.cmake +++ b/Modules/DeployQt4.cmake @@ -259,7 +259,8 @@ function(install_qt4_plugin_path plugin executable copy installed_plugin_path_va file(MAKE_DIRECTORY "${plugins_path}") file(COPY "${plugin}" DESTINATION "${plugins_path}") else() - if(configurations AND (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)) + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(configurations AND (_isMultiConfig OR CMAKE_BUILD_TYPE)) set(configurations CONFIGURATIONS ${configurations}) else() unset(configurations) @@ -295,7 +296,8 @@ function(install_qt4_plugin plugin executable copy installed_plugin_path_var) set(plugin_debug "${plugin_release}") endif() - if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE) + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(_isMultiConfig OR CMAKE_BUILD_TYPE) install_qt4_plugin_path("${plugin_release}" "${executable}" "${copy}" "${installed_plugin_path_var}_release" "${plugins_dir}" "${component}" "Release|RelWithDebInfo|MinSizeRel") install_qt4_plugin_path("${plugin_debug}" "${executable}" "${copy}" "${installed_plugin_path_var}_debug" "${plugins_dir}" "${component}" "Debug") diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index d284e27..4eea0fb 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -1790,7 +1790,8 @@ function(_ep_get_build_command name step cmd_var) set(cmd "${CMAKE_COMMAND}") endif() set(args --build ".") - if(CMAKE_CONFIGURATION_TYPES) + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(_isMultiConfig) if (CMAKE_CFG_INTDIR AND NOT CMAKE_CFG_INTDIR STREQUAL "." AND NOT CMAKE_CFG_INTDIR MATCHES "\\$") @@ -1815,7 +1816,7 @@ function(_ep_get_build_command name step cmd_var) if("x${step}x" STREQUAL "xTESTx") string(REGEX REPLACE "^(.*/)cmake([^/]*)$" "\\1ctest\\2" cmd "${cmd}") set(args "") - if(CMAKE_CONFIGURATION_TYPES) + if(_isMultiConfig) list(APPEND args -C ${config}) endif() endif() @@ -1955,7 +1956,8 @@ endfunction() # function(_ep_get_configuration_subdir_suffix suffix_var) set(suffix "") - if(CMAKE_CONFIGURATION_TYPES) + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(_isMultiConfig) set(suffix "/${CMAKE_CFG_INTDIR}") endif() set(${suffix_var} "${suffix}" PARENT_SCOPE) @@ -2085,7 +2087,8 @@ function(ExternalProject_Add_Step name step) set_property(SOURCE ${stamp_file} PROPERTY SYMBOLIC 1) set(touch) # Remove any existing stamp in case the option changed in an existing tree. - if(CMAKE_CONFIGURATION_TYPES) + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(_isMultiConfig) foreach(cfg ${CMAKE_CONFIGURATION_TYPES}) string(REPLACE "/${CMAKE_CFG_INTDIR}" "/${cfg}" stamp_file_config "${stamp_file}") file(REMOVE ${stamp_file_config}) diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake index 0786248..a0fd90f 100644 --- a/Modules/FindBoost.cmake +++ b/Modules/FindBoost.cmake @@ -275,13 +275,14 @@ endif() macro(_Boost_ADJUST_LIB_VARS basename) if(Boost_INCLUDE_DIR ) if(Boost_${basename}_LIBRARY_DEBUG AND Boost_${basename}_LIBRARY_RELEASE) - # if the generator supports configuration types then set - # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value - if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE) + # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for + # single-config generators, set optimized and debug libraries + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(_isMultiConfig OR CMAKE_BUILD_TYPE) set(Boost_${basename}_LIBRARY optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG}) else() - # if there are no configuration types and CMAKE_BUILD_TYPE has no value - # then just use the release libraries + # For single-config generators where CMAKE_BUILD_TYPE has no value, + # just use the release libraries set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} ) endif() # FIXME: This probably should be set for both cases diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake index 04b5cf9..24fe301 100644 --- a/Modules/FindCUDA.cmake +++ b/Modules/FindCUDA.cmake @@ -578,12 +578,15 @@ mark_as_advanced( CUDA_SEPARABLE_COMPILATION ) -# Makefile and similar generators don't define CMAKE_CONFIGURATION_TYPES, so we -# need to add another entry for the CMAKE_BUILD_TYPE. We also need to add the -# standerd set of 4 build types (Debug, MinSizeRel, Release, and RelWithDebInfo) -# for completeness. We need run this loop in order to accommodate the addition -# of extra configuration types. Duplicate entries will be removed by -# REMOVE_DUPLICATES. +# Single config generators like Makefiles or Ninja don't usually have +# CMAKE_CONFIGURATION_TYPES defined (but note that it can be defined if set by +# projects or developers). Even CMAKE_BUILD_TYPE might not be defined for +# single config generators (and should not be defined for multi-config +# generators). To ensure we get a complete superset of all possible +# configurations, we combine CMAKE_CONFIGURATION_TYPES, CMAKE_BUILD_TYPE and +# all of the standard configurations, then weed out duplicates with +# list(REMOVE_DUPLICATES). Looping over the unique set then ensures we have +# each configuration-specific set of nvcc flags defined and marked as advanced. set(CUDA_configuration_types ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} Debug MinSizeRel Release RelWithDebInfo) list(REMOVE_DUPLICATES CUDA_configuration_types) foreach(config ${CUDA_configuration_types}) diff --git a/Modules/FindQt4.cmake b/Modules/FindQt4.cmake index 714e4af..a65c533 100644 --- a/Modules/FindQt4.cmake +++ b/Modules/FindQt4.cmake @@ -398,13 +398,14 @@ macro (_QT4_ADJUST_LIB_VARS _camelCaseBasename) # if the release- as well as the debug-version of the library have been found: if (QT_${basename}_LIBRARY_DEBUG AND QT_${basename}_LIBRARY_RELEASE) - # if the generator supports configuration types then set - # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value - if (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE) + # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for + # single-config generators, set optimized and debug libraries + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(_isMultiConfig OR CMAKE_BUILD_TYPE) set(QT_${basename}_LIBRARY optimized ${QT_${basename}_LIBRARY_RELEASE} debug ${QT_${basename}_LIBRARY_DEBUG}) else() - # if there are no configuration types and CMAKE_BUILD_TYPE has no value - # then just use the release libraries + # For single-config generators where CMAKE_BUILD_TYPE has no value, + # just use the release libraries set(QT_${basename}_LIBRARY ${QT_${basename}_LIBRARY_RELEASE} ) endif() set(QT_${basename}_LIBRARIES optimized ${QT_${basename}_LIBRARY_RELEASE} debug ${QT_${basename}_LIBRARY_DEBUG}) diff --git a/Modules/SelectLibraryConfigurations.cmake b/Modules/SelectLibraryConfigurations.cmake index dce6f99..fe3bb00 100644 --- a/Modules/SelectLibraryConfigurations.cmake +++ b/Modules/SelectLibraryConfigurations.cmake @@ -38,11 +38,12 @@ macro( select_library_configurations basename ) set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.") endif() + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND - ( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE ) ) - # if the generator supports configuration types or CMAKE_BUILD_TYPE - # is set, then set optimized and debug options. + ( _isMultiConfig OR CMAKE_BUILD_TYPE ) ) + # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for + # single-config generators, set optimized and debug libraries set( ${basename}_LIBRARY "" ) foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE ) list( APPEND ${basename}_LIBRARY optimized "${_libname}" ) -- cgit v0.12