From dfd253d2c594b4d9834c8217dd8855380379d740 Mon Sep 17 00:00:00 2001 From: silverqx Date: Fri, 20 Oct 2023 18:27:28 +0200 Subject: [PATCH] cmake case-insensitive CMAKE_BUILD_TYPE Refactored to case-insensitive CMAKE_BUILD_TYPE everywhere. --- CMakeLists.txt | 2 +- cmake/CommonModules/CsDebug.cmake | 6 +++++- cmake/CommonModules/TinyHelpers.cmake | 22 +++++++++++++------- cmake/Modules/TinyDeployment.cmake | 6 +++--- cmake/Modules/TinyInitDefaultVariables.cmake | 4 ++++ cmake/TinyPackageConfigHelpers.cmake | 21 ++++++++++++------- 6 files changed, 41 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7077f82cd..8b6f2cde3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -502,7 +502,7 @@ if(TOM) endif() if(VERBOSE_CONFIGURE) - if(NOT TINY_IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + if(NOT TINY_IS_MULTI_CONFIG AND NOT TINY_BUILD_TYPE_LOWER STREQUAL "debug") message(STATUS "Disabled debug output and asserts") endif() diff --git a/cmake/CommonModules/CsDebug.cmake b/cmake/CommonModules/CsDebug.cmake index e3321c03f..002ef4404 100644 --- a/cmake/CommonModules/CsDebug.cmake +++ b/cmake/CommonModules/CsDebug.cmake @@ -55,8 +55,12 @@ function(cs_print_target_properties target) message(STATUS "Target properties for '${target}':") + # Don't use the TINY_BUILD_TYPE_UPPER here as this function can be used in contexts where + # the TINY_BUILD_TYPE_UPPER isn't available. + string(TOUPPER "${CMAKE_BUILD_TYPE}" cmakeBuildTypeUpper) + foreach(property ${CMAKE_PROPERTY_LIST}) - string(REPLACE "" "${CMAKE_BUILD_TYPE}" property ${property}) + string(REPLACE "" "${cmakeBuildTypeUpper}" property ${property}) if(property STREQUAL "LOCATION" OR property MATCHES "^LOCATION_" OR property MATCHES "_LOCATION$") diff --git a/cmake/CommonModules/TinyHelpers.cmake b/cmake/CommonModules/TinyHelpers.cmake index 7e1f8a378..11db561c4 100644 --- a/cmake/CommonModules/TinyHelpers.cmake +++ b/cmake/CommonModules/TinyHelpers.cmake @@ -290,16 +290,15 @@ endfunction() # Print a VERBOSE message against which library is project linking function(tiny_print_linking_against target) - if(TINY_IS_MULTI_CONFIG) + # TINY_BUILD_TYPE_UPPER STREQUAL "" means that the CMAKE_BUILD_TYPE was not defined or is empty + if(TINY_IS_MULTI_CONFIG OR TINY_BUILD_TYPE_UPPER STREQUAL "") return() endif() - string(TOUPPER ${CMAKE_BUILD_TYPE} buildType) - if(WIN32 AND BUILD_SHARED_LIBS) - get_target_property(libraryFilepath ${target} IMPORTED_IMPLIB_${buildType}) + get_target_property(libraryFilepath ${target} IMPORTED_IMPLIB_${TINY_BUILD_TYPE_UPPER}) else() - get_target_property(libraryFilepath ${target} IMPORTED_LOCATION_${buildType}) + get_target_property(libraryFilepath ${target} IMPORTED_LOCATION_${TINY_BUILD_TYPE_UPPER}) endif() message(VERBOSE "Linking against ${target} at ${libraryFilepath}") @@ -416,21 +415,28 @@ endfunction() # Replace /Zi by /Z7 in the CMAKE__FLAGS_ option for the CMake <3.25 function(tiny_fix_ccache_msvc_324) + # Nothing to do, multi-configuration generators are not supported + if(TINY_IS_MULTI_CONFIG OR TINY_BUILD_TYPE_LOWER STREQUAL "") + message(STATUS "The ccache compiler launcher is not supported for multi-configuration \ +generators or with undefined CMAKE_BUILD_TYPE on CMake <3.25") + return() + endif() + # Replace /Zi by /Z7 by the build config type, for the CMake <=3.24 - if(CMAKE_BUILD_TYPE STREQUAL "Debug") + if(TINY_BUILD_TYPE_LOWER STREQUAL "debug") tiny_replace_Zi_by_Z7_for(CMAKE_CXX_FLAGS_DEBUG "Flags used by the CXX compiler during DEBUG builds.") tiny_replace_Zi_by_Z7_for(CMAKE_C_FLAGS_DEBUG "Flags used by the C compiler during DEBUG builds.") # This should never happen, but I leave it here because it won't hurt anything - elseif(CMAKE_BUILD_TYPE STREQUAL "Release") + elseif(TINY_BUILD_TYPE_LOWER STREQUAL "release") tiny_replace_Zi_by_Z7_for(CMAKE_CXX_FLAGS_RELEASE "Flags used by the CXX compiler during RELEASE builds.") tiny_replace_Zi_by_Z7_for(CMAKE_C_FLAGS_RELEASE "Flags used by the C compiler during RELEASE builds.") - elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + elseif(TINY_BUILD_TYPE_LOWER STREQUAL "relwithdebinfo") tiny_replace_Zi_by_Z7_for(CMAKE_CXX_FLAGS_RELWITHDEBINFO "Flags used by the CXX compiler during RELWITHDEBINFO builds.") tiny_replace_Zi_by_Z7_for(CMAKE_C_FLAGS_RELWITHDEBINFO diff --git a/cmake/Modules/TinyDeployment.cmake b/cmake/Modules/TinyDeployment.cmake index f6f856d8e..6f89b60c5 100644 --- a/cmake/Modules/TinyDeployment.cmake +++ b/cmake/Modules/TinyDeployment.cmake @@ -21,7 +21,7 @@ function(tiny_install_tinyorm) if(TOM_EXAMPLE AND # Don't install for vcpkg debug build type - NOT (TINY_VCPKG AND CMAKE_BUILD_TYPE STREQUAL "Debug") + NOT (TINY_VCPKG AND TINY_BUILD_TYPE_LOWER STREQUAL "debug") ) install(TARGETS ${TomExample_target} EXPORT TinyOrmTargets RUNTIME) endif() @@ -45,7 +45,7 @@ function(tiny_install_tinyorm) if(TOM_EXAMPLE AND # Don't install for vcpkg debug build type - NOT (TINY_VCPKG AND CMAKE_BUILD_TYPE STREQUAL "Debug") + NOT (TINY_VCPKG AND TINY_BUILD_TYPE_LOWER STREQUAL "debug") ) install(FILES "$" TYPE BIN OPTIONAL) endif() @@ -53,7 +53,7 @@ function(tiny_install_tinyorm) # Do not install Package config, config version, header, doc. and CMake helper files # when installing for VCPKG Debug configuration - if(TINY_VCPKG AND CMAKE_BUILD_TYPE STREQUAL "Debug") + if(TINY_VCPKG AND TINY_BUILD_TYPE_LOWER STREQUAL "debug") return() endif() diff --git a/cmake/Modules/TinyInitDefaultVariables.cmake b/cmake/Modules/TinyInitDefaultVariables.cmake index 6535aaa7a..50cc80a3e 100644 --- a/cmake/Modules/TinyInitDefaultVariables.cmake +++ b/cmake/Modules/TinyInitDefaultVariables.cmake @@ -171,6 +171,10 @@ macro(tiny_init_tiny_variables_pre) # Tom seeders folder for the make:seeder command set(TomSeeders_folder database/seeders) + # Used in STREQUAL comparisons + string(TOLOWER "${CMAKE_BUILD_TYPE}" TINY_BUILD_TYPE_LOWER) + string(TOUPPER "${CMAKE_BUILD_TYPE}" TINY_BUILD_TYPE_UPPER) + get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) set(TINY_IS_MULTI_CONFIG "${isMultiConfig}" CACHE INTERNAL "True when using a multi-configuration generator.") diff --git a/cmake/TinyPackageConfigHelpers.cmake b/cmake/TinyPackageConfigHelpers.cmake index 44541c3b5..0803949b3 100644 --- a/cmake/TinyPackageConfigHelpers.cmake +++ b/cmake/TinyPackageConfigHelpers.cmake @@ -115,6 +115,9 @@ function(tiny_build_type_requirements_install_tree get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) tiny_to_bool(isMultiConfig ${isMultiConfig}) + # Used in STREQUAL comparisons + string(TOLOWER "${CMAKE_BUILD_TYPE}" cmakeBuildTypeLower) + message(DEBUG "isMultiConfig = ${isMultiConfig}") message(DEBUG "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}") message(DEBUG "cvfIsDebugOnly = ${cvfIsDebugOnly}") @@ -138,9 +141,9 @@ function(tiny_build_type_requirements_install_tree # Match Debug builds types for MSVC (linking debug against release # (or vice-versa) cause crashes) - elseif(MSVC AND ((CMAKE_BUILD_TYPE STREQUAL "Debug" + elseif(MSVC AND ((cmakeBuildTypeLower STREQUAL "debug" AND NOT "debug" IN_LIST cvfTargetConfigurations) - OR (NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND cvfIsDebugOnly)) + OR (NOT cmakeBuildTypeLower STREQUAL "debug" AND cvfIsDebugOnly)) ) # Obtain target configurations in printable format tiny_printable_configurations(tinyPrintableConfigurations @@ -180,6 +183,10 @@ function(tiny_build_type_requirements_build_tree get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) tiny_to_bool(isMultiConfig ${isMultiConfig}) + # Used in STREQUAL comparisons + string(TOLOWER "${CMAKE_BUILD_TYPE}" cmakeBuildTypeLower) + string(TOLOWER "${cvf_config_build_type}" cvfConfigBuildTypeLower) + message(DEBUG "isMultiConfig = ${isMultiConfig}") message(DEBUG "cvf_match_buildtree = ${cvf_match_buildtree}") message(DEBUG "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}") @@ -202,11 +209,11 @@ function(tiny_build_type_requirements_build_tree # Or if matching equal build tree was enabled and builds types don't match then # also tag as unsuitable (this is Build tree specific) elseif((cvf_match_buildtree - AND NOT CMAKE_BUILD_TYPE STREQUAL cvf_config_build_type) - OR (MSVC AND ((CMAKE_BUILD_TYPE STREQUAL "Debug" - AND NOT cvf_config_build_type STREQUAL "Debug") - OR (NOT CMAKE_BUILD_TYPE STREQUAL "Debug" - AND cvf_config_build_type STREQUAL "Debug"))) + AND NOT cmakeBuildTypeLower STREQUAL cvfConfigBuildTypeLower) + OR (MSVC AND ((cmakeBuildTypeLower STREQUAL "debug" + AND NOT cvfConfigBuildTypeLower STREQUAL "debug") + OR (NOT cmakeBuildTypeLower STREQUAL "debug" + AND cvfConfigBuildTypeLower STREQUAL "debug"))) ) set(${out_package_version} "${${out_package_version}} single-config CMAKE_BUILD_TYPE=${cvf_config_build_type}"