From 18c01f715151ccdf44b1941f8c404a7dfe6b3de7 Mon Sep 17 00:00:00 2001 From: Antonino Di Guardo <64427768+digant73@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:53:31 +0200 Subject: [PATCH] Fixed compilation with cmake on Windows (#16184) * Fixed compilation with cmake on Windows * cleanup on post build actions for Windows on cmake solution + minor cleanup * fix link error on IntelJITEvents --- 3rdparty/OpenAL/CMakeLists.txt | 4 +- 3rdparty/llvm/CMakeLists.txt | 13 +++- BUILDING.md | 111 ++++++++++++++++++++++++--------- CMakePresets.json | 29 ++++++--- rpcs3/CMakeLists.txt | 38 +++++------ 5 files changed, 137 insertions(+), 58 deletions(-) diff --git a/3rdparty/OpenAL/CMakeLists.txt b/3rdparty/OpenAL/CMakeLists.txt index ffeeee2bdc..2100de3b4f 100644 --- a/3rdparty/OpenAL/CMakeLists.txt +++ b/3rdparty/OpenAL/CMakeLists.txt @@ -5,8 +5,8 @@ if(USE_SYSTEM_OPENAL) target_include_directories(3rdparty_openal INTERFACE ${OPENAL_INCLUDE_DIR}) target_link_libraries(3rdparty_openal INTERFACE ${OPENAL_LIBRARY}) else() - option(ALSOFT_UTILS "Build utility programs" OFF) - option(ALSOFT_EXAMPLES "Build example programs" OFF) + option(ALSOFT_UTILS "Build utility programs" OFF) + option(ALSOFT_EXAMPLES "Build example programs" OFF) add_subdirectory(openal-soft EXCLUDE_FROM_ALL) add_library(3rdparty_openal INTERFACE) target_link_libraries(3rdparty_openal INTERFACE OpenAL::OpenAL) diff --git a/3rdparty/llvm/CMakeLists.txt b/3rdparty/llvm/CMakeLists.txt index 780d3412c4..e2eb18f129 100644 --- a/3rdparty/llvm/CMakeLists.txt +++ b/3rdparty/llvm/CMakeLists.txt @@ -17,7 +17,10 @@ if(WITH_LLVM) option(LLVM_CCACHE_BUILD OFF) set(LLVM_ENABLE_WARNINGS OFF CACHE BOOL "Enable compiler warnings.") - if(WIN32 AND COMPILER_X86) + # For Windows x86 (not Windows AArch64). + # Check on MSVC is needed due to COMPILER_X86, COMPILER_ARM etc. are not set/supported by the MSVC compiler, if used. + # Furthermore, the MSVC compiler is not available/supported on Windows AArch64 + if(WIN32 AND (COMPILER_X86 OR MSVC)) set(LLVM_USE_INTEL_JITEVENTS ON) endif() @@ -70,12 +73,18 @@ if(WITH_LLVM) set(LLVM_TARGETS_TO_BUILD "X86" CACHE STRING "Semicolon-separated list of targets to build, or \"all\".") endif() endif() - if((WIN32 AND BUILD_LLVM) OR (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND COMPILER_X86)) + + # For Windows x86 (not Windows AArch64) only when BUILD_LLVM is enabled and + # for Linux x86 (not Linux AArch64) even if BUILD_LLVM is disabled (precompiled llvm used) + if(LLVM_USE_INTEL_JITEVENTS OR (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND COMPILER_X86)) list (APPEND LLVM_ADDITIONAL_LIBS IntelJITEvents) endif() + + # For Linux even if BUILD_LLVM is disabled (precompiled llvm used) if(CMAKE_SYSTEM_NAME STREQUAL "Linux") list (APPEND LLVM_ADDITIONAL_LIBS PerfJITEvents) endif() + llvm_map_components_to_libnames(LLVM_LIBS ${LLVM_TARGETS_TO_BUILD} ${LLVM_ADDITIONAL_LIBS} diff --git a/BUILDING.md b/BUILDING.md index 1067a3d501..263fed68ed 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -7,25 +7,40 @@ Other instructions may be found [here](https://wiki.rpcs3.net/index.php?title=Bu ### Windows 10 or later -* [CMake 3.28.0+](https://www.cmake.org/download/) (add to PATH) -* [Python 3.6+](https://www.python.org/downloads/) (add to PATH) -* [Qt 6.7.3](https://www.qt.io/download-qt-installer) -* [Visual Studio 2022](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community) (or at least Visual Studio 2019 16.11.xx+ as C++20 is not included in previous versions) -* [Vulkan SDK 1.3.268.0](https://vulkan.lunarg.com/sdk/home) (See "Install the SDK" [here](https://vulkan.lunarg.com/doc/sdk/latest/windows/getting_started.html)) for now future SDKs don't work. You need precisely 1.3.268.0. +The following tools are required to build RPCS3 on Windows 10 or later: +- [Visual Studio 2022](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community) (or at least Visual Studio 2019 16.11.xx+ as C++20 is not included in previous versions) +- **Optional** - [CMake 3.28.0+](https://www.cmake.org/download/) (add to PATH) -**Either add the** `QTDIR` **environment variable, e.g.** `\6.7.3\msvc2019_64\` **, or use the [Visual Studio Qt Plugin](https://marketplace.visualstudio.com/items?itemName=TheQtCompany.QtVisualStudioTools2019)** + **NOTES:** + - **Visual Studio 2022** integrates **CMake 3.29+** and it also supports both the `sln` solution (`.sln`, `.vcxproj`) and `CMake` solution (`CMakeLists.txt`, `CMakePresets.json`). + See sections [Building with Visual Studio sln solution](#building-with-visual-studio-sln-solution) and [Building with Visual Studio CMake solution](#building-with-visual-studio-cmake-solution) + on how to build the project with **Visual Studio**. + - Install and use this standalone **CMake** tool just in case of your preference. See section [Building with standalone CMake tool](#building-with-standalone-cmake-tool) on how to build the project + with standalone **CMake** tool. -**NOTE: If you have issues with the Qt plugin, you may want to uninstall the Qt Plugin and install the [Legacy Qt Plugin](https://marketplace.visualstudio.com/items?itemName=TheQtCompany.LEGACYQtVisualStudioTools2019) instead.** +- [Python 3.6+](https://www.python.org/downloads/) (add to PATH) +- [Qt 6.7.3](https://www.qt.io/download-qt-installer) +- [Vulkan SDK 1.3.268.0](https://vulkan.lunarg.com/sdk/home) (see "Install the SDK" [here](https://vulkan.lunarg.com/doc/sdk/latest/windows/getting_started.html)) for now future SDKs don't work. You need precisely 1.3.268.0. + +The `sln` solution available only on **Visual Studio** is the preferred building solution. It easily allows to build the **RPCS3** application in `Release` and `Debug` mode. + +In order to build **RPCS3** with the `sln` solution (with **Visual Studio**), **Qt** libs need to be detected. To detect the libs: +- add and set the `QTDIR` environment variable, e.g. `\6.7.3\msvc2019_64\` +- or use the [Visual Studio Qt Plugin](https://marketplace.visualstudio.com/items?itemName=TheQtCompany.QtVisualStudioTools2019) + + **NOTE:** If you have issues with the **Visual Studio Qt Plugin**, you may want to uninstall it and install the [Legacy Qt Plugin](https://marketplace.visualstudio.com/items?itemName=TheQtCompany.LEGACYQtVisualStudioTools2019) instead. + +In order to build **RPCS3** with the `CMake` solution (with both **Visual Studio** and standalone **CMake** tool): +- add and set the `CMAKE_PREFIX_PATH` environment variable to the **Qt** libs path, e.g. `\6.7.3\msvc2019_64\` ### Linux -These are the essentials tools to build RPCS3 on Linux. Some of them can be installed through your favorite package manager. - -* Clang 17+ or GCC 13+ -* [CMake 3.28.0+](https://www.cmake.org/download/) -* [Qt 6.7.3](https://www.qt.io/download-qt-installer) -* [Vulkan SDK 1.3.268.0](https://vulkan.lunarg.com/sdk/home) (See "Install the SDK" [here](https://vulkan.lunarg.com/doc/sdk/latest/linux/getting_started.html)) for now future SDKs don't work. You need precisely 1.3.268.0. -* [SDL2](https://github.com/libsdl-org/SDL/releases) (for the FAudio backend) +These are the essentials tools to build RPCS3 on Linux. Some of them can be installed through your favorite package manager: +- Clang 17+ or GCC 13+ +- [CMake 3.28.0+](https://www.cmake.org/download/) +- [Qt 6.7.3](https://www.qt.io/download-qt-installer) +- [Vulkan SDK 1.3.268.0](https://vulkan.lunarg.com/sdk/home) (See "Install the SDK" [here](https://vulkan.lunarg.com/doc/sdk/latest/linux/getting_started.html)) for now future SDKs don't work. You need precisely 1.3.268.0. +- [SDL2](https://github.com/libsdl-org/SDL/releases) (for the FAudio backend) **If you have an NVIDIA GPU, you may need to install the libglvnd package.** @@ -38,6 +53,7 @@ These are the essentials tools to build RPCS3 on Linux. Some of them can be inst sudo apt-get install build-essential libasound2-dev libpulse-dev libopenal-dev libglew-dev zlib1g-dev libedit-dev libvulkan-dev libudev-dev git libevdev-dev libsdl2-2.0 libsdl2-dev libjack-dev libsndio-dev Ubuntu is usually horrendously out of date, and some packages need to be downloaded by hand. This part is for Qt, GCC, Vulkan, and CMake + ##### Qt PPA Ubuntu usually does not have a new enough Qt package to suit rpcs3's needs. There is currently no PPA available to work around this. @@ -65,6 +81,7 @@ sudo apt install vulkan-sdk ``` ##### CMake + ``` . /etc/os-release wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add - @@ -95,26 +112,64 @@ git submodule update --init ### Windows -#### Configuring the Qt plugin (if used) +#### Building with Visual Studio sln solution -1) Go to `Extensions->Qt VS Tools->Qt Versions`. -2) Add the path to your Qt installation with compiler e.g. `\6.7.3\msvc2019_64`, version will fill in automatically. -3) Go to `Extensions->Qt VS Tools->Options->Legacy Project Format`. (Only available in the legacy Qt plugin) -4) Set `Build: Run pre-build setup` to `true`. (Only available in the legacy Qt plugin) +Start **Visual Studio**, click on `Open a project or solution` and select the `rpcs3.sln` file inside the RPCS3's root folder -#### Building the projects +##### Configuring the Qt Plugin (if used) -Open `rpcs3.sln`. The recommended build configuration is `Release`. (On older revisions: `Release - LLVM`) +1) go to `Extensions->Qt VS Tools->Qt Versions` +2) add the path to your Qt installation with compiler e.g. `\6.7.3\msvc2019_64`, version will fill in automatically +3) go to `Extensions->Qt VS Tools->Options->Legacy Project Format`. (Only available in the **Legacy Qt Plugin**) +4) set `Build: Run pre-build setup` to `true`. (Only available in the **Legacy Qt Plugin**) -You may want to download the precompiled [LLVM libs](https://github.com/RPCS3/llvm-mirror/releases/download/custom-build-win-16.0.1/llvmlibs_mt.7z) and extract them to `3rdparty\llvm\`, as well as download and extract the [additional libs](https://github.com/RPCS3/glslang/releases/latest/download/glslanglibs_mt.7z) to `lib\%CONFIGURATION%-x64\` to speed up compilation time (unoptimised/debug libs are currently not available precompiled). +##### Building the projects -If you're not using the precompiled libs, build the following projects in *__BUILD_BEFORE* folder by right-clicking on a project > *Build*.: -* glslang -* **Either** llvm_build **or** llvm_build_clang_cl +**NOTE:** The recommended build configuration is `Release`. (On older revisions: `Release - LLVM`) -Afterwards: +You may want to download the precompiled [LLVM libs](https://github.com/RPCS3/llvm-mirror/releases/download/custom-build-win-16.0.1/llvmlibs_mt.7z) and extract them to `3rdparty\llvm\`, +as well as download and extract the [additional libs](https://github.com/RPCS3/glslang/releases/latest/download/glslanglibs_mt.7z) to `lib\%CONFIGURATION%-x64\` to speed up compilation +time (unoptimised/debug libs are currently not available precompiled). -`Build > Build Solution` +If you're not using the precompiled libs, those dependency libs need to be compiled first. From the `Solution Explorer` panel: +1) expand `__BUILD_BEFORE` +2) from the `Solution Configurations` drop-down menu, select `Release` (select `Debug` if you want to build in `Debug` mode) +3) one after another, right-click on the following projects and then click on `Build` to build the selected lib: + - `glslang` + - either `llvm_build` + - or `llvm_build_clang_cl` (if you installed **clang** on VS) + +In order to build the **RPCS3** application: +1) from the `Solution Configurations` drop-down menu, select `Release` (select `Debug` if you want to build in `Debug` mode) + + **NOTE:** In case you previously compiled the dependency libs under `__BUILD_BEFORE`, you have also to select the same build configuration (e.g. `Release`, if you compiled the dependency libs in `Release` mode) + +2) click on `Build` menu and then on `Build Solution` +3) once the build is completed, the **RPCS3** application will be available under the `\bin` folder + +#### Building with Visual Studio CMake solution + +Start **Visual Studio**, click on `Open a local folder` and select the RPCS3's root folder + +Once the project is open on VS, from the `Solution Explorer` panel: +1) right-click on `rpcs3` and then click on `Switch to CMake Targets View` +2) from the `Configuration` drop-down menu, select `msvc-release` (select `msvc-debug` if you want to build in `Debug` mode) +3) right-click on `CMakeLists.txt Project` and then click on `Configure Cache` +4) once the cache is created, the `rpcs3 project` will be available +5) right-click on `rpcs3 Project` and then click on `Build All`, or click on `Build` menu and then on `Build All` +6) once the build is completed, the **RPCS3** application will be available under the `\build-msvc\bin` folder + +#### Building with standalone CMake tool + +In case you preferred to install and use the standalone **CMake** tool: +1) move on the RPCS3's root folder +2) execute the following commands to create the cache and to build the application (for the build, use `--preset msvc-debug` if you want to build in `Debug` mode), respectively: + + ``` + cmake --preset msvc + cmake --build --preset msvc-release + ``` +3) once the build is completed, the **RPCS3** application will be available under the `\build-msvc\bin` folder ### Linux @@ -122,7 +177,7 @@ While still in the project root: 1) `cd .. && mkdir --parents rpcs3_build && cd rpcs3_build` 2) `cmake ../rpcs3/ && make` or `CXX=g++-13 CC=gcc-13 cmake ../rpcs3/ && make` to force these compilers -3) Run RPCS3 with `./bin/rpcs3` +3) run RPCS3 with `./bin/rpcs3` If compiling for ARM, pass the flag `-DUSE_NATIVE_INSTRUCTIONS=OFF` to the cmake command. This resolves some Neon errors when compiling our SIMD headers. diff --git a/CMakePresets.json b/CMakePresets.json index 82dc88e1a6..f2ad04077c 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -7,12 +7,12 @@ "binaryDir": "build-gcc", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", + "USE_NATIVE_INSTRUCTIONS": "ON", + "USE_PRECOMPILED_HEADERS": "ON", "USE_FAUDIO": "OFF", "USE_SYSTEM_CURL": "OFF", "USE_SYSTEM_ZLIB": "OFF", "USE_SYSTEM_LIBPNG": "OFF", - "USE_NATIVE_INSTRUCTIONS": "ON", - "USE_PRECOMPILED_HEADERS": "ON", "BUILD_LLVM": "OFF", "STATIC_LINK_LLVM": "ON" } @@ -23,13 +23,13 @@ "binaryDir": "build-clang64", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", + "USE_NATIVE_INSTRUCTIONS": "ON", + "USE_PRECOMPILED_HEADERS": "ON", "USE_FAUDIO": "OFF", "USE_SYSTEM_CURL": "OFF", "USE_SYSTEM_ZLIB": "OFF", "USE_SYSTEM_LIBPNG": "OFF", "LLVM_ENABLE_LIBCXX": "ON", - "USE_NATIVE_INSTRUCTIONS": "ON", - "USE_PRECOMPILED_HEADERS": "ON", "BUILD_LLVM": "OFF", "STATIC_LINK_LLVM": "ON" }, @@ -48,11 +48,14 @@ "strategy": "external" }, "cacheVariables": { + "CMAKE_CONFIGURATION_TYPES": "Debug;Release", "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", - "USE_FAUDIO": "OFF", - "USE_PRECOMPILED_HEADERS": "ON", - "USE_SYSTEM_ZLIB": "OFF", "USE_NATIVE_INSTRUCTIONS": "ON", + "USE_PRECOMPILED_HEADERS": "ON", + "USE_FAUDIO": "OFF", + "USE_SYSTEM_CURL": "OFF", + "USE_SYSTEM_ZLIB": "OFF", + "USE_SYSTEM_OPENAL": "OFF", "BUILD_LLVM": "ON", "STATIC_LINK_LLVM": "ON" }, @@ -64,5 +67,17 @@ } } } + ], + "buildPresets": [ + { + "name": "msvc-debug", + "configurePreset": "msvc", + "configuration": "Debug" + }, + { + "name": "msvc-release", + "configurePreset": "msvc", + "configuration": "Release" + } ] } diff --git a/rpcs3/CMakeLists.txt b/rpcs3/CMakeLists.txt index a32dbc41a4..edd9dcf59d 100644 --- a/rpcs3/CMakeLists.txt +++ b/rpcs3/CMakeLists.txt @@ -132,29 +132,29 @@ if(APPLE) endif() qt_finalize_target(rpcs3) add_custom_command(TARGET rpcs3 POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_SOURCE_DIR}/rpcs3.icns $/../Resources/rpcs3.icns - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_SOURCE_DIR}/bin/Icons $/../Resources/Icons - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_SOURCE_DIR}/bin/GuiConfigs $/../Resources/GuiConfigs - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_SOURCE_DIR}/bin/git $/../Resources/git - COMMAND "${MACDEPLOYQT_EXECUTABLE}" "${PROJECT_BINARY_DIR}/bin/rpcs3.app" "${QT_DEPLOY_FLAGS}") + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/rpcs3.icns $/../Resources/rpcs3.icns + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/bin/Icons $/../Resources/Icons + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/bin/GuiConfigs $/../Resources/GuiConfigs + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/bin/git $/../Resources/git + COMMAND "${MACDEPLOYQT_EXECUTABLE}" "${PROJECT_BINARY_DIR}/bin/rpcs3.app" "${QT_DEPLOY_FLAGS}") elseif(UNIX) add_custom_command(TARGET rpcs3 POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_SOURCE_DIR}/bin/Icons $/Icons) - add_custom_command(TARGET rpcs3 POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_SOURCE_DIR}/bin/GuiConfigs $/GuiConfigs) - add_custom_command(TARGET rpcs3 POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_SOURCE_DIR}/bin/git $/git) + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/bin/Icons $/Icons + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/bin/GuiConfigs $/GuiConfigs + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/bin/git $/git) elseif(WIN32) + if(MSVC) + add_custom_command(TARGET rpcs3 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/3rdparty/OpenAL/openal-soft/$/OpenAL32.dll $) + endif() add_custom_command(TARGET rpcs3 POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_SOURCE_DIR}/bin" "$" - COMMAND "${WINDEPLOYQT_EXECUTABLE}" --no-compiler-runtime --no-opengl-sw --no-patchqt --no-translations --no-quick --no-system-d3d-compiler --no-quick-import --plugindir "$,$/plugins,$/share/qt6/plugins>" --verbose 0 "$") + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/bin/Icons $/Icons + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/bin/GuiConfigs $/GuiConfigs + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/bin/git $/git + COMMAND "${WINDEPLOYQT_EXECUTABLE}" --no-compiler-runtime --no-opengl-sw --no-patchqt + --no-translations --no-quick --no-system-d3d-compiler --no-quick-import + --plugindir "$,$/plugins,$/share/qt6/plugins>" + --verbose 0 "$") endif() # Unix installation