1 change: 1 addition & 0 deletions Externals/hidapi/CMakeLists.txt
@@ -1,6 +1,7 @@
project(hidapi)

add_library(hidapi STATIC hidapi/hidapi.h)
dolphin_disable_warnings_msvc(hidapi)
target_include_directories(hidapi PUBLIC hidapi)

if(APPLE)
Expand Down
10 changes: 6 additions & 4 deletions Externals/imgui/CMakeLists.txt
@@ -1,6 +1,8 @@
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (NOT MSVC)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()

set(SRCS
imgui.cpp
Expand All @@ -10,10 +12,10 @@ set(SRCS
)

add_library(imgui STATIC ${SRCS})
dolphin_disable_warnings_msvc(imgui)
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")

target_link_libraries(imgui
PRIVATE
common
fmt::fmt
)
1 change: 1 addition & 0 deletions Externals/libiconv-1.14/CMakeLists.txt
Expand Up @@ -7,3 +7,4 @@ set(SRCS lib/iconv.c
)

add_library(iconv STATIC ${SRCS})
dolphin_disable_warnings_msvc(iconv)
1 change: 1 addition & 0 deletions Externals/liblzma/CMakeLists.txt
Expand Up @@ -207,6 +207,7 @@ set(LZMA_SRCS

add_library(lzma STATIC ${LZMA_SRCS} ${LZMA_PUBLIC_HDRS})
add_library(LibLZMA::LibLZMA ALIAS lzma)
dolphin_disable_warnings_msvc(lzma)

target_compile_definitions(lzma PUBLIC LZMA_API_STATIC)

Expand Down
2 changes: 2 additions & 0 deletions Externals/libpng/CMakeLists.txt
Expand Up @@ -39,6 +39,8 @@ add_library(png STATIC
pngwutil.c
)

dolphin_disable_warnings_msvc(png)

option(PNG_HARDWARE_OPTIMIZATIONS "Enable hardware optimizations for libpng" OFF)

if(PNG_HARDWARE_OPTIMIZATIONS)
Expand Down
3 changes: 3 additions & 0 deletions Externals/libusb/CMakeLists.txt
Expand Up @@ -6,6 +6,8 @@ add_library(usb STATIC EXCLUDE_FROM_ALL
libusb/libusb/strerror.c
libusb/libusb/sync.c
)
dolphin_disable_warnings_msvc(usb)

set_target_properties(usb PROPERTIES VERSION 1.0.26)
if(WIN32)
target_include_directories(usb BEFORE PUBLIC libusb/libusb PRIVATE libusb/msvc)
Expand All @@ -26,6 +28,7 @@ if(WIN32 OR CYGWIN)
libusb/libusb/os/windows_common.c
libusb/libusb/os/windows_usbdk.c
libusb/libusb/os/windows_winusb.c
libusb/libusb/os/events_windows.c
)
set(PLATFORM_WINDOWS TRUE)
elseif(APPLE)
Expand Down
1 change: 1 addition & 0 deletions Externals/mGBA/CMakeLists.txt
@@ -1,6 +1,7 @@
set(LIBMGBA_ONLY ON)
set(USE_LZMA ON)
add_subdirectory(mgba EXCLUDE_FROM_ALL)
dolphin_disable_warnings_msvc(mgba)

if(NOT MSVC)
target_compile_options(mgba PRIVATE -Wno-unused-parameter -Wno-unused-result -Wno-unused-variable)
Expand Down
6 changes: 6 additions & 0 deletions Externals/mbedtls/library/CMakeLists.txt
Expand Up @@ -189,28 +189,34 @@ endif()

if(USE_STATIC_MBEDTLS_LIBRARY)
add_library(${mbedcrypto_static_target} STATIC ${src_crypto})
dolphin_disable_warnings_msvc(${mbedcrypto_static_target})
set_target_properties(${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto)
target_link_libraries(${mbedcrypto_static_target} PUBLIC ${libs})

add_library(${mbedx509_static_target} STATIC ${src_x509})
dolphin_disable_warnings_msvc(${mbedx509_static_target})
set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509)
target_link_libraries(${mbedx509_static_target} PUBLIC ${libs} ${mbedcrypto_static_target})

add_library(${mbedtls_static_target} STATIC ${src_tls})
dolphin_disable_warnings_msvc(${mbedtls_static_target})
set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls)
target_link_libraries(${mbedtls_static_target} PUBLIC ${libs} ${mbedx509_static_target})
endif(USE_STATIC_MBEDTLS_LIBRARY)

