Merge pull request #9668 from leoetlino/windows-cmake-fixes

CMake: minor Windows fixes
This commit is contained in:
JMC47 2021-05-14 08:22:11 -04:00 committed by GitHub
commit 16e91172b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 17 deletions

View File

@ -1,7 +1,11 @@
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
foreach(f CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if("${${f}}" MATCHES "/Zi")
string(REGEX REPLACE "/Zi" "/Z7" "${f}" "${${f}}")
endif()
endforeach()
endif()
# The default MSVC flags for Release and RelWithDebInfo are poorly chosen
# (see issue https://gitlab.kitware.com/cmake/cmake/-/issues/20812)
# By default, inlining is disabled for RelWithDebInfo.
# Manually redefine MSVC flags to match Visual Studio defaults
# and ensure that Release builds generate debug info.
foreach(f CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELEASE)
# optimize, define NDEBUG, generate debug info
set(${f} "/O2 /DNDEBUG /Z7")
endforeach()
endif()

View File

@ -124,11 +124,6 @@ if (WIN32)
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
string(APPEND CMAKE_RUNTIME_OUTPUT_DIRECTORY /ARM64)
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif()
# setup CCache
@ -240,6 +235,12 @@ if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
check_and_add_flag(EXCEPTIONS /EHsc)
dolphin_compile_definitions(_DEBUG DEBUG_ONLY)
# Enable function-level linking
add_compile_options(/Gy)
# Generate intrinsic functions
add_compile_options(/Oi)
# Disable buffer security check
add_compile_options(/GS-)
# Enforce C++ standard conforming conversion rules to catch possible bugs
add_compile_options(/permissive-)
# Remove unreferenced inline functions/data to reduce link time and catch bugs
@ -259,6 +260,10 @@ if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
)
string(APPEND CMAKE_EXE_LINKER_FLAGS " /NXCOMPAT")
# Generate debug data
string(APPEND CMAKE_EXE_LINKER_FLAGS " /DEBUG")
# Eliminate dead code and data
string(APPEND CMAKE_EXE_LINKER_FLAGS " /OPT:REF /OPT:ICF")
else()
add_definitions(-D_DEFAULT_SOURCE)
@ -327,10 +332,15 @@ if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
endif()
if(ENABLE_LTO)
check_and_add_flag(LTO -flto)
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
set(CMAKE_AR gcc-ar)
set(CMAKE_RANLIB gcc-ranlib)
if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
add_compile_options(/GL)
string(APPEND CMAKE_EXE_LINKER_FLAGS " /LTCG")
else()
check_and_add_flag(LTO -flto)
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
set(CMAKE_AR gcc-ar)
set(CMAKE_RANLIB gcc-ranlib)
endif()
endif()
endif()
@ -844,6 +854,8 @@ include_directories("${PROJECT_BINARY_DIR}/Source/Core")
#
if(ENABLE_TESTS)
message(STATUS "Using static gtest from Externals")
# Force gtest to link the C runtime dynamically on Windows in order to avoid runtime mismatches.
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(Externals/gtest EXCLUDE_FROM_ALL)
else()
message(STATUS "Unit tests are disabled")

View File

@ -370,6 +370,11 @@ if(WIN32)
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/Data/Sys" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Sys"
)
# Copy license.txt
add_custom_command(TARGET dolphin-emu POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/license.txt" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/license.txt"
)
# Copy qt.conf
add_custom_command(TARGET dolphin-emu POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/qt.conf.win" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/qt.conf"
@ -401,6 +406,9 @@ if(WIN32)
$<IF:$<CONFIG:Debug>,--debug,--release>
--no-translations
--no-compiler-runtime
--no-system-d3d-compiler
--no-angle
--no-opengl-sw
"$<TARGET_FILE:dolphin-emu>"
)
endif()
@ -423,7 +431,11 @@ if(GETTEXT_MSGFMT_EXECUTABLE)
foreach(po ${LINGUAS})
get_filename_component(lang ${po} NAME_WE)
set(mo_dir ${CMAKE_CURRENT_BINARY_DIR}/${lang})
if(WIN32)
set(mo_dir ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Languages/${lang})
else()
set(mo_dir ${CMAKE_CURRENT_BINARY_DIR}/${lang})
endif()
set(mo ${mo_dir}/dolphin-emu.mo)
target_sources(dolphin-emu PRIVATE ${mo})
@ -439,7 +451,6 @@ if(GETTEXT_MSGFMT_EXECUTABLE)
add_custom_command(OUTPUT ${mo}
COMMAND ${CMAKE_COMMAND} -E make_directory ${mo_dir}
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${mo} ${po}
COMMAND ${CMAKE_COMMAND} -E copy ${mo} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Languages/${lang}/dolphin-emu.mo
DEPENDS ${po}
)
else()