CMake: Introduce Presets, replacing Settings

This introduces a CMakePresets file for both Unix-likes and Windows that replace the old CMakeSettings.

It adds presets for **Debug** and **Release** profiles for both **x64** and **ARM64** architectures, as well as **Generic builds**.
Presets can be used using[ Visual Studio's built-in CMakePresets support](https://learn.microsoft.com/en-us/cpp/build/cmake-presets-vs?view=msvc-170), or [Visual Studio Code's CMake Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) extension.

They can also be used from the command line, like so:

- x64/Unix-like/Ninja:
  - Configure: `cmake --preset ninja-release-x64`
  - Build: `cmake --build --preset ninja-build-release-x64`
  - Configure + Build: `cmake --workflow --preset ninja-release-x64`
- ARM64/Windows/Visual Studio:
  - Configure: `cmake --preset visualstudio-release-arm64`
  - Build: `cmake --build --preset visualstudio-build-release-arm64`
  - Configure + Build: `cmake --workflow --preset visualstudio-release-arm64`

The Ninja generator is available to both Windows and Unix-likes, while the Visual Studio Generator is only available on Windows.

**Cross-compiling**

On **Windows**, the Visual Studio generator automatically takes care of everything, you just need to select an ARM64 preset.

On **Unix-likes**, to cross-compile you need to install a cross-compiler and (optionally) a sysroot of the target system.
Here is an example to compile from x64 to ARM64 with a sysroot:

- `cmake --preset ninja-release-arm64 -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_SYSROOT=/opt/sysroots/aarch64-linux-gnu`
- `cmake --build --preset ninja-build-release-arm64`

You will need a sysroot to link against Qt, since we do not vendor it in on platforms other than Windows.

**User presets**

A `CMakeUserPresets.json` file may be created locally at the root of the project to further customize your presets.
For example, here are the user presets I used to test this PR on Arch Linux with a generic Arch Linux ARM sysroot:

```json
{
  "version": 10,
  "configurePresets": [
    {
      "name": "gcc-debug-arm64",
      "inherits": "ninja-debug-arm64",
      "cacheVariables": {
        "CMAKE_C_COMPILER": "aarch64-linux-gnu-gcc",
        "CMAKE_CXX_COMPILER": "aarch64-linux-gnu-g++",
        "CMAKE_EXE_LINKER_FLAGS": "-L/opt/sysroots/ArchLinuxARM/lib",
        "CMAKE_SYSROOT": "/opt/sysroots/ArchLinuxARM"
      }
    },
    {
      "name": "clang-debug-arm64",
      "inherits": "ninja-debug-arm64",
      "cacheVariables": {
        "CMAKE_C_COMPILER": "clang",
        "CMAKE_CXX_COMPILER": "clang++",
        "CMAKE_C_FLAGS": "-target aarch64-linux-gnu",
        "CMAKE_CXX_FLAGS": "-target aarch64-linux-gnu",
        "CMAKE_SYSROOT": "/opt/sysroots/ArchLinuxARM"
      }
    },
    {
      "name": "clang-debug-x64",
      "inherits": "ninja-debug-x64",
      "cacheVariables": {
        "CMAKE_C_COMPILER": "clang",
        "CMAKE_CXX_COMPILER": "clang++"
      }
    }
  ],
  "buildPresets": [
    {
      "name": "gcc-build-debug-arm64",
      "configurePreset": "gcc-debug-arm64"
    },
    {
      "name": "clang-build-debug-arm64",
      "configurePreset": "clang-debug-arm64"
    },
    {
      "name": "clang-build-debug-x64",
      "configurePreset": "clang-debug-x64"
    }
  ],
  "workflowPresets": [
    {
      "name": "gcc-debug-arm64",
      "steps": [
        { "type": "configure", "name": "gcc-debug-arm64" },
        { "type": "build", "name": "gcc-build-debug-arm64" }
      ]
    },
    {
      "name": "clang-debug-arm64",
      "steps": [
        { "type": "configure", "name": "clang-debug-arm64" },
        { "type": "build", "name": "clang-build-debug-arm64" }
      ]
    },
    {
      "name": "clang-debug-x64",
      "steps": [
        { "type": "configure", "name": "clang-debug-x64" },
        { "type": "build", "name": "clang-build-debug-x64" }
      ]
    }
  ]
}
```

They are then used like so:
Configure + Build with GCC: `cmake --workflow --preset gcc-debug-arm64`
Configure + Build with Clang: `cmake --workflow --preset clang-debug-arm64`
Configure + Build with Clang (x64): `cmake --workflow --preset clang-debug-x64`