if(USE_SHARED_MBEDTLS_LIBRARY)
add_library(${mbedcrypto_target} SHARED ${src_crypto})
dolphin_disable_warnings_msvc(${mbedcrypto_target})
set_target_properties(${mbedcrypto_target} PROPERTIES VERSION 2.28.0 SOVERSION 7)
target_link_libraries(${mbedcrypto_target} PUBLIC ${libs})

add_library(${mbedx509_target} SHARED ${src_x509})
dolphin_disable_warnings_msvc(${mbedx509_target})
set_target_properties(${mbedx509_target} PROPERTIES VERSION 2.28.0 SOVERSION 1)
target_link_libraries(${mbedx509_target} PUBLIC ${libs} ${mbedcrypto_target})

add_library(${mbedtls_target} SHARED ${src_tls})
dolphin_disable_warnings_msvc(${mbedtls_target})
set_target_properties(${mbedtls_target} PROPERTIES VERSION 2.28.0 SOVERSION 14)
target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target})
endif(USE_SHARED_MBEDTLS_LIBRARY)
Expand Down
1 change: 1 addition & 0 deletions Externals/miniupnpc/CMakeLists.txt
Expand Up @@ -33,6 +33,7 @@ set(SRCS src/igd_desc_parse.c
src/receivedata.c)

add_library(miniupnpc STATIC ${SRCS})
dolphin_disable_warnings_msvc(miniupnpc)
target_include_directories(miniupnpc PUBLIC src)

add_library(Miniupnpc::miniupnpc ALIAS miniupnpc)
1 change: 1 addition & 0 deletions Externals/minizip/CMakeLists.txt
Expand Up @@ -26,6 +26,7 @@ add_library(minizip STATIC
unzip.h
zip.h
)
dolphin_disable_warnings_msvc(minizip)

