Skip to content

Commit

Permalink
cmake case-insensitive CMAKE_BUILD_TYPE
Browse files Browse the repository at this point in the history
Refactored to case-insensitive CMAKE_BUILD_TYPE everywhere.
  • Loading branch information
silverqx committed Oct 20, 2023
1 parent b4685e8 commit dfd253d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 5 additions & 1 deletion cmake/CommonModules/CsDebug.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<CONFIG>" "${CMAKE_BUILD_TYPE}" property ${property})
string(REPLACE "<CONFIG>" "${cmakeBuildTypeUpper}" property ${property})

if(property STREQUAL "LOCATION" OR property MATCHES "^LOCATION_"
OR property MATCHES "_LOCATION$")
Expand Down
22 changes: 14 additions & 8 deletions cmake/CommonModules/TinyHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -416,21 +415,28 @@ endfunction()
# Replace /Zi by /Z7 in the CMAKE_<C|CXX>_FLAGS_<CONFIG> 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
Expand Down
6 changes: 3 additions & 3 deletions cmake/Modules/TinyDeployment.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -45,15 +45,15 @@ 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 "$<TARGET_PDB_FILE:${TomExample_target}>" TYPE BIN OPTIONAL)
endif()
endif()

# 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()

Expand Down
4 changes: 4 additions & 0 deletions cmake/Modules/TinyInitDefaultVariables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
21 changes: 14 additions & 7 deletions cmake/TinyPackageConfigHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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
Expand Down Expand Up @@ -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}")
Expand All @@ -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}"
Expand Down

0 comments on commit dfd253d

Please sign in to comment.