Skip to content

Commit 86b50eb

Browse files
CMake: Introduce Presets, replacing Settings
This introduces a CMakePresets file for both Linux 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, and can be used using Visual Studio's built-in CMakePresets support, or Visual Studio Code's CMake Tools extension. They can also be used from the command line, like so: x64/Linux: Configure: `cmake --preset unix-release-x64` Build: `cmake --build --preset unix-build-release-x64` Configure + Build: `cmake --workflow --preset unix-release-x64` ARM64/Windows: Configure: `cmake --preset windows-release-arm64` Build: `cmake --build --preset windows-build-release-arm64` Configure + Build: `cmake --workflow --preset windows-release-arm64` **Cross-compiling** On Windows, the Visual Studio generator automatically takes care of selecting the cross-compiler if required. On Linux, the Ninja generator is used. 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 unix-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 unix-build-release-arm64` You will need a sysroot to link against Qt, since we do not vendor it in on platforms other than Windows. 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": "unix-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": "unix-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" } } ], "buildPresets": [ { "name": "gcc-build-debug-arm64", "configurePreset": "gcc-debug-arm64" }, { "name": "clang-build-debug-arm64", "configurePreset": "clang-debug-arm64" } ], "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" } ] } ] } ``` 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` These changes should also make it trivial to cross-compile from Linux to FreeBSD and vice-versa, however this is untested.
1 parent d04bfb9 commit 86b50eb

File tree

5 files changed

+506
-147
lines changed

5 files changed

+506
-147
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ CMakeLists.txt.user
4343
/.vscode/
4444
# Ignore flatpak-builder's cache dir
4545
.flatpak-builder
46+
# Ignore CMake user presets
47+
CMakeUserPresets.json

CMake/DolphinToolchain.cmake

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
set(ARCH "generic" CACHE STRING "Target architecture")
2+
3+
set(VALID_ARCHS x86_64 arm64 generic)
4+
if(NOT ARCH IN_LIST VALID_ARCHS)
5+
message(FATAL_ERROR "Invalid ARCH='${ARCH}'. Valid: ${VALID_ARCHS}")
6+
endif()
7+
8+
if(ARCH STREQUAL "generic")
9+
set(ENABLE_GENERIC "ON")
10+
else()
11+
set(CMAKE_SYSTEM_PROCESSOR "${ARCH}")
12+
endif()
13+
14+
if (NOT DEFINED CMAKE_SYSTEM_NAME)
15+
if(EXISTS "${CMAKE_SYSROOT}/usr/include/linux")
16+
set(CMAKE_SYSTEM_NAME Linux)
17+
elseif(EXISTS "${CMAKE_SYSROOT}/Windows/System32")
18+
set(CMAKE_SYSTEM_NAME Windows)
19+
elseif(EXISTS "${CMAKE_SYSROOT}/System/Library")
20+
set(CMAKE_SYSTEM_NAME Darwin)
21+
elseif(EXISTS "${CMAKE_SYSROOT}/usr/include/osreldate.h")
22+
set(CMAKE_SYSTEM_NAME FreeBSD)
23+
elseif(EXISTS "${CMAKE_SYSROOT}/usr/include/c++/v1/__locale_dir/locale_base_api/openbsd.h")
24+
set(CMAKE_SYSTEM_NAME OpenBSD)
25+
elseif(EXISTS "${CMAKE_SYSROOT}/usr/include/dev/dm/netbsd-dm.h")
26+
set(CMAKE_SYSTEM_NAME NetBSD)
27+
elseif(EXISTS "${CMAKE_SYSROOT}/boot/system/develop")
28+
set(CMAKE_SYSTEM_NAME Haiku)
29+
else()
30+
message(WARNING "Cannot detect OS from sysroot '${CMAKE_SYSROOT}/'. Cross-compilation has been disabled.")
31+
endif()
32+
endif()
33+
34+
set(CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT}")
35+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
36+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
37+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
38+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
39+
40+
if(NOT QT_HOST_PATH)
41+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
42+
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "AMD64")
43+
set(QT_HOST_PATH "${CMAKE_SOURCE_DIR}/Externals/Qt/Qt6.5.1/x64")
44+
else()
45+
set(QT_HOST_PATH "${CMAKE_SOURCE_DIR}/Externals/Qt/Qt6.5.1/ARM64")
46+
endif()
47+
else()
48+
set(QT_HOST_PATH "/usr")
49+
endif()
50+
endif()

0 commit comments

Comments
 (0)