From 0842ee6d7b3e5f1d5794bded3c3f342b36b350ff Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Tue, 28 Nov 2023 14:15:36 -0800 Subject: [PATCH] build: Make MSVC builds more deterministic to aid caching. (#7213) --- src/CMakeLists.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ac221ad90..d5f22267e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,6 +51,10 @@ if (MSVC) /Zc:throwingNew /GT + # Some flags for more deterministic builds, to aid caching. + /experimental:deterministic + /d1trimfile:"${CMAKE_SOURCE_DIR}" + # External headers diagnostics /experimental:external # Enables the external headers options. This option isn't required in Visual Studio 2019 version 16.10 and later /external:anglebrackets # Treats all headers included by #include
, where the header file is enclosed in angle brackets (< >), as external headers @@ -87,7 +91,8 @@ if (MSVC) # Since MSVC's debugging information is not very deterministic, so we have to disable it # when using ccache or other caching tools - if (CITRA_USE_CCACHE OR CITRA_USE_PRECOMPILED_HEADERS) + if (CMAKE_C_COMPILER_LAUNCHER STREQUAL "ccache" OR CMAKE_CXX_COMPILER_LAUNCHER STREQUAL "ccache" + OR CITRA_USE_PRECOMPILED_HEADERS) # Precompiled headers are deleted if not using /Z7. See https://github.com/nanoant/CMakePCHCompiler/issues/21 add_compile_options(/Z7) else() @@ -98,7 +103,7 @@ if (MSVC) add_compile_options("$<$:/GS->") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG /MANIFEST:NO" CACHE STRING "" FORCE) - set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /MANIFEST:NO /INCREMENTAL:NO /OPT:REF,ICF" CACHE STRING "" FORCE) + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /MANIFEST:NO /INCREMENTAL:NO /OPT:REF,ICF /PDBALTPATH:%_PDB%" CACHE STRING "" FORCE) else() add_compile_options( -Wall