*Addendum: It should also now be possible to cross-compile from Windows to Unix-likes, and Unix-like to other Unix-like (e.g. Linux -> FreeBSD), however this is untested.*
This commit is contained in:
Joshua Vandaële 2025-12-11 03:29:56 +01:00
parent 6551c9bc24
commit 3b91d2b74d
No known key found for this signature in database
GPG Key ID: 6BB95AF71EB0F406
5 changed files with 460 additions and 149 deletions

2
.gitignore vendored
View File

@ -43,3 +43,5 @@ CMakeLists.txt.user
/.vscode/
# Ignore flatpak-builder's cache dir
.flatpak-builder
# Ignore CMake user presets
CMakeUserPresets.json

View File

@ -0,0 +1,50 @@
set(ARCH "generic" CACHE STRING "Target architecture")
set(VALID_ARCHS x86_64 arm64 generic)
if(NOT ARCH IN_LIST VALID_ARCHS)
message(FATAL_ERROR "Invalid ARCH='${ARCH}'. Valid: ${VALID_ARCHS}")
endif()
if(ARCH STREQUAL "generic")
set(ENABLE_GENERIC "ON")
else()
set(CMAKE_SYSTEM_PROCESSOR "${ARCH}")
endif()
if (NOT DEFINED CMAKE_SYSTEM_NAME)
if(EXISTS "${CMAKE_SYSROOT}/usr/include/linux")
set(CMAKE_SYSTEM_NAME Linux)
elseif(EXISTS "${CMAKE_SYSROOT}/Windows/System32")
set(CMAKE_SYSTEM_NAME Windows)
elseif(EXISTS "${CMAKE_SYSROOT}/System/Library")
set(CMAKE_SYSTEM_NAME Darwin)
elseif(EXISTS "${CMAKE_SYSROOT}/usr/include/osreldate.h")
set(CMAKE_SYSTEM_NAME FreeBSD)
elseif(EXISTS "${CMAKE_SYSROOT}/usr/include/c++/v1/__locale_dir/locale_base_api/openbsd.h")
set(CMAKE_SYSTEM_NAME OpenBSD)
elseif(EXISTS "${CMAKE_SYSROOT}/usr/include/dev/dm/netbsd-dm.h")
set(CMAKE_SYSTEM_NAME NetBSD)
elseif(EXISTS "${CMAKE_SYSROOT}/boot/system/develop")
set(CMAKE_SYSTEM_NAME Haiku)
else()
message(WARNING "Cannot detect OS from sysroot '${CMAKE_SYSROOT}/'. Cross-compilation has been disabled.")
endif()
endif()
set(CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
if(NOT QT_HOST_PATH)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "AMD64")
set(QT_HOST_PATH "${CMAKE_SOURCE_DIR}/Externals/Qt/Qt6.5.1/x64")
else()
set(QT_HOST_PATH "${CMAKE_SOURCE_DIR}/Externals/Qt/Qt6.5.1/ARM64")
endif()
else()
set(QT_HOST_PATH "/usr")
endif()
endif()

397
CMakePresets.json Normal file
View File

