From fd475589a51fadab8919acd9d30d6e02ad07e824 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 14 May 2020 09:27:27 +0200 Subject: [PATCH] Build : Adjust compiler flags for debug builds buildcache requires compiler flag /Z7 to be set for MSVC. Adjust these flags to be able to use caching for debug builds. --- CMakeLists.txt | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fb2c69ce7..921afef16e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,5 @@ cmake_minimum_required (VERSION 2.8.12) -################################################################################ -# buildcache -# -# buildcache will be used if found in path -################################################################################ -find_program(buildcache_program buildcache) -if(buildcache_program) - set(CMAKE_CXX_COMPILER_LAUNCHER "${buildcache_program}") - message( STATUS "Found buildcache from : ${buildcache_program}" ) -else() - message( STATUS "No buildcache found" ) -endif() - include (CheckCSourceCompiles) project (ResInsight) @@ -200,6 +187,36 @@ 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") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Z7") + endif() +else() + message( STATUS "No buildcache found" ) +endif() + ################################################################################ # HDF5 ################################################################################