if (UNIX)
target_sources(minizip PRIVATE
Expand Down
1 change: 1 addition & 0 deletions Externals/pugixml/CMakeLists.txt
Expand Up @@ -35,6 +35,7 @@ if(BUILD_SHARED_LIBS)
else()
add_library(pugixml STATIC ${SOURCES})
endif()
dolphin_disable_warnings_msvc(pugixml)

set_target_properties(pugixml PROPERTIES VERSION 1.8 SOVERSION 1)
get_target_property(PUGIXML_VERSION_STRING pugixml VERSION)
Expand Down
1 change: 1 addition & 0 deletions Externals/soundtouch/CMakeLists.txt
Expand Up @@ -16,4 +16,5 @@ set(SRCS
)

add_library(SoundTouch STATIC ${SRCS})
dolphin_disable_warnings_msvc(SoundTouch)
add_definitions(-w)
1 change: 1 addition & 0 deletions Externals/xxhash/CMakeLists.txt
@@ -1,6 +1,7 @@
project(xxhash C)

add_library(xxhash STATIC xxhash.c)
dolphin_disable_warnings_msvc(xxhash)
target_include_directories(xxhash
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
1 change: 1 addition & 0 deletions Externals/zlib/CMakeLists.txt
Expand Up @@ -86,6 +86,7 @@ set(ZLIB_SRCS
)

add_library(z STATIC ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
dolphin_disable_warnings_msvc(z)
add_library(ZLIB::ZLIB ALIAS z)

target_include_directories(z
Expand Down
1 change: 1 addition & 0 deletions Externals/zstd/CMakeLists.txt
Expand Up @@ -115,6 +115,7 @@ set(ZSTD_SRCS
)

add_library(zstd STATIC ${ZSTD_SRCS} ${ZSTD_PUBLIC_HDRS} ${ZSTD_PRIVATE_HDRS})
dolphin_disable_warnings_msvc(zstd)
add_library(zstd::zstd ALIAS zstd)

target_include_directories(zstd
Expand Down
53 changes: 4 additions & 49 deletions Source/CMakeLists.txt
Expand Up @@ -18,62 +18,17 @@ if(CMAKE_SYSTEM_NAME MATCHES "Windows")
add_definitions(-D_SILENCE_CXX20_OLD_SHARED_PTR_ATOMIC_SUPPORT_DEPRECATION_WARNING)
endif()

if (MSVC)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std:c++latest")
else()
if (NOT MSVC)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if (MSVC)
# TODO: Use https://cmake.org/cmake/help/latest/policy/CMP0092.html instead (once we can require CMake >= 3.15)
# Taken from http://www.cmake.org/Wiki/CMake_FAQ#Dynamic_Replace.
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
MAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
# Replaces /W3 with /W4 in defaults (add_compile_options would cause very annoying warnings here)
string(REPLACE "/W3" "/W4" ${flag_var} "${${flag_var}}")
endforeach()

# Disable some warnings
add_compile_options(
/wd4201 # nonstandard extension used : nameless struct/union
/wd4127 # conditional expression is constant
/wd4100 # 'identifier' : unreferenced formal parameter
/wd4200 # InputCommon fix temp.
/wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data
/wd4121 # 'symbol' : alignment of a member was sensitive to packing
/wd4324 # Padding was added at the end of a structure because you specified a __declspec(align) value.
/wd4714 # function 'function' marked as __forceinline not inlined
/wd4351 # new behavior: elements of array 'array' will be default initialized
# TODO: Enable this warning once possible
/wd4245 # conversion from 'type1' to 'type2', signed/unsigned mismatch
# Currently jits use some annoying code patterns which makes this common
)

# Additional warnings
add_compile_options(
/w44263 # Non-virtual member function hides base class virtual function
/w44265 # Class has virtual functions, but destructor is not virtual
)

# Treat all warnings as errors
add_compile_options(/WX)

# All files are encoded as UTF-8
add_compile_options(/utf-8)

# Use PCH
# 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)
else()
check_and_add_flag(HAVE_WALL -Wall)
# TODO: would like these but they produce overwhelming amounts of warnings
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/AudioCommon/CMakeLists.txt
Expand Up @@ -83,3 +83,8 @@ PRIVATE
cubeb
SoundTouch
FreeSurround)

if(MSVC)
# Add precompiled header
target_link_libraries(audiocommon PRIVATE use_pch)
endif()
12 changes: 11 additions & 1 deletion Source/Core/Common/CMakeLists.txt
Expand Up @@ -287,7 +287,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_sources(common PUBLIC HRWrap.h HRWrap.cpp)
target_sources(common PRIVATE HRWrap.h HRWrap.cpp)
endif()

if(USE_UPNP)
Expand All @@ -308,3 +308,13 @@ if(UNIX)
elseif(WIN32)
target_link_libraries(common PRIVATE "-INCLUDE:enableCompatPatches")
endif()

if(MSVC)
# Add precompiled header
target_link_libraries(common PRIVATE use_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()
5 changes: 5 additions & 0 deletions Source/Core/Core/CMakeLists.txt
Expand Up @@ -702,3 +702,8 @@ if(UNIX)
MemoryWatcher.h
)
endif()

if(MSVC)
# Add precompiled header
target_link_libraries(core PRIVATE use_pch)
endif()
5 changes: 5 additions & 0 deletions Source/Core/DiscIO/CMakeLists.txt
Expand Up @@ -77,3 +77,8 @@ PRIVATE
pugixml
ZLIB::ZLIB
)

if(MSVC)
# Add precompiled header
target_link_libraries(discio PRIVATE use_pch)
endif()
5 changes: 5 additions & 0 deletions Source/Core/DolphinNoGUI/CMakeLists.txt
Expand Up @@ -26,6 +26,11 @@ PRIVATE
cpp-optparse
)

if(MSVC)
# Add precompiled header
target_link_libraries(dolphin-nogui PRIVATE use_pch)
endif()

if(USE_DISCORD_PRESENCE)
target_compile_definitions(dolphin-nogui PRIVATE -DUSE_DISCORD_PRESENCE)
endif()
Expand Down
21 changes: 17 additions & 4 deletions Source/Core/DolphinQt/CMakeLists.txt
Expand Up @@ -382,9 +382,6 @@ if (WIN32)
endif()

if (MSVC)
# Don't propogate warnings in qt headers to Dolphin
target_compile_options(dolphin-emu PRIVATE /experimental:external)
target_compile_options(dolphin-emu PRIVATE /external:W0)
set(qtGui "")
set(qtGuiPriv "")
set(qtWidgetsPriv "")
Expand All @@ -394,6 +391,15 @@ if (MSVC)
target_compile_options(dolphin-emu PRIVATE "${qtGui}")
target_compile_options(dolphin-emu PRIVATE "${qtGuiPriv}")
target_compile_options(dolphin-emu PRIVATE "${qtWidgets}")

if ("${QT_VERSION_MAJOR}" GREATER_EQUAL 6)
# Qt6 requires RTTI
remove_cxx_flag_from_target(dolphin-emu "/GR-")
target_compile_options(dolphin-emu PRIVATE "/GR")
else()
# Add precompiled header
target_link_libraries(audiocommon PRIVATE use_pch)
endif()
endif()

if(WIN32)
Expand Down Expand Up @@ -430,6 +436,13 @@ if(WIN32)
get_filename_component(QT_BINARY_DIRECTORY "${MOC_EXECUTABLE_LOCATION}" DIRECTORY)
find_program(WINDEPLOYQT_EXE windeployqt HINTS "${QT_BINARY_DIRECTORY}")

if ("${QT_VERSION_MAJOR}" LESS 6)
set(NO_ANGLE_PARAM "--no-angle")
else()
# parameter no longer exists in Qt6
set(NO_ANGLE_PARAM "")
endif()

# Note: We set the PATH for the duration of this command so that the
# deployment application is able to locate the Qt libraries to copy.
# if the necessary paths aren't already set beforehand.
Expand All @@ -452,7 +465,7 @@ if(WIN32)
--no-translations
--no-compiler-runtime
--no-system-d3d-compiler
--no-angle
"${NO_ANGLE_PARAM}"
--no-opengl-sw
"$<TARGET_FILE:dolphin-emu>"
)
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/DolphinTool/CMakeLists.txt
Expand Up @@ -19,5 +19,10 @@ PRIVATE
cpp-optparse
)

