From 649375ae17df107c1ca9c7c1a12dc20cd3f0109b Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 27 Jan 2023 18:31:35 +0100 Subject: [PATCH] CMake: Improve setting of debug info flags for buildcache --- CMakeLists.txt | 64 +++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2988fa79b5..8573951aa8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,6 +96,40 @@ if(RESINSIGHT_USE_OPENMP) endif() endif() +# ############################################################################## +# buildcache +# ############################################################################## +find_program(buildcache_program buildcache) +if(buildcache_program) + set(CMAKE_CXX_COMPILER_LAUNCHER "${buildcache_program}") + message(STATUS "Found buildcache from : ${buildcache_program}") + + if(MSVC) + # New concept for defining MSVC debug info flags introduced in 3.25. + # Evaluate this concept to simplify the setting of CXX-flags + # https://cmake.org/cmake/help/v3.25/prop_tgt/MSVC_DEBUG_INFORMATION_FORMAT.html#prop_tgt:MSVC_DEBUG_INFORMATION_FORMAT + # https://cmake.org/cmake/help/v3.25/policy/CMP0141.html#policy:CMP0141 + + # It is required to use compiler flag /Z7 to be able to use buildcache + # https://github.com/mbitsnbites/buildcache/blob/master/doc/usage.md + # https://learn.microsoft.com/en-us/cpp/build/reference/z7-zi-zi-debug-information-format?view=msvc-170 + + string(REGEX REPLACE "/Zi" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REGEX REPLACE "/Zi" "" CMAKE_CXX_FLAGS_DEBUG + "${CMAKE_CXX_FLAGS_DEBUG}" + ) + string(REGEX REPLACE "/Zi" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO + "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" + ) + + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Z7") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Z7") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Z7") + endif() +else() + message(STATUS "No buildcache found") +endif() + # ############################################################################## # ABAQUS ODB # ############################################################################## @@ -296,36 +330,6 @@ if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") endif() endif() -# ############################################################################## -# buildcache -# -# buildcache will be used if found in path It is required to use compiler flag -# /Zi to be able to use buildcache See -# https://docs.microsoft.com/en-us/cpp/build/reference/z7-zi-zi-debug-information-format?view=vs-2019 -# The adjustments of build flags must also be placed after libecl, as the -# adjustments cause compiler issues for libecl -# ############################################################################## -find_program(buildcache_program buildcache) -if(buildcache_program) - set(CMAKE_CXX_COMPILER_LAUNCHER "${buildcache_program}") - message(STATUS "Found buildcache from : ${buildcache_program}") - - if(MSVC) - string(REGEX REPLACE "/Zi" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - - if(CMAKE_CXX_FLAGS_DEBUG MATCHES "/Zi") - message(STATUS "Clearing pdb setting") - string(REGEX REPLACE "/Zi" "" CMAKE_CXX_FLAGS_DEBUG - "${CMAKE_CXX_FLAGS_DEBUG}" - ) - endif() - - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Z7") - endif() -else() - message(STATUS "No buildcache found") -endif() - # ############################################################################## # HDF5 # ##############################################################################