cmake added support for cmp0141 with ccache

Added support for the MSVC debug information format flags selected by
an abstraction added in the CMake 3.25 if the compiler launcher is
the ccache.

In the CMake >=3.25 the CMAKE_MSVC_DEBUG_INFORMATION_FORMAT will be
set to the "$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>" if the compiler
launcher is the ccache.

In the CMake <3.25 the old replace /Zi by /Z7 by the build config type
in the CMAKE_C/CXX_FLAGS_DEBUG/RELWITHDEBINFO CMake flags.
This commit is contained in:
silverqx
2022-12-01 16:13:52 +01:00
parent 9d8f9a8489
commit 39e3e6cb6e
2 changed files with 46 additions and 6 deletions
-5
View File
@@ -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"
+46 -1
View File
@@ -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
"$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>"
CACHE BOOL ${help_string} FORCE
)
set(${out_variable} TRUE PARENT_SCOPE)
return()
endif()
endif()
set(${out_variable} FALSE PARENT_SCOPE)
endfunction()