From fce0fdb6dc6d594d77a07a88815c7c1624718fd2 Mon Sep 17 00:00:00 2001 From: sorgts Date: Sun, 16 Aug 2020 14:01:23 +0200 Subject: [PATCH] Fix undesired re-builds after runnning CMake --- CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f9eae3205..398bad57e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -240,6 +240,18 @@ endif() if(ARM64) message("Generating for ARMv8, ${CMAKE_BUILD_TYPE}") endif() + +# It looks like the flags for the selected build type are written to the cache after each run, which causes some of the operations +# below to keep expanding them with the same flags over and over on every run, leading to a rebuild of the majority of the files. +# To work around this, remember the initial state of the variables from the first run and reset the variables to that. +# TODO: Setting the attributes per target would probably be a better solution. +foreach (LANGUAGE C CXX) + foreach (BUILD_TYPE DEBUG MINSIZEREL RELEASE RELWITHDEBINFO) + set(_CMAKE_${LANGUAGE}_FLAGS_${BUILD_TYPE}_INITIAL ${CMAKE_${LANGUAGE}_FLAGS_${BUILD_TYPE}} CACHE STRING "") + set(CMAKE_${LANGUAGE}_FLAGS_${BUILD_TYPE} ${_CMAKE_${LANGUAGE}_FLAGS_${BUILD_TYPE}_INITIAL}) + endforeach() +endforeach() + if(NOT MSVC) if(ANDROID) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")