Skip to content

Commit 967879b

Browse files
committed
Upgrade project for CMake 4
This also includes updates to the dependencies, docs, and font handling. Will also enable using this as Sublime Text project.
1 parent c846919 commit 967879b

File tree

11 files changed

+179
-30
lines changed

11 files changed

+179
-30
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Release
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches: ["main"]
66
pull_request:
7-
branches: [ "main" ]
7+
branches: ["main"]
88

99
env:
1010
BUILD_TYPE: Release
@@ -13,15 +13,15 @@ jobs:
1313
build:
1414
strategy:
1515
matrix:
16-
os: [ macos-14, ubuntu-latest, windows-latest ]
16+
os: [macos-14, ubuntu-latest, windows-latest]
1717

1818
runs-on: ${{ matrix.os }}
1919

2020
steps:
2121
- uses: actions/checkout@v4
2222

2323
- name: Configure CMake
24-
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
24+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DWARNINGS_AS_ERRORS=FALSE
2525

2626
- name: Build
2727
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Application build output
22
build/
33
distribution/
4+
.cache/
45

56
# Created by CPack when executing tests.
67
Testing/
@@ -14,3 +15,4 @@ profile.json
1415

1516
# User defined CMake preset file.
1617
CMakeUserPresets.json
18+
*.sublime-workspace

CMakePresets.json

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"generator": "Ninja",
1717
"binaryDir": "build/release",
1818
"cacheVariables": {
19-
"CMAKE_BUILD_TYPE": "Release"
19+
"CMAKE_BUILD_TYPE": "Release",
20+
"WARNINGS_AS_ERRORS": "FALSE"
2021
}
2122
},
2223
{
@@ -41,7 +42,8 @@
4142
"binaryDir": "build/xcode-release",
4243
"cacheVariables": {
4344
"CMAKE_BUILD_TYPE": "Release",
44-
"CMAKE_OSX_ARCHITECTURES": "x86_64;arm64"
45+
"CMAKE_OSX_ARCHITECTURES": "x86_64;arm64",
46+
"WARNINGS_AS_ERRORS": "FALSE"
4547
},
4648
"condition": {
4749
"type": "equals",
@@ -62,9 +64,7 @@
6264
"displayName": "Build Release",
6365
"configurePreset": "release",
6466
"configuration": "Release",
65-
"targets": [
66-
"App"
67-
]
67+
"targets": ["App"]
6868
},
6969
{
7070
"name": "xcode-debug",
@@ -82,9 +82,7 @@
8282
"displayName": "Build Release (Xcode)",
8383
"configurePreset": "xcode-release",
8484
"configuration": "Release",
85-
"targets": [
86-
"App"
87-
],
85+
"targets": ["App"],
8886
"condition": {
8987
"type": "equals",
9088
"lhs": "${hostSystemName}",
@@ -97,17 +95,13 @@
9795
"name": "release",
9896
"displayName": "Distribute Release",
9997
"configurePreset": "release",
100-
"configurations": [
101-
"Release"
102-
]
98+
"configurations": ["Release"]
10399
},
104100
{
105101
"name": "xcode-release",
106102
"displayName": "Distribute Release (Xcode)",
107103
"configurePreset": "xcode-release",
108-
"configurations": [
109-
"Release"
110-
],
104+
"configurations": ["Release"],
111105
"condition": {
112106
"type": "equals",
113107
"lhs": "${hostSystemName}",

cmake/CompilerWarnings.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
function(set_project_warnings project_name)
44
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE)
5-
message(STATUS "Treat compiler warnings as errors")
65

76
set(MSVC_WARNINGS
87
/W4 # Baseline reasonable warnings
@@ -59,6 +58,7 @@ function(set_project_warnings project_name)
5958
)
6059

6160
if (WARNINGS_AS_ERRORS)
61+
message(STATUS "Treat compiler warnings as errors")
6262
set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
6363
set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
6464
endif ()

docs/Profiling.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ int Application::run() {
6868

6969
## Show results
7070

71-
The resulting JSON file uses
72-
the [Trace Event Format](https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview). Any
71+
The resulting JSON file (`profile.json`) uses the [Trace Event Format](https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview). Any
7372
tool that can read this format can visualize the profiler data. For example the web
7473
tool [Perfetto](https://ui.perfetto.dev/) or Chromes built in [chrome://tracing](chrome://tracing). Just drag&drop the
7574
generated profiler JSON file onto the tool to load it.
@@ -78,6 +77,6 @@ This is roughly how this looks like on Chrome.
7877

7978
![chrome-trace.png](assets/chrome-trace.png)
8079

81-
***
80+
---
8281

8382
Next up: [Logging](Logging.md)

src/core/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ include(${PROJECT_SOURCE_DIR}/cmake/StaticAnalyzers.cmake)
55
add_library(${NAME} STATIC
66
Core/Log.cpp Core/Log.hpp Core/Debug/Instrumentor.hpp
77
Core/Application.cpp Core/Application.hpp Core/Window.cpp Core/Window.hpp
8-
Core/Resources.hpp Core/DPIHandler.hpp)
8+
Core/Resources.hpp Core/Resources.cpp
9+
Core/DPIHandler.hpp)
910

1011
# Define set of OS specific files to include
1112
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")

src/core/Core/Application.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@ ExitStatus App::Application::run() {
7575
const float font_size{18.0F * font_scaling_factor};
7676
const std::string font_path{Resources::font_path("Manrope.ttf").generic_string()};
7777

78-
io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size);
79-
io.FontDefault = io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size);
78+
if (Resources::exists(font_path)) {
79+
io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size);
80+
io.FontDefault = io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size);
81+
} else {
82+
APP_WARN("Could not find font file under: {}", font_path.c_str());
83+
}
84+
8085
DPIHandler::set_global_font_scaling(&io);
8186

8287
// Setup Platform/Renderer backends

src/core/Core/Resources.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "Core/Resources.hpp"
2+
3+
#include <sys/stat.h>
4+
5+
#include <filesystem>
6+
7+
#include "Core/Debug/Instrumentor.hpp"
8+
9+
namespace App {
10+
11+
bool Resources::exists(const std::filesystem::path& pathname) {
12+
APP_PROFILE_FUNCTION();
13+
14+
struct stat buffer;
15+
return (stat(pathname.generic_string().c_str(), &buffer) == 0);
16+
}
17+
18+
} // namespace App

src/core/Core/Resources.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Resources {
99
public:
1010
[[nodiscard]] static std::filesystem::path resource_path(const std::filesystem::path& file_path);
1111
[[nodiscard]] static std::filesystem::path font_path(const std::string_view& font_file);
12+
[[nodiscard]] static bool exists(const std::filesystem::path& pathname);
1213
};
1314

1415
} // namespace App

