diff --git a/CMakeLists.txt b/CMakeLists.txt index 02eac468f..1e0a241cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,11 +3,6 @@ # 3.22 - because is used CMP0127: cmake_dependent_option() supports full Condition Syntax cmake_minimum_required(VERSION 3.22...3.25 FATAL_ERROR) -# My logic doesn't work well with this new msvc debug info related policy, so force old -# until I fix it, currently, with the new it doesn't add the /Z7 to the CXX compiler flags -# so ccache will miss every time. -cmake_policy(SET CMP0141 OLD) - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CommonModules" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" diff --git a/cmake/CommonModules/TinyHelpers.cmake b/cmake/CommonModules/TinyHelpers.cmake index 664fb4fb2..0cfcbeaaa 100644 --- a/cmake/CommonModules/TinyHelpers.cmake +++ b/cmake/CommonModules/TinyHelpers.cmake @@ -378,13 +378,27 @@ function(tiny_fix_ccache) set(CMAKE_DISABLE_PRECOMPILE_HEADERS ON CACHE BOOL ${help_string} FORCE) endif() - # Replace /Zi by /Z7 by the build config type + # Below fixes are only needed for the MSVC + if(NOT MSVC) + return() + endif() + + # Support the MSVC debug information format flags selected by an abstraction added + # in the CMake 3.25. + set(wasCcacheFixed FALSE) + tiny_fix_ccache_msvc_325(wasCcacheFixed) + if(wasCcacheFixed) + return() + endif() + + # Replace /Zi by /Z7 by the build config type, for the CMake <=3.24 if(CMAKE_BUILD_TYPE 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") tiny_replace_Zi_by_Z7_for(CMAKE_CXX_FLAGS_RELEASE "Flags used by the CXX compiler during RELEASE builds.") @@ -399,3 +413,34 @@ function(tiny_fix_ccache) endif() endfunction() + +# Support the MSVC debug information format flags selected by an abstraction added +# in the CMake 3.25. +function(tiny_fix_ccache_msvc_325 out_variable) + + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.25") + + cmake_policy(GET CMP0141 policy_cmp0141) + if(policy_cmp0141 STREQUAL "NEW") + get_property(help_string CACHE CMAKE_MSVC_DEBUG_INFORMATION_FORMAT + PROPERTY HELPSTRING + ) + if(NOT help_string) + set(help_string + "Default value for MSVC_DEBUG_INFORMATION_FORMAT of targets." + ) + endif() + + set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT + "$<$:Embedded>" + CACHE BOOL ${help_string} FORCE + ) + + set(${out_variable} TRUE PARENT_SCOPE) + return() + endif() + endif() + + set(${out_variable} FALSE PARENT_SCOPE) + +endfunction()