Skip to content

Fix macOS build and Linux icon #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 0 additions & 2 deletions src/app/cmake/AppAssets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(MACOSX_STATIC_ASSETS
${SHARED_STATIC_ASSETS}
${PROJECT_SOURCE_DIR}/src/assets/icons/icon.icns)
set_source_files_properties(${MACOSX_STATIC_ASSETS}
PROPERTIES MACOSX_PACKAGE_LOCATION ${CMAKE_INSTALL_DATADIR})
target_sources(${NAME} PUBLIC ${MACOSX_STATIC_ASSETS})
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_sources(${NAME} PRIVATE ${SHARED_STATIC_ASSETS})
Expand Down
6 changes: 3 additions & 3 deletions src/app/cmake/packaging/Linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/assets/ DESTINATION ${CMAKE_INSTALL_
# Linux app icon setup
configure_file(
${PROJECT_SOURCE_DIR}/src/app/Manifests/App.desktop.in
${CMAKE_CURRENT_BINARY_DIR}/App.desktop
${CMAKE_CURRENT_BINARY_DIR}/${NAME}.desktop
@ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/App.desktop
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.desktop
DESTINATION share/applications)
install(FILES ${PROJECT_SOURCE_DIR}/src/assets/icons/BaseAppIcon.png
DESTINATION share/pixmaps
RENAME ${APP_NAME}_icon.png)
RENAME ${NAME}_icon.png)
6 changes: 2 additions & 4 deletions src/core/Core/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Application::Application(const std::string& title) {
APP_PROFILE_FUNCTION();

const unsigned int init_flags{SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMEPAD};
if (SDL_Init(init_flags) != 0) {
APP_ERROR("Error: %s\n", SDL_GetError());
if (!SDL_Init(init_flags)) {
APP_ERROR("Error on SDL_Init(): %s\n", SDL_GetError());
m_exit_status = ExitStatus::FAILURE;
}

Expand All @@ -26,8 +26,6 @@ Application::Application(const std::string& title) {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");

m_window = std::make_unique<Window>(Window::Settings{title});
}

Expand Down
9 changes: 6 additions & 3 deletions src/core/Core/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Window::Window(const Settings& settings)
Window::~Window() {
APP_PROFILE_FUNCTION();

SDL_GL_DeleteContext(m_gl_context);
SDL_GL_DestroyContext(m_gl_context);
SDL_DestroyWindow(m_window);

ImGui_ImplOpenGL3_Shutdown();
Expand Down Expand Up @@ -100,7 +100,7 @@ void Window::update() {
if (ImGui::BeginMenu("View")) {
ImGui::MenuItem("Some Panel", nullptr, &m_show_some_panel);
ImGui::MenuItem("ImGui Demo Panel", nullptr, &m_show_demo_panel);
ImGui::MenuItem("Debug Panel", nullptr, &m_show_debug_panel);
ImGui::MenuItem("Debug Panels", nullptr, &m_show_debug_panel);
ImGui::EndMenu();
}

Expand All @@ -121,7 +121,10 @@ void Window::update() {

// Debug panel
if (m_show_debug_panel) {
ImGui::Begin("Debug panel", &m_show_debug_panel);
ImGui::ShowMetricsWindow();
ImGui::ShowDebugLogWindow();

ImGui::Begin("App debug panel", &m_show_debug_panel);
ImGui::Text("User config path: %s", m_user_config_path.c_str());
ImGui::Text("Global font scaling %f", io.FontGlobalScale);
ImGui::End();
Expand Down
8 changes: 4 additions & 4 deletions vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ FetchContent_Declare(
FetchContent_Declare(
fmt
GIT_REPOSITORY "https://github.com/fmtlib/fmt.git"
GIT_TAG 10.2.1
GIT_TAG 11.0.2
)

FetchContent_Declare(
Expand All @@ -23,19 +23,19 @@ FetchContent_Declare(
FetchContent_Declare(
imgui
GIT_REPOSITORY "https://github.com/ocornut/imgui.git"
GIT_TAG 085781f5ca5372d5fc804d7e44b5bf27a8994af7 # Branch: docking, date: 19.03.2024, 06:52 GMT+1
GIT_TAG 68aa9a86ec933510073932980a0940742ecc833c # Branch: docking, date: 10.09.2024, 04:29 GMT+2
)

FetchContent_Declare(
SDL3
GIT_REPOSITORY "https://github.com/libsdl-org/SDL.git"
GIT_TAG prerelease-3.1.1
GIT_TAG 6e2f2428baca59280cb9bab47f7dac1159f94c46 # Branch: main, date: 12.09.2024, 08:31 GMT+2
)

FetchContent_Declare(
spdlog
GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
GIT_TAG v1.13.0
GIT_TAG v1.14.1
)

# Settings
Expand Down
5 changes: 1 addition & 4 deletions vendor/imgui-setup/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
FetchContent_GetProperties(imgui)
if (NOT imgui_POPULATED)
FetchContent_Populate(imgui)
endif ()
FetchContent_MakeAvailable(imgui)

add_library(imgui
${imgui_SOURCE_DIR}/imgui.cpp ${imgui_SOURCE_DIR}/imgui.h
Expand Down