Skip to content
Permalink
Browse files
Merge pull request #11506 from phire/cmake_fixes
CMake/MSVC fixes
  • Loading branch information
phire committed Jan 31, 2023
2 parents 12431a8 + 5d7643a commit c6b851c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 25 deletions.
@@ -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 "")
@@ -9,10 +9,6 @@
"buildRoot": "${workspaceRoot}\\Build\\${name}",
"cmakeCommandArgs": "",
"variables": [
{
"name": "CMAKE_PREFIX_PATH",
"value": "${workspaceRoot}\\Externals\\Qt\\Qt6.3.0\\x64"
}
]
},
{
@@ -24,10 +20,6 @@
"buildRoot": "${workspaceRoot}\\Build\\${name}",
"cmakeCommandArgs": "",
"variables": [
{
"name": "CMAKE_PREFIX_PATH",
"value": "${workspaceRoot}\\Externals\\Qt\\Qt6.3.0\\x64"
}
]
},
{
@@ -39,10 +31,6 @@
"buildRoot": "${workspaceRoot}\\Build\\${name}",
"cmakeCommandArgs": "",
"variables": [
{
"name": "CMAKE_PREFIX_PATH",
"value": "${workspaceRoot}\\Externals\\Qt\\Qt6.3.0\\ARM64"
},
{
"name": "CMAKE_SYSTEM_NAME",
"value": "Windows"
@@ -62,10 +50,6 @@
"buildRoot": "${workspaceRoot}\\Build\\${name}",
"cmakeCommandArgs": "",
"variables": [
{
"name": "CMAKE_PREFIX_PATH",
"value": "${workspaceRoot}\\Externals\\Qt\\Qt6.3.0\\ARM64"
},
{
"name": "CMAKE_SYSTEM_NAME",
"value": "Windows"
@@ -227,12 +227,14 @@ endif(CMAKE_COMPILER_IS_IAR)

if(CMAKE_COMPILER_IS_MSVC)
# Strictest warnings
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3")
# Dolphin/MSVC: we want to disable all warnings for externals
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3")
endif(CMAKE_COMPILER_IS_MSVC)

if(MBEDTLS_FATAL_WARNINGS)
if(CMAKE_COMPILER_IS_MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
# Dolphin/MSVC: we want to disable all warnings for externals
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
endif(CMAKE_COMPILER_IS_MSVC)

if(CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNU)
@@ -1,6 +1,9 @@
#pragma once

#include <Windows.h>
#include <string>

#include "Common/CommonTypes.h"

namespace WindowsRegistry
{
@@ -4,9 +4,11 @@
#include "Common/CPUDetect.h"

#ifdef _WIN32
#include <windows.h>
#include <processthreadsapi.h>
#endif

#include <algorithm>
#include <cstring>
#include <string>
#include <thread>
@@ -3,11 +3,11 @@ if(POLICY CMP0084)
cmake_policy(SET CMP0084 NEW)
endif()

if (NOT QT_DIR AND MSVC)
if (MSVC)
if(_M_ARM_64)
set(QT_DIR "${CMAKE_SOURCE_DIR}/Externals/Qt/Qt6.3.0/ARM64/lib/cmake/Qt6")
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/Externals/Qt/Qt6.3.0/ARM64")
else()
set(QT_DIR "${CMAKE_SOURCE_DIR}/Externals/Qt/Qt6.3.0/x64/lib/cmake/Qt6")
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/Externals/Qt/Qt6.3.0/x64")
endif()
endif()

@@ -2,6 +2,12 @@
# 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

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

# Uncomment this return to disable PCH
#return()

add_library(build_pch pch.h pch.cpp)

# fmt/format.h is included in the PCH
@@ -15,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
@@ -30,8 +56,7 @@ 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)
# link the pch into anything that depends on use_pch
target_link_libraries(use_pch INTERFACE build_pch)

# targets which use the pch need these compile options

0 comments on commit c6b851c

Please sign in to comment.