if(MSVC)
# Add precompiled header
target_link_libraries(dolphin-tool PRIVATE use_pch)
endif()

set(CPACK_PACKAGE_EXECUTABLES ${CPACK_PACKAGE_EXECUTABLES} dolphin-tool)
install(TARGETS dolphin-tool RUNTIME DESTINATION ${bindir})
5 changes: 5 additions & 0 deletions Source/Core/InputCommon/CMakeLists.txt
Expand Up @@ -205,3 +205,8 @@ if(ENABLE_SDL)
message(STATUS "SDL NOT found, disabling SDL input")
endif()
endif()

if(MSVC)
# Add precompiled header
target_link_libraries(inputcommon PRIVATE use_pch)
endif()
5 changes: 5 additions & 0 deletions Source/Core/UICommon/CMakeLists.txt
Expand Up @@ -68,3 +68,8 @@ if(USE_DISCORD_PRESENCE)
target_compile_definitions(uicommon PRIVATE -DUSE_DISCORD_PRESENCE)
target_link_libraries(uicommon PRIVATE discord-rpc)
endif()

if(MSVC)
# Add precompiled header
target_link_libraries(uicommon PRIVATE use_pch)
endif()
7 changes: 6 additions & 1 deletion Source/Core/UpdaterCommon/CMakeLists.txt
Expand Up @@ -10,4 +10,9 @@ target_link_libraries(updatercommon PRIVATE
ZLIB::ZLIB
ed25519
cpp-optparse
)
)

if(MSVC)
# Add precompiled header
target_link_libraries(updatercommon PRIVATE use_pch)
endif()
5 changes: 5 additions & 0 deletions Source/Core/VideoBackends/D3D/CMakeLists.txt
Expand Up @@ -29,3 +29,8 @@ PUBLIC
videocommon
videod3dcommon
)

if(MSVC)
# Add precompiled header
target_link_libraries(videod3d PRIVATE use_pch)
endif()
5 changes: 5 additions & 0 deletions Source/Core/VideoBackends/D3D12/CMakeLists.txt
Expand Up @@ -35,3 +35,8 @@ PUBLIC
videocommon
videod3dcommon
)

