Commit 86b50eb
committed
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- CMake
5 files changed
+506
-147
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
0 commit comments