From 05881ffa6272e716547c38bad7fa9ff65877e0e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BF=8A=E5=98=89?= Date: Sat, 13 Nov 2021 23:11:49 +0800 Subject: [PATCH] Disable vulkan in Windows build when HAVE_VULKAN is off and other cmake build fixes. (#11118) * Make WolfSSL build support multi-config generator. Fix a build error in Windows when using QT's moc. Disable vulkan in Windows build when HAVE_VULKAN is off. * add WIN32_LEAN_AND_MEAN definition to VS project. add HAVE_VULKAN definition to VS project. Define NTSTATUS in main.cpp. --- 3rdparty/wolfssl/CMakeLists.txt | 13 +------------ rpcs3/Emu/System.cpp | 4 ++-- rpcs3/emucore.vcxproj | 2 ++ rpcs3/headless_application.cpp | 2 +- rpcs3/main.cpp | 9 +++++++++ rpcs3/rpcs3.vcxproj | 4 ++-- rpcs3/rpcs3qt/CMakeLists.txt | 6 ++++++ rpcs3/rpcs3qt/gui_application.cpp | 9 ++------- rpcs3/rpcs3qt/render_creator.cpp | 4 ++-- 9 files changed, 27 insertions(+), 26 deletions(-) diff --git a/3rdparty/wolfssl/CMakeLists.txt b/3rdparty/wolfssl/CMakeLists.txt index 037628551b..e247b19854 100644 --- a/3rdparty/wolfssl/CMakeLists.txt +++ b/3rdparty/wolfssl/CMakeLists.txt @@ -27,18 +27,7 @@ else() add_subdirectory(wolfssl EXCLUDE_FROM_ALL) - # TODO(cjj19970505@live.cn) - # This only works in single-config generator - # For a multi-config generator, we need to provide different wolfssl binaries for different config - if (GENERATOR_IS_MULTI_CONFIG) - message( FATAL_ERROR "RPCS3 can only be configured using single-config generator." ) - endif() - - if(MSVC) - set(WolfSSL_LIBRARY "${CMAKE_CURRENT_BINARY_DIR}/wolfssl/${CMAKE_BUILD_TYPE}/wolfssl.lib" CACHE INTERNAL "") - else() - set(WolfSSL_LIBRARY "${CMAKE_CURRENT_BINARY_DIR}/wolfssl/libwolfssl.a" CACHE INTERNAL "") - endif() + set(WolfSSL_LIBRARY "$" CACHE INTERNAL "") # "${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/wolfssl/" provides openssl headers # So that curl can be built on an environment where openssl headers are not provided diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 68a1554953..8158a481ea 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -41,7 +41,7 @@ #include "display_sleep_control.h" -#if defined(_WIN32) || defined(HAVE_VULKAN) +#if defined(HAVE_VULKAN) #include "Emu/RSX/VK/VulkanAPI.h" #endif @@ -718,7 +718,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool if (!add_only) { // Log some extra info in case of boot -#if defined(_WIN32) || defined(HAVE_VULKAN) +#if defined(HAVE_VULKAN) if (g_cfg.video.renderer == video_renderer::vulkan) { sys_log.notice("Vulkan SDK Revision: %d", VK_HEADER_VERSION); diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index f967666902..d3f4c2122a 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -42,6 +42,8 @@ Use ..\3rdparty\wolfssl\wolfssl;..\3rdparty\flatbuffers\include;..\3rdparty\libusb\libusb\libusb;..\3rdparty\yaml-cpp\yaml-cpp\include;..\3rdparty\zlib\zlib;..\llvm\include;..\llvm_build\include;$(VULKAN_SDK)\Include MaxSpeed + HAVE_VULKAN;%(PreprocessorDefinitions) + HAVE_VULKAN;%(PreprocessorDefinitions) cmd.exe /c "$(SolutionDir)\Utilities\git-version-gen.cmd" diff --git a/rpcs3/headless_application.cpp b/rpcs3/headless_application.cpp index 41c2e35e02..8424878d48 100644 --- a/rpcs3/headless_application.cpp +++ b/rpcs3/headless_application.cpp @@ -73,7 +73,7 @@ void headless_application::InitializeCallbacks() break; } case video_renderer::opengl: -#if defined(_WIN32) || defined(HAVE_VULKAN) +#if defined(HAVE_VULKAN) case video_renderer::vulkan: #endif { diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index f76c091dde..fa666e886d 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -26,6 +26,15 @@ #ifdef _WIN32 #include #include "util/dyn_lib.hpp" + +// TODO(cjj19970505@live.cn) +// When compiling with WIN32_LEAN_AND_MEAN definition +// NTSTATUS is defined in CMake build but not in VS build +// May be caused by some different header pre-inclusion between CMake and VS configurations. +#if !defined(NTSTATUS) +// Copied from ntdef.h +typedef _Return_type_success_(return >= 0) LONG NTSTATUS; +#endif DYNAMIC_IMPORT("ntdll.dll", NtQueryTimerResolution, NTSTATUS(PULONG MinimumResolution, PULONG MaximumResolution, PULONG CurrentResolution)); DYNAMIC_IMPORT("ntdll.dll", NtSetTimerResolution, NTSTATUS(ULONG DesiredResolution, BOOLEAN SetResolution, PULONG CurrentResolution)); #else diff --git a/rpcs3/rpcs3.vcxproj b/rpcs3/rpcs3.vcxproj index 5040942f6c..dbbd6de098 100644 --- a/rpcs3/rpcs3.vcxproj +++ b/rpcs3/rpcs3.vcxproj @@ -79,7 +79,7 @@ 4577;4467;%(DisableSpecificWarnings) $(IntDir) MaxSpeed - _WINDOWS;UNICODE;WIN32;WIN64;WITH_DISCORD_RPC;QT_NO_DEBUG;QT_WIDGETS_LIB;QT_GUI_LIB;QT_CORE_LIB;NDEBUG;QT_WINEXTRAS_LIB;QT_CONCURRENT_LIB;QT_MULTIMEDIA_LIB;QT_MULTIMEDIAWIDGETS_LIB;QT_SVG_LIB;%(PreprocessorDefinitions) + _WINDOWS;UNICODE;WIN32;WIN64;WIN32_LEAN_AND_MEAN;HAVE_VULKAN;WITH_DISCORD_RPC;QT_NO_DEBUG;QT_WIDGETS_LIB;QT_GUI_LIB;QT_CORE_LIB;NDEBUG;QT_WINEXTRAS_LIB;QT_CONCURRENT_LIB;QT_MULTIMEDIA_LIB;QT_MULTIMEDIAWIDGETS_LIB;QT_SVG_LIB;%(PreprocessorDefinitions) false $(IntDir)vc$(PlatformToolsetVersion).pdb true @@ -130,7 +130,7 @@ 4577;4467;%(DisableSpecificWarnings) $(IntDir) Disabled - _WINDOWS;UNICODE;WIN32;WIN64;QT_WIDGETS_LIB;QT_GUI_LIB;QT_CORE_LIB;QT_WINEXTRAS_LIB;QT_CONCURRENT_LIB;QT_MULTIMEDIA_LIB;QT_MULTIMEDIAWIDGETS_LIB;QT_SVG_LIB;%(PreprocessorDefinitions) + _WINDOWS;UNICODE;WIN32;WIN64;WIN32_LEAN_AND_MEAN;HAVE_VULKAN;QT_WIDGETS_LIB;QT_GUI_LIB;QT_CORE_LIB;QT_WINEXTRAS_LIB;QT_CONCURRENT_LIB;QT_MULTIMEDIA_LIB;QT_MULTIMEDIAWIDGETS_LIB;QT_SVG_LIB;%(PreprocessorDefinitions) false true true diff --git a/rpcs3/rpcs3qt/CMakeLists.txt b/rpcs3/rpcs3qt/CMakeLists.txt index de12f49031..1803d4c8e3 100644 --- a/rpcs3/rpcs3qt/CMakeLists.txt +++ b/rpcs3/rpcs3qt/CMakeLists.txt @@ -108,6 +108,12 @@ set_target_properties(rpcs3_ui AUTOUIC ON AUTORCC ON) +# AUTOMOC brings Windows.h to the sources, which have some definitions conflicting with winsock2.h +# define WIN32_LEAN_AND_MEAN resolve the problem +# https://docs.microsoft.com/en-us/windows/win32/winsock/creating-a-basic-winsock-application +# https://docs.microsoft.com/en-us/windows/win32/winprog/using-the-windows-headers#faster-builds-with-smaller-header-files +target_compile_definitions(rpcs3_ui PRIVATE WIN32_LEAN_AND_MEAN) + target_link_libraries(rpcs3_ui PUBLIC 3rdparty::qt5 3rdparty::yaml-cpp diff --git a/rpcs3/rpcs3qt/gui_application.cpp b/rpcs3/rpcs3qt/gui_application.cpp index 5e65b09e7d..6568cbd708 100644 --- a/rpcs3/rpcs3qt/gui_application.cpp +++ b/rpcs3/rpcs3qt/gui_application.cpp @@ -1,8 +1,3 @@ -#ifdef _WIN32 -// This is to avoid inclusion of winsock.h from windows.h header which creates conflicts with inclusion of winsock2.h later -#define _WINSOCKAPI_ -#endif - #include "gui_application.h" #include "qt_utils.h" @@ -46,7 +41,7 @@ #include "Emu/RSX/Null/NullGSRender.h" #include "Emu/RSX/GL/GLGSRender.h" -#if defined(_WIN32) || defined(HAVE_VULKAN) +#if defined(HAVE_VULKAN) #include "Emu/RSX/VK/VKGSRender.h" #endif @@ -342,7 +337,7 @@ void gui_application::InitializeCallbacks() g_fxo->init>(); break; } -#if defined(_WIN32) || defined(HAVE_VULKAN) +#if defined(HAVE_VULKAN) case video_renderer::vulkan: { g_fxo->init>(); diff --git a/rpcs3/rpcs3qt/render_creator.cpp b/rpcs3/rpcs3qt/render_creator.cpp index d03e94a929..1b9135dc57 100644 --- a/rpcs3/rpcs3qt/render_creator.cpp +++ b/rpcs3/rpcs3qt/render_creator.cpp @@ -4,7 +4,7 @@ #include "Utilities/Thread.h" -#if defined(_WIN32) || defined(HAVE_VULKAN) +#if defined(HAVE_VULKAN) #include "Emu/RSX/VK/vkutils/instance.hpp" #endif @@ -20,7 +20,7 @@ constexpr auto qstr = QString::fromStdString; render_creator::render_creator(QObject *parent) : QObject(parent) { -#if defined(WIN32) || defined(HAVE_VULKAN) +#if defined(HAVE_VULKAN) // Some drivers can get stuck when checking for vulkan-compatible gpus, f.ex. if they're waiting for one to get // plugged in. This whole contraption is for showing an error message in case that happens, so that user has // some idea about why the emulator window isn't showing up.