@ -0,0 +1,397 @@
{
"version": 6,
"configurePresets": [
{
"name": "ninja-generator",
"generator": "Ninja",
"hidden": true
},
{
"name": "visualstudio-generator",
"generator": "Visual Studio 18 2026",
"toolset": {
"value": "v145",
"strategy": "set"
},
"hidden": true
},
{
"name": "release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_CONFIGURATION_TYPES": "Release"
},
"hidden": true
},
{
"name": "debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_CONFIGURATION_TYPES": "Debug"
},
"hidden": true
},
{
"name": "generic",
"binaryDir": "${sourceDir}/build/generic",
"toolchainFile": "CMake/DolphinToolchain.cmake",
"cacheVariables": {
"ARCH": "generic"
},
"hidden": true
},
{
"name": "x64",
"binaryDir": "${sourceDir}/build/x64",
"toolchainFile": "CMake/DolphinToolchain.cmake",
"cacheVariables": {
"ARCH": "x86_64"
},
"hidden": true
},
{
"name": "arm64",
"binaryDir": "${sourceDir}/build/ARM64",
"toolchainFile": "CMake/DolphinToolchain.cmake",
"cacheVariables": {
"ARCH": "arm64"
},
"hidden": true
},
{
"name": "visualstudio-generic",
"inherits": ["generic", "visualstudio-generator"],
"hidden": true
},
{
"name": "visualstudio-x64",
"inherits": ["x64", "visualstudio-generator"],
"architecture": {
"value": "x64",
"strategy": "set"
},
"hidden": true
},
{
"name": "visualstudio-arm64",
"inherits": ["arm64", "visualstudio-generator"],
"architecture": {
"value": "arm64",
"strategy": "set"
},
"hidden": true
},
{
"name": "ninja-generic",
"inherits": ["generic", "ninja-generator"],
"hidden": true
},
{
"name": "ninja-x64",
"architecture": {
"value": "x64",
"strategy": "external"
},
"inherits": ["x64", "ninja-generator"],
"hidden": true
},
{
"name": "ninja-arm64",
"architecture": {
"value": "arm64",
"strategy": "external"
},
"inherits": ["arm64", "ninja-generator"],
"hidden": true
},
{
"name": "visualstudio-release-generic",
"displayName": "Configure: Release - Visual Studio - Generic",
"inherits": ["release", "visualstudio-generic"],
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "visualstudio-release-x64",
"displayName": "Configure: Release - Visual Studio - x64",
"inherits": ["release", "visualstudio-x64"],
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "visualstudio-release-arm64",
"displayName": "Configure: Release - Visual Studio - ARM64",
"inherits": ["release", "visualstudio-arm64"],
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "visualstudio-debug-generic",
"displayName": "Configure: Debug - Visual Studio - Generic",
"inherits": ["debug", "visualstudio-generic"],
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "visualstudio-debug-x64",
"displayName": "Configure: Debug - Visual Studio - x64",
"inherits": ["debug", "visualstudio-x64"],
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "visualstudio-debug-arm64",
"displayName": "Configure: Debug - Visual Studio - ARM64",
"inherits": ["debug", "visualstudio-arm64"],
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "ninja-release-generic",
"displayName": "Configure: Release - Ninja - Generic",
"inherits": ["release", "ninja-generic"]
},
{
"name": "ninja-release-x64",
"displayName": "Configure: Release - Ninja - x64",
"inherits": ["release", "ninja-x64"]
},
{
"name": "ninja-release-arm64",
"displayName": "Configure: Release - Ninja - ARM64",
"inherits": ["release", "ninja-arm64"]
},
{
"name": "ninja-debug-generic",
"displayName": "Configure: Debug - Ninja - Generic",
"inherits": ["debug", "ninja-generic"]
},
{
"name": "ninja-debug-x64",
"displayName": "Configure: Debug - Ninja - x64",
"inherits": ["debug", "ninja-x64"]
},
{
"name": "ninja-debug-arm64",
"displayName": "Configure: Debug - Ninja - ARM64",
"inherits": ["debug", "ninja-arm64"]
}
],
"buildPresets": [
{
"name": "visualstudio-build-release-generic",
"displayName": "Build: Release - Visual Studio - Generic",
"configurePreset": "visualstudio-release-generic",
"configuration": "Release",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "visualstudio-build-release-x64",
"displayName": "Build: Release - Visual Studio - x64",
"configurePreset": "visualstudio-release-x64",
"configuration": "Release",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "visualstudio-build-release-arm64",
"displayName": "Build: Release - Visual Studio - ARM64",
"configurePreset": "visualstudio-release-arm64",
"configuration": "Release",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "visualstudio-build-debug-generic",
"displayName": "Build: Debug - Visual Studio - Generic",
"configurePreset": "visualstudio-debug-generic",
"configuration": "Debug",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "visualstudio-build-debug-x64",
"displayName": "Build: Debug - Visual Studio - x64",
"configurePreset": "visualstudio-debug-x64",
"configuration": "Debug",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "visualstudio-build-debug-arm64",
"displayName": "Build: Debug - Visual Studio - ARM64",
"configurePreset": "visualstudio-debug-arm64",
"configuration": "Debug",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "ninja-build-release-generic",
"displayName": "Build: Release - Ninja - Generic",
"configurePreset": "ninja-release-generic"
},
{
"name": "ninja-build-release-x64",
"displayName": "Build: Release - Ninja - x64",
"configurePreset": "ninja-release-x64"
},
{
"name": "ninja-build-release-arm64",
"displayName": "Build: Release - Ninja - ARM64",
"configurePreset": "ninja-release-arm64"
},
{
"name": "ninja-build-debug-generic",
"displayName": "Build: Debug - Ninja - Generic",
"configurePreset": "ninja-debug-generic"
},
{
"name": "ninja-build-debug-x64",
"displayName": "Build: Debug - Ninja - x64",
"configurePreset": "ninja-debug-x64"
},
{
"name": "ninja-build-debug-arm64",
"displayName": "Build: Debug - Ninja - ARM64",
"configurePreset": "ninja-debug-arm64"
}
],
"workflowPresets": [
{
"name": "visualstudio-release-generic",
"displayName": "Release - Visual Studio - Generic",
"steps": [
{ "type": "configure", "name": "visualstudio-release-generic" },
{ "type": "build", "name": "visualstudio-build-release-generic" }
]
},
{
"name": "visualstudio-release-x64",
"displayName": "Release - Visual Studio - x64",
"steps": [
{ "type": "configure", "name": "visualstudio-release-x64" },
{ "type": "build", "name": "visualstudio-build-release-x64" }
]
},
{
"name": "visualstudio-release-arm64",
"displayName": "Release - Visual Studio - ARM64",
"steps": [
{ "type": "configure", "name": "visualstudio-release-arm64" },
{ "type": "build", "name": "visualstudio-build-release-arm64" }
]
},
{
"name": "visualstudio-debug-generic",
"displayName": "Debug - Visual Studio - Generic",
"steps": [
{ "type": "configure", "name": "visualstudio-debug-generic" },
{ "type": "build", "name": "visualstudio-build-debug-generic" }
]
},
{
"name": "visualstudio-debug-x64",
"displayName": "Debug - Visual Studio - x64",
"steps": [
{ "type": "configure", "name": "visualstudio-debug-x64" },
{ "type": "build", "name": "visualstudio-build-debug-x64" }
]
},
{
"name": "visualstudio-debug-arm64",
"displayName": "Debug - Visual Studio - ARM64",
"steps": [
{ "type": "configure", "name": "visualstudio-debug-arm64" },
{ "type": "build", "name": "visualstudio-build-debug-arm64" }
]
},
{
"name": "ninja-release-generic",
"displayName": "Release - Ninja - Generic",
"steps": [
{ "type": "configure", "name": "ninja-release-generic" },
{ "type": "build", "name": "ninja-build-release-generic" }
]
},
{
"name": "ninja-release-x64",
"displayName": "Release - Ninja - x64",
"steps": [
{ "type": "configure", "name": "ninja-release-x64" },
{ "type": "build", "name": "ninja-build-release-x64" }
]
},
{
"name": "ninja-release-arm64",
"displayName": "Release - Ninja - ARM64",
"steps": [
{ "type": "configure", "name": "ninja-release-arm64" },
{ "type": "build", "name": "ninja-build-release-arm64" }
]
},
{
"name": "ninja-debug-generic",
"displayName": "Debug - Ninja - Generic",
"steps": [
{ "type": "configure", "name": "ninja-debug-generic" },
{ "type": "build", "name": "ninja-build-debug-generic" }
]
},
{
"name": "ninja-debug-x64",
"displayName": "Debug - Ninja - x64",
"steps": [
{ "type": "configure", "name": "ninja-debug-x64" },
{ "type": "build", "name": "ninja-build-debug-x64" }
]
},
{
"name": "ninja-debug-arm64",
"displayName": "Debug - Ninja - ARM64",
"steps": [
{ "type": "configure", "name": "ninja-debug-arm64" },
{ "type": "build", "name": "ninja-build-debug-arm64" }
]
}
]
}

