From 20cc2d72671948ec47014ba1998c67d62f8b17e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BF=8A=E5=98=89?= Date: Sun, 2 Jan 2022 15:10:58 +0800 Subject: [PATCH] Add multi-config generator build support for Windows. --- CMakeLists.txt | 31 ++++++++++++++++++------------- rpcs3/CMakeLists.txt | 17 ++--------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc0b390063..74421142c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,16 +26,17 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/buildfiles/cmake") include(CheckCXXCompilerFlag) -# TODO(cjj19970505@live.cn) -# Currently cmake config scripts are single-config generator only. get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTI_CONFIG) - message(FATAL_ERROR "Multi-config generators are not supported.") -endif() - -if(NOT CMAKE_BUILD_TYPE) - message(STATUS "No build type selected, default to Release") - set(CMAKE_BUILD_TYPE "Release") + # TODO(cjj19970505@live.cn) + # Currently DicordRPC is included as a binary compiled with /MT flag. + # We need all 4 binaries(/MT /MTd /MD /MDd) or including the source instead of binary. + set(USE_DISCORD_RPC OFF CACHE BOOL "Discord RPC is only avaliable with single-config generator" FORCE) +else() + if(NOT CMAKE_BUILD_TYPE) + message(STATUS "No build type selected, default to Release") + set(CMAKE_BUILD_TYPE "Release") + endif() endif() if(CMAKE_BUILD_TYPE MATCHES "Debug" AND NOT MSVC) @@ -45,14 +46,16 @@ endif() if(MSVC) option(USE_MSVC_STATIC_CRT "Use static MSVC C runtime" OFF) - # TODO(cjj19970505@live.cno) + # TODO(cjj19970505@live.cn) # DiscordRPC binary in 3rdparty is compiled /MT # So theoretically we should enable DiscordRPC in Release and static CRT build # since we might encounter some rumtime issues when more than one CRT version are presented. # https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-160#what-problems-exist-if-an-application-uses-more-than-one-crt-version # Add other DiscordRPC binaries(compiled with /MTd, /MD, /MDd) or compile it from source may address this issue. - if(NOT(CMAKE_BUILD_TYPE MATCHES "Release" AND USE_MSVC_STATIC_CRT)) - set(USE_DISCORD_RPC OFF CACHE BOOL "Discord RPC is only available in Release and static CRT build." FORCE) + if(NOT IS_MULTI_CONFIG) + if(NOT(CMAKE_BUILD_TYPE MATCHES "Release" AND USE_MSVC_STATIC_CRT)) + set(USE_DISCORD_RPC OFF CACHE BOOL "Discord RPC is only available in Release and static CRT build." FORCE) + endif() endif() if(USE_MSVC_STATIC_CRT) @@ -79,8 +82,10 @@ if(MSVC) # For more info: # https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-160#what-problems-exist-if-an-application-uses-more-than-one-crt-version # https://wiki.qt.io/Technical_FAQ#Why_does_a_statically_built_Qt_use_the_dynamic_Visual_Studio_runtime_libraries_.3F_Do_I_need_to_deploy_those_with_my_application_.3F - if(USE_MSVC_STATIC_CRT AND CMAKE_BUILD_TYPE MATCHES "Debug") - message(AUTHOR_WARNING "Debug build currently can not work with static CRT.") + if(USE_MSVC_STATIC_CRT) + if(IS_MULTI_CONFIG OR CMAKE_BUILD_TYPE MATCHES "Debug") + message(AUTHOR_WARNING "Debug build currently can not work with static CRT.") + endif() endif() endif() diff --git a/rpcs3/CMakeLists.txt b/rpcs3/CMakeLists.txt index a8fcfec597..3c591b8122 100644 --- a/rpcs3/CMakeLists.txt +++ b/rpcs3/CMakeLists.txt @@ -155,10 +155,6 @@ elseif(UNIX) COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/bin/git $/git) elseif(WIN32) - # TODO(cjj19970505@live.cn) - # this is a single-config generator workaround - # multi-config generator will fail. - # TODO(cjj19970505@live.cn) # offical Qt binaries are built with -MD(d) only as stated in offical wiki # https://wiki.qt.io/Technical_FAQ#Why_does_a_statically_built_Qt_use_the_dynamic_Visual_Studio_runtime_libraries_.3F_Do_I_need_to_deploy_those_with_my_application_.3F @@ -179,19 +175,10 @@ elseif(WIN32) list(APPEND _QT5_TOOLS_PATHS "${Qt5_DIR}/../../../bin/") # If Qt5 is installed from vcpkg - if(CMAKE_BUILD_TYPE STREQUAL "Debug") - list(APPEND _QT5_TOOLS_PATHS "${Qt5_DIR}/../../../tools/qt5/debug/bin/") - else() - list(APPEND _QT5_TOOLS_PATHS "${Qt5_DIR}/../../../tools/qt5/bin/") - endif() - - find_program(_WINDEPLOYQT - NAMES windeployqt - PATHS ${_QT5_TOOLS_PATHS} - REQUIRED) - message("Use windeployqt in ${_WINDEPLOYQT}") + list(APPEND _QT5_TOOLS_PATHS "${Qt5_DIR}/../../../tools/qt5$<$:/debug>/bin/") add_custom_command(TARGET rpcs3 POST_BUILD + COMMAND set PATH=${_QT5_TOOLS_PATHS}$%PATH% COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_SOURCE_DIR}/bin" "$" # If Qt5 is installed from vcpkg, add binary path to PATH # otherwise windeployqt tool won't be able to locate necessary dlls