Skip to content

Commit ee3f863

Browse files
committed
Make CMAKE_OSX_ARCHITECTURES a cache variable and update docs
1 parent 98d48c7 commit ee3f863

7 files changed

+42
-14
lines changed

Diff for: CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.22)
22

3-
include(cmake/UniversalAppleBuild.cmake)
3+
include(cmake/AppleBuild.cmake)
44

55
project(
66
BasicGuiProjectSetupOpenGL

Diff for: CMakePresets.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"generator": "Xcode",
2626
"binaryDir": "build/xcode-debug",
2727
"cacheVariables": {
28-
"CMAKE_BUILD_TYPE": "Debug"
28+
"CMAKE_BUILD_TYPE": "Debug",
29+
"CMAKE_OSX_ARCHITECTURES": "x86_64;arm64"
2930
},
3031
"condition": {
3132
"type": "equals",
@@ -39,7 +40,8 @@
3940
"generator": "Xcode",
4041
"binaryDir": "build/xcode-release",
4142
"cacheVariables": {
42-
"CMAKE_BUILD_TYPE": "Release"
43+
"CMAKE_BUILD_TYPE": "Release",
44+
"CMAKE_OSX_ARCHITECTURES": "x86_64;arm64"
4345
},
4446
"condition": {
4547
"type": "equals",

Diff for: cmake/UniversalAppleBuild.cmake renamed to cmake/AppleBuild.cmake

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# This file needs to be included before calling `project`.
22
if (APPLE AND "${CMAKE_GENERATOR}" STREQUAL "Xcode")
3-
# Generate universal executable for Apple hardware.
4-
set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)")
3+
# Define apple architecture for Release builds, use default. For an explicit
4+
# universal executable use `x86_64;arm64`.
5+
set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)" CACHE INTERNAL "OS X architecture")
56

67
# Support older macOS versions.
78
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15 CACHE STRING "Minimum OS X deployment version")

Diff for: docs/BuildAndExecution.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ Run on a built target, in this example **debug**:
8989
```
9090

9191
Though, even better is to use **Xcode as generator** to create app builds on macOS. Only difference in usage is running
92-
CMake with `-GXcode`. If `CMAKE_OSX_ARCHITECTURES` is not set, it will create universal binaries on M1/2 macs.
92+
CMake with `-GXcode` and setting the `CMAKE_OSX_ARCHITECTURES` variable, for example to `x86_64;arm64` for a universal
93+
binaries.
9394

9495
To run a **debug** build created with Xcode:
9596

Diff for: docs/CMakePresets.md

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ cpack --preset release
6767

6868
## Workflows
6969

70+
> [!IMPORTANT]
71+
> Workflow presets are only available in CMake version 3.25 and up.
72+
7073
To list all available workflows, some dependent on the current system:
7174

7275
```shell

Diff for: docs/Packaging.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Packaging settings for the application executable are in `src/app/cmake/packagin
2323
The final application build for Apple devices should be built via the `Xcode` generator with CMake.
2424

2525
```shell
26-
cmake -GXcode -DCMAKE_BUILD_TYPE=Release -B build/xcode
27-
cmake --build build/xcode
26+
cmake -GXcode -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -B build/xcode
27+
cmake --build build/xcode --config Release
2828
```
2929

3030
### Windows
@@ -61,8 +61,8 @@ system**.
6161
Xcode should be used to create the release build for the application distributable.
6262

6363
```shell
64-
cmake -GXcode -DCMAKE_BUILD_TYPE=Release -B build/xcode
65-
cmake --build build/xcode
64+
cmake -GXcode -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -B build/xcode
65+
cmake --build build/xcode --config Release
6666
cpack --config build/xcode/CPackConfig.cmake
6767
```
6868

Diff for: docs/QuickStart.md

+25-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Having all [requirements](README.md#requirements) set, here you can find how to
44

55
## Table of contents
66

7+
- [TL;DR](#tldr)
78
- [Build](#build)
89
- [Execute](#execute)
910
- [macOS](#macos)
@@ -12,6 +13,24 @@ Having all [requirements](README.md#requirements) set, here you can find how to
1213
- [Distribution](#distribution)
1314
- [Tests](#tests)
1415

16+
## TL;DR
17+
18+
> [!IMPORTANT]
19+
> Workflow presets are only available in CMake version 3.25 and up.
20+
21+
The quickest way possible to get an actual distributable from zero is using the available CMake workflows. For Linux and
22+
Windows:
23+
24+
```shell
25+
cmake --workflow --preset dist
26+
```
27+
28+
And for macOS with Xcode:
29+
30+
```shell
31+
cmake --workflow --preset xcode-dist
32+
```
33+
1534
## Build
1635

1736
Usually available build modes are `Debug`, `Release`, and `RelWithDebInfo`.
@@ -30,12 +49,14 @@ cmake -GNinja -DCMAKE_BUILD_TYPE=Release -B build/release
3049
cmake --build build/release
3150
```
3251

33-
On macOS Xcode should be used as generator via `-GXCode`. For example creating a release build with XCode.
52+
On macOS Xcode should be used as generator via `-GXcode`. For example creating a release build with XCode. It is also
53+
necessary to specify the Apple architecture via `CMAKE_OSX_ARCHITECTURES`, for example for a universal executable using
54+
the value `x86_64;arm64"`.
3455

3556
```shell
36-
# Using Xcode
37-
cmake -GXcode -DCMAKE_BUILD_TYPE=Release -B build/xcode
38-
cmake --build build/xcode
57+
# Using Xcode, create universal executable
58+
cmake -GXcode -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -B build/xcode
59+
cmake --build build/xcode --config Release
3960
```
4061

4162
## Execute

0 commit comments

Comments
 (0)