From 6bb2e4d706c4e243badaebfa567c7b3b9dbd6c60 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sun, 29 Jan 2023 22:10:03 +1300 Subject: [PATCH] CMake/MSVC: Fix warnings about conflicting /Zi and /Z7 --- CMakeLists.txt | 4 ++++ Source/PCH/CMakeLists.txt | 24 ++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dc09a3bb6..d3d05385ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,10 @@ if (POLICY CMP0117) cmake_policy(SET CMP0117 NEW) # MSVC RTTI flag will not be added by default. endif() +if (POLICY CMP0141) + cmake_policy(SET CMP0141 NEW) # MSVC debug information format flags are selected by an abstraction. +endif() + # Minimum OS X version. # This is inserted into the Info.plist as well. set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15.0" CACHE STRING "") diff --git a/Source/PCH/CMakeLists.txt b/Source/PCH/CMakeLists.txt index b1a6595284..50f3fa234b 100644 --- a/Source/PCH/CMakeLists.txt +++ b/Source/PCH/CMakeLists.txt @@ -21,8 +21,28 @@ target_compile_options(build_pch PRIVATE /Ycpch.h) target_compile_options(build_pch PUBLIC /Fp$/dolphin.pch ) # Sharing a PCH breaks pdb files. So we use the /Z7 option to inline the pdb into -# the binary. That also requires us to disable minimal rebuilds. -target_compile_options(build_pch PUBLIC /Z7 /Gm-) +# the binary. However MSVC gets noisy if you set both /Zi and /Z7 +if (POLICY CMP0141) + # CMake 3.25 has a policy that makes us control this somewhat sanely + set_property(TARGET build_pch PROPERTY MSVC_DEBUG_INFORMATION_FORMAT "$<$:Embedded>") + + # Unfortnually, properties don't propagate. So we also set it globally via parent scope + set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$:Embedded>" PARENT_SCOPE) +else() + if (CMAKE_CXX_FLAGS_DEBUG MATCHES "/Zi") + # Otherwise we do an ugly string replace to remove it from FLAGS_DEBUG + string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + + # and also overwrite the version in the parent scope + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" PARENT_SCOPE) + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" PARENT_SCOPE) + + target_compile_options(build_pch PUBLIC "$<$:/Z7>") + endif() +endif() +# Setting /Z7 also requires us to disable minimal rebuilds. +target_compile_options(build_pch PUBLIC "$<$:/Gm->") # To get this working with ninja, we need to tell it that compiling pch.cpp generates an extra output set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/pch.cpp PROPERTIES