View File

@ -1,64 +0,0 @@
{
"configurations": [
{
"name": "Release",
"configurationType": "Release",
"generator": "Ninja",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildCommandArgs": "",
"buildRoot": "${workspaceRoot}\\Build\\${name}",
"cmakeCommandArgs": "",
"variables": [
]
},
{
"name": "Debug",
"configurationType": "Debug",
"generator": "Ninja",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildCommandArgs": "",
"buildRoot": "${workspaceRoot}\\Build\\${name}",
"cmakeCommandArgs": "",
"variables": [
]
},
{
"name": "Release (arm64)",
"configurationType": "Release",
"generator": "Ninja",
"inheritEnvironments": [ "msvc_arm64_x64" ],
"buildCommandArgs": "",
"buildRoot": "${workspaceRoot}\\Build\\${name}",
"cmakeCommandArgs": "",
"variables": [
{
"name": "CMAKE_SYSTEM_NAME",
"value": "Windows"
},
{
"name": "CMAKE_SYSTEM_PROCESSOR",
"value": "aarch64"
}
]
},
{
"name": "Debug (arm64)",
"configurationType": "Debug",
"generator": "Ninja",
"inheritEnvironments": [ "msvc_arm64_x64" ],
"buildCommandArgs": "",
"buildRoot": "${workspaceRoot}\\Build\\${name}",
"cmakeCommandArgs": "",
"variables": [
{
"name": "CMAKE_SYSTEM_NAME",
"value": "Windows"
},
{
"name": "CMAKE_SYSTEM_PROCESSOR",
"value": "aarch64"
}
]
}
]
}

