Skip to content

Commit

Permalink
Make CMAKE_OSX_ARCHITECTURES a cache variable and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHelmut committed Apr 13, 2024
1 parent a768f31 commit 9bdc3ee
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.22)

include(cmake/UniversalAppleBuild.cmake)
include(cmake/AppleBuild.cmake)

project(
BasicGuiProjectSetupOpenGL
Expand Down
6 changes: 4 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"generator": "Xcode",
"binaryDir": "build/xcode-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_OSX_ARCHITECTURES": "x86_64;arm64"
},
"condition": {
"type": "equals",
Expand All @@ -39,7 +40,8 @@
"generator": "Xcode",
"binaryDir": "build/xcode-release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_OSX_ARCHITECTURES": "x86_64;arm64"
},
"condition": {
"type": "equals",
Expand Down
5 changes: 3 additions & 2 deletions cmake/UniversalAppleBuild.cmake → cmake/AppleBuild.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# This file needs to be included before calling `project`.
if (APPLE AND "${CMAKE_GENERATOR}" STREQUAL "Xcode")
# Generate universal executable for Apple hardware.
set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)")
# Define apple architecture for Release builds, use default. For an explicit
# universal executable use `x86_64;arm64`.
set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)" CACHE INTERNAL "OS X architecture")

# Support older macOS versions.
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15 CACHE STRING "Minimum OS X deployment version")
Expand Down
3 changes: 2 additions & 1 deletion docs/BuildAndExecution.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ Run on a built target, in this example **debug**:
```

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

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

Expand Down
3 changes: 3 additions & 0 deletions docs/CMakePresets.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ cpack --preset release

## Workflows

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

```shell
Expand Down
8 changes: 4 additions & 4 deletions docs/Packaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Packaging settings for the application executable are in `src/app/cmake/packagin
The final application build for Apple devices should be built via the `Xcode` generator with CMake.

```shell
cmake -GXcode -DCMAKE_BUILD_TYPE=Release -B build/xcode
cmake --build build/xcode
cmake -GXcode -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -B build/xcode
cmake --build build/xcode --config Release
```

### Windows
Expand Down Expand Up @@ -61,8 +61,8 @@ system**.
Xcode should be used to create the release build for the application distributable.

```shell
cmake -GXcode -DCMAKE_BUILD_TYPE=Release -B build/xcode
cmake --build build/xcode
cmake -GXcode -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -B build/xcode
cmake --build build/xcode --config Release
cpack --config build/xcode/CPackConfig.cmake
```

Expand Down
29 changes: 25 additions & 4 deletions docs/QuickStart.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Having all [requirements](README.md#requirements) set, here you can find how to

## Table of contents

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

## TL;DR

> [!IMPORTANT]
> Workflow presets are only available in CMake version 3.25 and up.
The quickest way possible to get an actual distributable from zero is using the available CMake workflows. For Linux and
Windows:

```shell
cmake --workflow --preset dist
```

And for macOS with Xcode:

```shell
cmake --workflow --preset xcode-dist
```

## Build

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

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

```shell
# Using Xcode
cmake -GXcode -DCMAKE_BUILD_TYPE=Release -B build/xcode
cmake --build build/xcode
# Using Xcode, create universal executable
cmake -GXcode -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -B build/xcode
cmake --build build/xcode --config Release
```

## Execute
Expand Down

0 comments on commit 9bdc3ee

Please sign in to comment.