template.sublime-project

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
{
2+
"folders":
3+
[
4+
{
5+
"path": ".",
6+
}
7+
],
8+
"settings": {
9+
"cmake": {
10+
"build_folder": "$folder/build",
11+
"command_line_overrides": {
12+
"CMAKE_POLICY_VERSION_MINIMUM": "3.5",
13+
},
14+
},
15+
"LSP": {
16+
"clangd": {
17+
"initializationOptions": {
18+
"clangd.clang-tidy": true,
19+
},
20+
},
21+
},
22+
},
23+
"build_systems":
24+
[
25+
{
26+
"config": "Debug",
27+
"env":
28+
{
29+
},
30+
"generator": "Unix Makefiles",
31+
"name": "Debug",
32+
"target": "cmake_build",
33+
"variants":
34+
[
35+
{
36+
"build_target": "App",
37+
"name": "App"
38+
},
39+
{
40+
"artifact": "src/app/App.app/Contents/MacOS/App",
41+
"build_target": "App",
42+
"name": "Run: App",
43+
"target": "cmake_run"
44+
},
45+
{
46+
"artifact": "src/app/App.app/Contents/MacOS/App",
47+
"build_target": "App",
48+
"debug": true,
49+
"name": "Run under LLDB: App",
50+
"target": "cmake_run"
51+
},
52+
{
53+
"build_target": "Core",
54+
"name": "Core"
55+
},
56+
{
57+
"build_target": "ResourcesTest",
58+
"name": "ResourcesTest"
59+
},
60+
{
61+
"artifact": "src/core/Tests/ResourcesTest",
62+
"build_target": "ResourcesTest",
63+
"name": "Run: ResourcesTest",
64+
"target": "cmake_run"
65+
},
66+
{
67+
"artifact": "src/core/Tests/ResourcesTest",
68+
"build_target": "ResourcesTest",
69+
"debug": true,
70+
"name": "Run under LLDB: ResourcesTest",
71+
"target": "cmake_run"
72+
},
73+
{
74+
"build_target": "SDL2",
75+
"name": "SDL2"
76+
},
77+
{
78+
"build_target": "SDL2-static",
79+
"name": "SDL2-static"
80+
},
81+
{
82+
"build_target": "SDL2_test",
83+
"name": "SDL2_test"
84+
},
85+
{
86+
"build_target": "Settings",
87+
"name": "Settings"
88+
},
89+
{
90+
"build_target": "TestRunner",
91+
"name": "TestRunner"
92+
},
93+
{
94+
"build_target": "doctest_with_main",
95+
"name": "doctest_with_main"
96+
},
97+
{
98+
"build_target": "fmt",
99+
"name": "fmt"
100+
},
101+
{
102+
"build_target": "glad",
103+
"name": "glad"
104+
},
105+
{
106+
"build_target": "imgui",
107+
"name": "imgui"
108+
},
109+
{
110+
"build_target": "sdl_headers_copy",
111+
"name": "sdl_headers_copy"
112+
},
113+
{
114+
"build_target": "spdlog",
115+
"name": "spdlog"
116+
},
117+
{
118+
"build_target": "uninstall",
119+
"name": "uninstall"
120+
},
121+
{
122+
"name": "ctest",
123+
"target": "ctest_run"
124+
}
125+
],
126+
"working_dir": "$folder/build"
127+
}
128+
],
129+
}

0 commit comments

Comments
 (0)