diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 6e8a6a4aa..d89f97675 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -26,10 +26,12 @@ jobs: include: - os: ubuntu-latest cache_path: ~/.ccache - extra_cmake_args: -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain/linux-x64.cmake -DUSE_DISCORD_RICH_PRESENCE=OFF + extra_cmake_args: + cmake_preset: linux-ninja-clang - os: windows-latest cache_path: ~\AppData\Local\Mozilla\sccache - extra_cmake_args: -DBOOST_ROOT=C:\hostedtoolcache\windows\Boost\1.78.0\x86_64 -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain/windows-x64.cmake -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache + extra_cmake_args: -DBOOST_ROOT=C:\hostedtoolcache\windows\Boost\1.78.0\x86_64 -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache + cmake_preset: windows-ninja steps: - name: Set up build environment (macos-latest) @@ -86,20 +88,20 @@ jobs: - name: CMake run: | - cmake -B build -DCI=ON -DCMAKE_BUILD_TYPE=${{ matrix.config }} ${{ matrix.extra_cmake_args }} -G Ninja - cmake --build build --config ${{ matrix.config }} + cmake -DCI=ON ${{ matrix.extra_cmake_args }} --preset ${{ matrix.cmake_preset }} + cmake --build build/${{ matrix.cmake_preset }} --config ${{ matrix.config }} if: matrix.os != 'windows-latest' - name: CMake shell: cmd run: | call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" -arch=x64 - cmake -B build -DCI=ON -DCMAKE_BUILD_TYPE=${{ matrix.config }} ${{ matrix.extra_cmake_args }} -G Ninja - cmake --build build --config ${{ matrix.config }} + cmake -DCI=ON ${{ matrix.extra_cmake_args }} --preset ${{ matrix.cmake_preset }} + cmake --build build/${{ matrix.cmake_preset }} --config ${{ matrix.config }} if: matrix.os == 'windows-latest' - name: CTest - working-directory: build + working-directory: build/${{ matrix.cmake_preset }} run: ctest --build-config ${{ matrix.config }} --output-on-failure - name: Compute git short sha @@ -109,7 +111,9 @@ jobs: - uses: actions/upload-artifact@v3 with: name: vita3k-${{ steps.git_short_sha.outputs.value }}-${{ matrix.os }} - path: build/bin + # path is set up to be /bin/ since that's how multi-config + # generators work on CMake + path: build/${{ matrix.cmake_preset }}/bin/${{ matrix.config }} create-release: needs: [build] diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 7bea08302..0becf7c86 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -29,7 +29,7 @@ jobs: # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection os: [ubuntu-latest] config: [Release] - + cmake_preset: [linux-ninja-clang] steps: - name: Set up build environment (ubuntu-latest) @@ -78,8 +78,8 @@ jobs: - name: Build run: | - cmake -B build -DCI=ON -DCMAKE_BUILD_TYPE=${{ matrix.config }} -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain/linux-x64.cmake -DUSE_DISCORD_RICH_PRESENCE=OFF -G Ninja - cmake --build build --config ${{ matrix.config }} + cmake -DCI=ON --preset ${{ matrix.cmake_preset }} + cmake --build build/${{ matrix.cmake_preset }} --config ${{ matrix.config }} - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 diff --git a/.gitignore b/.gitignore index 03aa6f943..80dad5497 100755 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ build /docs/html/ # clangd cache .cache +# CMake user presets +CMakeUserPresets.json diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 000000000..ee6080a29 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,214 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 23, + "patch": 0 + }, + "configurePresets": [ + { + "name": "base", + "hidden": true, + "description": "Base hidden preset to set general options", + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "USE_DISCORD_RICH_PRESENCE": true + } + }, + { + "name": "windows", + "inherits": "base", + "displayName": "Windows default", + "description": "Windows native build using default generator and default compiler", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "windows-vs2022", + "inherits": "windows", + "displayName": "Windows with Visual Studio 2022", + "description": "Windows native build using Visual Studio 2022 generator and default toolchain/compiler", + "generator": "Visual Studio 17 2022", + "architecture": "x64" + }, + { + "name": "windows-vs2022-clang", + "inherits": "windows-vs2022", + "displayName": "Windows with Visual Studio 2022 and Clang", + "description": "Windows native build using Visual Studio 2022 generator and the ClangCL/LLVM toolchain", + "toolset": "ClangCL" + }, + { + "name": "windows-ninja", + "inherits": "windows", + "displayName": "Windows with Ninja", + "description": "Windows native build using Ninja Multi-Config and default compiler", + "generator": "Ninja Multi-Config" + }, + { + "name": "windows-ninja-clang", + "inherits": "windows-ninja", + "displayName": "Windows with Ninja and Clang", + "description": "Windows native build using Ninja Multi-Config and Clang compiler", + "cacheVariables": { + "CMAKE_C_COMPILER": "clang-cl", + "CMAKE_CXX_COMPILER": "clang-cl" + } + }, + { + "name": "linux", + "inherits": "base", + "displayName": "Linux default", + "description": "Linux native build using default generator and default compiler", + "cacheVariables": { + "USE_DISCORD_RICH_PRESENCE": false + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "linux-ninja", + "inherits": "linux", + "displayName": "Linux with Ninja", + "description": "Linux native build using Ninja Multi-Config generator and default compiler", + "generator": "Ninja Multi-Config" + }, + { + "name": "linux-ninja-clang", + "inherits": "linux-ninja", + "displayName": "Linux with Ninja and Clang", + "description": "Linux native build using Ninja Multi-Config generator and Clang compiler", + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" + } + }, + { + "name": "linux-ninja-gnu", + "inherits": "linux-ninja", + "displayName": "Linux with Ninja and GNU GCC", + "description": "Linux native build using Ninja Multi-Config generator and GNU GCC compiler", + "cacheVariables": { + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" + } + }, + { + "name": "macos", + "inherits": "base", + "displayName": "macOS default", + "description": "macOS native build using default generator and default compiler", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + }, + { + "name": "macos-ninja", + "inherits": "macos", + "displayName": "macOS with Ninja", + "description": "Linux native build using Ninja Multi-Config generator and default compiler", + "generator": "Ninja Multi-Config" + }, + { + "name": "macos-xcode", + "inherits": "macos", + "displayName": "macOS with Xcode", + "description": "Linux native build using Xcode generator and default compiler", + "generator": "Xcode" + } + ], + "buildPresets": [ + { + "name": "windows-vs2022-debug", + "displayName": "Debug", + "description": "Build with debugging information and no compiler optimizations", + "configuration": "Debug", + "configurePreset": "windows-vs2022" + }, + { + "name": "windows-vs2022-relwithdebinfo", + "displayName": "Release with debugging information", + "description": "Build with compiler optimizations enabled and limited debugging information", + "configuration": "RelWithDebInfo", + "configurePreset": "windows-vs2022" + }, + { + "name": "windows-vs2022-release", + "displayName": "Release", + "description": "Build with compiler optimizations enabled and no debugging information", + "configuration": "Release", + "configurePreset": "windows-vs2022" + }, + { + "name": "windows-vs2022-clang-debug", + "displayName": "Debug", + "description": "Build with debugging information and no compiler optimizations", + "configuration": "Debug", + "configurePreset": "windows-vs2022-clang" + }, + { + "name": "windows-vs2022-clang-relwithdebinfo", + "displayName": "Release with debugging information", + "description": "Build with compiler optimizations enabled and limited debugging information", + "configuration": "RelWithDebInfo", + "configurePreset": "windows-vs2022-clang" + }, + { + "name": "windows-vs2022-clang-release", + "displayName": "Release", + "description": "Build with compiler optimizations enabled and no debugging information", + "configuration": "Release", + "configurePreset": "windows-vs2022-clang" + }, + { + "name": "linux-ninja-clang-debug", + "displayName": "Debug", + "description": "Build with debugging information and no compiler optimizations", + "configuration": "Debug", + "configurePreset": "linux-ninja-clang" + }, + { + "name": "linux-ninja-clang-relwithdebinfo", + "displayName": "Release with debugging information", + "description": "Build with compiler optimizations enabled and limited debugging information", + "configuration": "RelWithDebInfo", + "configurePreset": "linux-ninja-clang" + }, + { + "name": "linux-ninja-clang-release", + "displayName": "Release", + "description": "Build with compiler optimizations enabled and no debugging information", + "configuration": "Release", + "configurePreset": "linux-ninja-clang" + }, + { + "name": "linux-ninja-gnu-debug", + "displayName": "Debug", + "description": "Build with debugging information and no compiler optimizations", + "configuration": "Debug", + "configurePreset": "linux-ninja-gnu" + }, + { + "name": "linux-ninja-gnu-relwithdebinfo", + "displayName": "Release with debugging information", + "description": "Build with compiler optimizations enabled and limited debugging information", + "configuration": "RelWithDebInfo", + "configurePreset": "linux-ninja-gnu" + }, + { + "name": "linux-ninja-gnu-release", + "displayName": "Release", + "description": "Build with compiler optimizations enabled and no debugging information", + "configuration": "Release", + "configurePreset": "linux-ninja-gnu" + } + ] +} diff --git a/building.md b/building.md index 384075693..ad30217ec 100644 --- a/building.md +++ b/building.md @@ -1,18 +1,20 @@ # Build Vita3K -Vita3K uses CMake for its project configuration and generation and should in theory be compatible with any project generator supported by CMake, C++17 compatible compiler and IDE with CMake support. However, the following settings are recommended to be used when compiling or developing: +Vita3K uses CMake for its project configuration and generation and should in theory be compatible with any project generator supported by CMake, C++17 compatible compiler and IDE with CMake support. -Target OS | Host OS | [Project generator](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html) (`-G`) | C/C++ Compiler (`-DCMAKE_C_COMPILER` and `-DCMAKE_CXX_COMPILER`) ---- | --- | --- | --- -Windows | Windows | Visual Studio / MSBuild | `cl` a.k.a Microsoft Visual C/C++ Compiler (included as a part of the [Build Tools for Visual Studio 2022](https://aka.ms/vs/17/release/vs_BuildTools.exe) and the ` Desktop development with C++` Visual Studio workload) -macOS | macOS | Xcode | Clang (`clang` and `clang++`) -Linux | Linux | Ninja | Clang (`clang` and `clang++`) +The project provides [CMake presets](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html) to allow configuring and building Vita3K without having to deal with adding the needed arguments through a command-line or using the user interface of your IDE or code editor of choice. As long as your IDE or code editor supports CMake, the software should immediately detect the presets and let you choose which configure settings you want to use to generate the project. Reference on how to use CMake presets with various IDEs and code editors can be found here: -Vita3K also comes bundled with CMake toolchain files found in `./cmake/toolchain` for each target platform that automatically set up platform-specific variables such as the C/C++ compiler to the values shown in table above and must always be used when generating projects using CMake. Despite this, if needed the set values can be overwritten at project generation as well via CMake `-D` arguments and the project generator will be either the default one for the host OS platform or the one the person building the emulator decides to use. +- [Visual Studio](https://docs.microsoft.com/en-us/cpp/build/cmake-presets-vs) +- [Visual Studio Code](https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/cmake-presets.md) +- [CLion](https://www.jetbrains.com/help/clion/cmake-presets.html): CMake presets in CLion are imported as CLion's [CMake profiles](https://www.jetbrains.com/help/clion/cmake-profile.html). -**Note: Vita3K doesn't support compilation for 32-bit/x86/i386 platforms.** +All presets are named after `--`, are automatically hidden and shown depending on your host OS and generate a binary folder of path `/build/`. For command-line users, run `cmake --list-presets` on the top directory of the repository to see which presets are available to you. For presets without `` and/or ``, the project generator and/or the compiler haven't been explicitly specified in the preset to let CMake fallback to the platform defaults. -For convenience, the following building instructions are given as examples based on the information from the table: +If you still want to use presets but none of them works for your setup, you can create new ones for you creating a `CMakeUserPresets.json` file and you can check the specification [here](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html). Git will ignore this file. + +**Note: Vita3K doesn't support compilation for 32-bit/x86/i386 platforms. macOS is also considered unsupported due to incompatibilities with the OpenGL implementation.** + +For convenience, the following building instructions are given as examples: ## Windows @@ -32,11 +34,13 @@ For convenience, the following building instructions are given as examples based cd Vita3K ``` -- Run Visual Studio 2022. On the project selection window open the local clone of the repository as a folder. Thanks to the integration between Visual Studio and CMake, Visual Studio will automatically setup the project for you. -- Use the [CMake Settings Editor](https://docs.microsoft.com/en-us/cpp/build/customize-cmake-settings?view=msvc-170) to set "CMake toolchain file" to `./cmake/toolchain/windows-x64.cmake`. If asked to do so, delete and re-generate the CMake cache. +- Run Visual Studio 2022. On the project selection window open the local clone of the repository as a folder. Thanks to the integration between Visual Studio and CMake, Visual Studio will automatically detect the repository as a CMake project. +- Wait for all components for Visual Studio to be loaded. At the top of the window, there should be three new menus that allow you to select the target (specific to Visual Studio), a CMake configure preset and a CMake build preset (if available). Recommended preset for Visual Studio 2022 is *Windows with Visual Studio 2022*. From there, the project will be ready to build right from the Visual Studio UI. +If you aren't satisfied with the way the Visual Studio integrates CMake projects and you would like to just use regular Visual Studio solution files (`.sln`), you can close Visual Studio and then open the solution file found in `build//`. + ### Build using terminal - Install: @@ -56,17 +60,19 @@ From there, the project will be ready to build right from the Visual Studio UI. - Generate the project: ```cmd - cmake -S . -B build-windows -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain/windows-x64.cmake + cmake --preset windows-vs2022 ``` - The line above will generate a Visual Studio 2022 project inside a folder called `build-windows`. + The line above will generate a Visual Studio 2022 project inside a folder called `build/windows-vs2022`. - Build the project: ```cmd - cmake --build build-windows + cmake --build build/windows-vs2022 ``` ## macOS (Xcode) +**Note: As of June 2022, running Vita3K in macOS is considered unsupported due to incompatibilities with the OpenGL implementation.** + - Install Xcode at App Store. - Install [`brew`](https://brew.sh). @@ -87,17 +93,17 @@ From there, the project will be ready to build right from the Visual Studio UI. - Generate Xcode project. ``` - cmake -S . -B build-macos -G Xcode -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain/macos-x64.cmake + cmake --preset macos-xcode ``` - This example will generate a Xcode project inside a folder called `build-macos`. + This example will generate a Xcode project inside a folder called `build/macos-xcode`. -- Open Xcode project `vita3k.xcodeproj` generated in `build-macos` directory. +- Open Xcode project `vita3k.xcodeproj` generated in `build/macos-xcode` directory. - When prompted to create schemes, create one for the `vita3k` target only. The project builds many targets, so it will make your life easier if you create schemes as needed. - Build the project using the Xcode UI. If needed, the build process can be invoked as well the same way as with the other platforms using a terminal: ```sh - cmake --build build-macos + cmake --build build/macos-xcode ``` ## Linux @@ -120,25 +126,27 @@ From there, the project will be ready to build right from the Visual Studio UI. - Generate the project. ```sh - cmake -S . -B build-linux -G Ninja -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain/linux-x64.cmake + cmake --preset linux-ninja-clang ``` - This example will generate a Ninja (`ninja-build`) project instead of a Make (`make`, the default project generator for Linux) one inside a folder called `build-linux`. + This example will generate a Ninja Multi-Config (`ninja-build`) project instead of a Make (`make`, the default project generator for Linux) one inside the folder `build/linux-ninja-clang`. - Build the project: ```sh - cmake --build build-linux + cmake --build build/linux-ninja-clang ``` ## Note - After cloning or checking out a branch, you should always update submodules. ```sh - `git submodule update --init --recursive` + git submodule update --init --recursive ``` -- If `boost` failed to build, you can opt out for system `boost` package (Linux and macOS only). +- If Boost failed to build, you can use the system Boost package (Linux and macOS only). ```sh brew install boost # for macOS sudo apt install libboost-filesystem-dev libboost-program-options-dev libboost-system-dev # for Ubuntu/Debian ``` + + If needed, CMake options `VITA3K_FORCE_CUSTOM_BOOST` and `VITA3K_FORCE_SYSTEM_BOOST` can be set to change the way the CMake project looks for Boost. diff --git a/cmake/toolchain/linux-x64.cmake b/cmake/toolchain/linux-x64.cmake deleted file mode 100644 index 92caec501..000000000 --- a/cmake/toolchain/linux-x64.cmake +++ /dev/null @@ -1,18 +0,0 @@ -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_PROCESSOR x64) - -# Fixes issue with setting CMAKE_SYSYEM_NAME manually and the cross-compilation check -if(CMAKE_HOST_SYSTEM_NAME STREQUAL CMAKE_SYSTEM_NAME) - set(CMAKE_CROSSCOMPILING FALSE) -else() - set(CMAKE_CROSSCOMPILING TRUE) -endif() - -# Compiler settings -set(CMAKE_C_COMPILER clang) -set(CMAKE_CXX_COMPILER clang++) - -# Disables cross-compilation -if (CMAKE_CROSSCOMPILING) - message(FATAL_ERROR "Vita3K cross-compilation for Linux isn't supported.") -endif() diff --git a/cmake/toolchain/macos-x64.cmake b/cmake/toolchain/macos-x64.cmake deleted file mode 100644 index bc91db09c..000000000 --- a/cmake/toolchain/macos-x64.cmake +++ /dev/null @@ -1,18 +0,0 @@ -set(CMAKE_SYSTEM_NAME Darwin) -set(CMAKE_SYSTEM_PROCESSOR x64) - -# Fixes issue with setting CMAKE_SYSYEM_NAME manually and the cross-compilation check -if(CMAKE_HOST_SYSTEM_NAME STREQUAL CMAKE_SYSTEM_NAME) - set(CMAKE_CROSSCOMPILING FALSE) -else() - set(CMAKE_CROSSCOMPILING TRUE) -endif() - -# Compiler settings -set(CMAKE_C_COMPILER clang) -set(CMAKE_CXX_COMPILER clang++) - -# Disables cross-compilation -if (CMAKE_CROSSCOMPILING) - message(FATAL_ERROR "Vita3K cross-compilation for macOS isn't supported.") -endif() diff --git a/cmake/toolchain/windows-x64.cmake b/cmake/toolchain/windows-x64.cmake deleted file mode 100644 index e286e66cf..000000000 --- a/cmake/toolchain/windows-x64.cmake +++ /dev/null @@ -1,17 +0,0 @@ -set(CMAKE_SYSTEM_NAME Windows) -set(CMAKE_SYSTEM_PROCESSOR x64) - -# Fixes issue with setting CMAKE_SYSYEM_NAME manually and the cross-compilation check -if(CMAKE_HOST_SYSTEM_NAME STREQUAL CMAKE_SYSTEM_NAME) - set(CMAKE_CROSSCOMPILING FALSE) -else() - set(CMAKE_CROSSCOMPILING TRUE) -endif() - -# Compiler settings -set(CMAKE_C_COMPILER cl) -set(CMAKE_CXX_COMPILER cl) - -if (CMAKE_CROSSCOMPILING) - message(FATAL_ERROR "Vita3K cross-compilation for Windows isn't supported.") -endif() diff --git a/gen-linux.sh b/gen-linux.sh old mode 100755 new mode 100644 index 19c380106..f66a1db89 --- a/gen-linux.sh +++ b/gen-linux.sh @@ -2,4 +2,4 @@ set -ex # Generate project files for Ninja -cmake -S . -B build-linux -G Ninja -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain/linux-x64.cmake +cmake --preset linux-ninja-clang diff --git a/gen-macos.sh b/gen-macos.sh deleted file mode 100755 index 6738f1cb8..000000000 --- a/gen-macos.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -ex - -# Generate project files for Xcode -cmake -S . -B build-macos -G Xcode -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain/macos-x64.cmake diff --git a/gen-windows.bat b/gen-windows.bat index 1d0642c2c..8cf594f26 100644 --- a/gen-windows.bat +++ b/gen-windows.bat @@ -1,5 +1,5 @@ @echo off REM Generate project files for your last Visual Studio version you have -call cmake -S . -B build-windows -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain/windows-x64.cmake +call cmake -S . -B build-windows pause diff --git a/vita3k/CMakeLists.txt b/vita3k/CMakeLists.txt index d4487e28e..4d432fe47 100644 --- a/vita3k/CMakeLists.txt +++ b/vita3k/CMakeLists.txt @@ -58,6 +58,7 @@ if (USE_VULKAN) endif() set_property(GLOBAL PROPERTY USE_FOLDERS ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if(NOT MSVC) add_compile_options(-Wformat -Werror=format-security)