if(MSVC)
# Add precompiled header
target_link_libraries(videod3d12 PRIVATE use_pch)
endif()
5 changes: 5 additions & 0 deletions Source/Core/VideoBackends/D3DCommon/CMakeLists.txt
Expand Up @@ -12,3 +12,8 @@ PUBLIC
common
videocommon
)

if(MSVC)
# Add precompiled header
target_link_libraries(videod3dcommon PRIVATE use_pch)
endif()
5 changes: 5 additions & 0 deletions Source/Core/VideoBackends/Null/CMakeLists.txt
Expand Up @@ -17,3 +17,8 @@ PUBLIC
common
videocommon
)

if(MSVC)
# Add precompiled header
target_link_libraries(videonull PRIVATE use_pch)
endif()
5 changes: 5 additions & 0 deletions Source/Core/VideoBackends/OGL/CMakeLists.txt
Expand Up @@ -33,3 +33,8 @@ PUBLIC
PRIVATE
${X11_LIBRARIES}
)

if(MSVC)
# Add precompiled header
target_link_libraries(videoogl PRIVATE use_pch)
endif()
5 changes: 5 additions & 0 deletions Source/Core/VideoBackends/Software/CMakeLists.txt
Expand Up @@ -41,3 +41,8 @@ PUBLIC
common
videocommon
)

if(MSVC)
# Add precompiled header
target_link_libraries(videosoftware PRIVATE use_pch)
endif()
5 changes: 5 additions & 0 deletions Source/Core/VideoBackends/Vulkan/CMakeLists.txt
Expand Up @@ -62,3 +62,8 @@ SYSTEM PRIVATE
${CMAKE_SOURCE_DIR}/Externals/glslang/SPIRV
${CMAKE_SOURCE_DIR}/Externals/glslang
)

if(MSVC)
# Add precompiled header
target_link_libraries(videovulkan PRIVATE use_pch)
endif()
5 changes: 5 additions & 0 deletions Source/Core/VideoCommon/CMakeLists.txt
Expand Up @@ -180,3 +180,8 @@ if(FFmpeg_FOUND)
)
endif()
endif()

if(MSVC)
# Add precompiled header
target_link_libraries(videocommon PRIVATE use_pch)
endif()
5 changes: 5 additions & 0 deletions Source/Core/WinUpdater/CMakeLists.txt
Expand Up @@ -12,3 +12,8 @@ target_link_libraries(winupdater PRIVATE
)

set_target_properties(winupdater PROPERTIES OUTPUT_NAME "Updater")

if(MSVC)
# Add precompiled header
target_link_libraries(winupdater PRIVATE use_pch)
endif()
47 changes: 42 additions & 5 deletions Source/PCH/CMakeLists.txt
@@ -1,6 +1,43 @@
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})
# 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(build_pch pch.h pch.cpp)

# fmt/format.h is included in the PCH
target_link_libraries(pch PUBLIC fmt::fmt)
target_link_libraries(build_pch PUBLIC fmt::fmt)

# pch.cpp should be compiled with the /Yc command, which creates the precompiled header
target_compile_options(build_pch PRIVATE /Ycpch.h)

# /Fp sets the location of the PCH. By forcing it to a fixed location, all modules
# will share this one PCH. We give it a fixed name so we can depend on it later
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-)

# 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
OBJECT_OUTPUTS $<TARGET_FILE_DIR:build_pch>/dolphin.pch
)

# and then create a custom target that depends on the pch output
# so that ninja won't start building anything that depends on this
# target before the pch is built
add_custom_target(force_build_pch
DEPENDS $<TARGET_FILE_DIR:build_pch>/dolphin.pch
)

# linking against this interface libary will cause targets to enable PCH
add_library(use_pch INTERFACE)
target_link_libraries(use_pch INTERFACE build_pch)

# targets which use the 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(use_pch INTERFACE /Yupch.h /FIpch.h)

# For ninja, we need to depend on force_build_pch
add_dependencies(use_pch force_build_pch)
4 changes: 4 additions & 0 deletions 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.