summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Mansell <phiren@gmail.com>2023-01-29 22:10:03 +1300
committerScott Mansell <phiren@gmail.com>2023-01-31 23:21:07 +1300
commit6bb2e4d706c4e243badaebfa567c7b3b9dbd6c60 (patch)
tree0a50ed5c79b4dc13a5aa7b00506208fd6ba79e1a
parent854a73dee0c7285b7c138ec3a117d47f7ebe1a2b (diff)
CMake/MSVC: Fix warnings about conflicting /Zi and /Z7
-rw-r--r--CMakeLists.txt4
-rw-r--r--Source/PCH/CMakeLists.txt24
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$<TARGET_FILE_DIR:build_pch>/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 "$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>")
+
+ # Unfortnually, properties don't propagate. So we also set it globally via parent scope
+ set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug,RelWithDebInfo>: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 "$<$<CONFIG:Debug,RelWithDebInfo>:/Z7>")
+ endif()
+endif()
+# Setting /Z7 also requires us to disable minimal rebuilds.
+target_compile_options(build_pch PUBLIC "$<$<CONFIG:Debug,RelWithDebInfo>:/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