View File

@ -36,101 +36,27 @@ Please read the [FAQ](https://dolphin-emu.org/docs/faq/) before using Dolphin.
Dolphin can only be installed on devices that satisfy the above requirements. Attempting to install on an unsupported device will fail and display an error message.
## Building for Windows
## Building
Use the solution file `Source/dolphin-emu.sln` to build Dolphin on Windows.
Dolphin targets the latest MSVC shipped with Visual Studio or Build Tools.
Other compilers might be able to build Dolphin on Windows but have not been
tested and are not recommended to be used. Git and latest Windows SDK must be
installed when building.
You may find building instructions on the appropriate wiki page for your operating system:
* [Windows](https://github.com/dolphin-emu/dolphin/wiki/Building-for-Windows)
* [Linux](https://github.com/dolphin-emu/dolphin/wiki/Building-for-Linux)
* [macOS](https://github.com/dolphin-emu/dolphin/wiki/Building-for-macOS)
* [Android](#android-specific-instructions) <!-- TODO: Create a "Building for Android" wiki page and link it here -->
* [OpenBSD](https://github.com/dolphin-emu/dolphin/wiki/Building-for-OpenBSD) (unsupported)
Before building, make sure to pull all submodules:
Make sure to pull submodules before building:
```sh
git submodule update --init --recursive
```
The "Release" solution configuration includes performance optimizations for the best user experience but complicates debugging Dolphin.
The "Debug" solution configuration is significantly slower, more verbose and less permissive but makes debugging Dolphin easier.
## Building for Linux and macOS
Dolphin requires [CMake](https://cmake.org/) for systems other than Windows.
You need a recent version of GCC or Clang with decent c++20 support. CMake will
inform you if your compiler is too old.
Many libraries are bundled with Dolphin and used if they're not installed on
your system. CMake will inform you if a bundled library is used or if you need
to install any missing packages yourself. You may refer to the [wiki](https://github.com/dolphin-emu/dolphin/wiki/Building-for-Linux) for more information.
Make sure to pull submodules before building:
```sh
git submodule update --init --recursive
```
### macOS Build Steps:
A binary supporting a single architecture can be built using the following steps:
1. `mkdir build`
2. `cd build`
3. `cmake ..`
4. `make -j $(sysctl -n hw.logicalcpu)`
An application bundle will be created in `./Binaries`.
A script is also provided to build universal binaries supporting both x64 and ARM in the same
application bundle using the following steps:
1. `mkdir build`
2. `cd build`
3. `python ../BuildMacOSUniversalBinary.py`
4. Universal binaries will be available in the `universal` folder
Doing this is more complex as it requires installation of library dependencies for both x64 and ARM (or universal library
equivalents) and may require specifying additional arguments to point to relevant library locations.
Execute BuildMacOSUniversalBinary.py --help for more details.
### Linux Global Build Steps:
To install to your system.
1. `mkdir build`
2. `cd build`
3. `cmake ..`
4. `make -j $(nproc)`
5. `sudo make install`
### Linux Local Build Steps:
Useful for development as root access is not required.
1. `mkdir Build`
2. `cd Build`
3. `cmake .. -DLINUX_LOCAL_DEV=true`
4. `make -j $(nproc)`
5. `ln -s ../../Data/Sys Binaries/`
### Linux Portable Build Steps:
Can be stored on external storage and used on different Linux systems.
Or useful for having multiple distinct Dolphin setups for testing/development/TAS.
1. `mkdir Build`
2. `cd Build`
3. `cmake .. -DLINUX_LOCAL_DEV=true`
4. `make -j $(nproc)`
5. `cp -r ../Data/Sys/ Binaries/`
6. `touch Binaries/portable.txt`
## Building for Android
### Android-specific instructions
These instructions assume familiarity with Android development. If you do not have an
Android dev environment set up, see [AndroidSetup.md](AndroidSetup.md).
Make sure to pull submodules before building:
```sh
git submodule update --init --recursive
```
If using Android Studio, import the Gradle project located in `./Source/Android`.
Android apps are compiled using a build system called Gradle. Dolphin's native component,