diff --git a/Externals/imgui/CMakeLists.txt b/Externals/imgui/CMakeLists.txt index b3d48432a1..2b805f7725 100644 --- a/Externals/imgui/CMakeLists.txt +++ b/Externals/imgui/CMakeLists.txt @@ -14,6 +14,5 @@ target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(imgui PRIVATE - common fmt::fmt ) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index d68acaca4f..3017a2abd8 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -72,9 +72,8 @@ if (MSVC) add_compile_options(/external:W0) add_compile_options(/external:templates-) + # Compile PCH add_subdirectory(PCH) - add_definitions(/I${PCH_DIRECTORY}) - add_definitions(/Yu${PCH_PATH}) # Don't include timestamps in binaries add_link_options(/Brepro) diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index e7cc3d88d8..984a143ce9 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -308,3 +308,14 @@ if(UNIX) elseif(WIN32) target_link_libraries(common PRIVATE "-INCLUDE:enableCompatPatches") endif() + +if(MSVC) + # Add precompiled header + # it will propergate down to everything that depends on common + target_link_libraries(common PUBLIC pch) + + # We need to disable PCH for this one file, because it's C and our PCH is C++ + set_source_files_properties( + ${CMAKE_CURRENT_SOURCE_DIR}/ImageC.c + PROPERTIES COMPILE_FLAGS "/Y- /I${CMAKE_SOURCE_DIR}/Source/PCH/nopch") +endif() diff --git a/Source/PCH/CMakeLists.txt b/Source/PCH/CMakeLists.txt index 7346b24dff..aeddfa52f5 100644 --- a/Source/PCH/CMakeLists.txt +++ b/Source/PCH/CMakeLists.txt @@ -1,6 +1,24 @@ +# The PCH that dolphin uses for MSVC is non-standard; +# Instead of having one PCH per module, dolphin has one PCH shared between all modules. +# So we need to implement PCH manually, rather than using the PCH support built into cmake + add_library(pch pch.h pch.cpp) -set(PCH_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -set(PCH_NAME ${PCH.pch}) -target_compile_options(pch PUBLIC /Ycpch.h /Fp${PCH_DIRECTORY}/${PCH_NAME}) + +# pch.cpp should be compiled with the /Yc command, which creates the precompiled header +target_compile_options(pch PRIVATE /Yc"pch.h" /Fo$) + +# /Fp sets the location of the PCH. By forcing it to a fixed location, all modules +# will share this one PCH +target_compile_options(pch PUBLIC /Fp$) + +# 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(pch PUBLIC /Z7 /Gm-) + +# targets which include pch need these compile options +# /Yu - Use precompiled header named "pch.h" +# /FI - Force include "pch.h" at top of every source file +target_compile_options(pch INTERFACE /Yu"pch.h" /FI"pch.h") + # fmt/format.h is included in the PCH target_link_libraries(pch PUBLIC fmt::fmt) diff --git a/Source/PCH/nopch/pch.h b/Source/PCH/nopch/pch.h new file mode 100644 index 0000000000..6b7c4c5b31 --- /dev/null +++ b/Source/PCH/nopch/pch.h @@ -0,0 +1,4 @@ +// dummy include to help with disabling pch for a single file +// cmake doesn't provide a clean way to disable MSVC's force include option + +// So we can just point it at an empty file instead.