-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
185 lines (167 loc) · 7.16 KB
/
Copy pathCMakeLists.txt
File metadata and controls
185 lines (167 loc) · 7.16 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#
# CMake build for Qyst release/CI packaging.
#
# The plain Makefile remains the simple way to build locally against system
# libraries. This build instead:
# - statically links SDL3 (built from source, pinned below)
# - dynamically links sfsexp (LGPL: must NOT be statically linked),
# built as a shared library from its pinned source release
# - produces a relocatable layout: executable + data/ side by side
# (or a Qyst.app bundle on macOS with -DQYST_BUNDLE=ON)
#
# Options:
# -DQYST_VERSION=v0.2 version string (from the git tag in CI)
# -DQYST_BUNDLE=ON macOS: build a Qyst.app bundle
# -DQYST_ICON_ICO=path Windows: .ico to embed in the executable
# -DQYST_ICON_ICNS=path macOS bundle: .icns for the app icon
#
cmake_minimum_required(VERSION 3.24)
set(QYST_VERSION "0.0.0-dev" CACHE STRING "Qyst version string")
option(QYST_BUNDLE "Build a macOS .app bundle" OFF)
set(QYST_ICON_ICO "" CACHE FILEPATH "Windows .ico file to embed")
set(QYST_ICON_ICNS "" CACHE FILEPATH "macOS .icns file for the bundle")
# Numeric x.y.z for bundle/rc metadata ("v0.2" -> "0.2").
string(REGEX MATCH "[0-9]+(\\.[0-9]+)*" QYST_VERSION_NUMERIC "${QYST_VERSION}")
if(NOT QYST_VERSION_NUMERIC)
set(QYST_VERSION_NUMERIC "0.0.0")
endif()
project(Qyst VERSION "${QYST_VERSION_NUMERIC}" LANGUAGES C)
include(FetchContent)
#-----------------------------------------------------------------------------
# SDL3 -- statically linked, pinned release.
#-----------------------------------------------------------------------------
set(SDL_SHARED OFF CACHE BOOL "" FORCE)
set(SDL_STATIC ON CACHE BOOL "" FORCE)
set(SDL_TEST_LIBRARY OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
SDL3
URL https://github.com/libsdl-org/SDL/releases/download/release-3.4.14/SDL3-3.4.14.tar.gz
)
FetchContent_MakeAvailable(SDL3)
#-----------------------------------------------------------------------------
# sfsexp -- shared library (LGPL), pinned release v1.4.1.
# Upstream only ships autotools, so the library target is defined here.
#-----------------------------------------------------------------------------
FetchContent_Declare(
sfsexp
URL https://github.com/mjsottile/sfsexp/archive/b7d3bea0effb6663a6d69897bc1c4ea3cc08b682.tar.gz
)
FetchContent_MakeAvailable(sfsexp)
add_library(sexp SHARED
${sfsexp_SOURCE_DIR}/src/cstring.c
${sfsexp_SOURCE_DIR}/src/event_temp.c
${sfsexp_SOURCE_DIR}/src/faststack.c
${sfsexp_SOURCE_DIR}/src/io.c
${sfsexp_SOURCE_DIR}/src/parser.c
${sfsexp_SOURCE_DIR}/src/sexp.c
${sfsexp_SOURCE_DIR}/src/sexp_memory.c
${sfsexp_SOURCE_DIR}/src/sexp_ops.c
${sfsexp_SOURCE_DIR}/src/sexp_vis.c
)
target_include_directories(sexp PUBLIC ${sfsexp_SOURCE_DIR}/src)
set_target_properties(sexp PROPERTIES
C_STANDARD 99
VERSION 1.0.0
SOVERSION 1
WINDOWS_EXPORT_ALL_SYMBOLS ON # upstream has no dllexport annotations
)
#-----------------------------------------------------------------------------
# Qyst executable.
#-----------------------------------------------------------------------------
add_executable(qyst src/qyst.c)
target_include_directories(qyst PRIVATE
src
external/pl_mpeg
external/log/src
external/scalable-font2
)
target_link_libraries(qyst PRIVATE SDL3::SDL3-static sexp)
set_target_properties(qyst PROPERTIES C_STANDARD 99)
# Warning flags mirrored from the Makefile. The full set is GCC-only;
# Clang/AppleClang gets the subset it understands.
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(qyst PRIVATE
-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wformat=2
-Wformat-overflow=2 -Wformat-truncation=2 -Wformat-security
-Wnull-dereference -Wstack-protector -Wtrampolines -Walloca -Wvla
-Warray-bounds=2 -Wimplicit-fallthrough=3 -Wshift-overflow=2 -Wcast-qual
-Wstringop-overflow=4 -Warith-conversion -Wlogical-op -Wduplicated-cond
-Wduplicated-branches -Wstrict-prototypes -Wmissing-prototypes -Wundef
-Wstrict-overflow=4 -Wswitch-default -Wswitch-enum -Wcast-align=strict
)
target_compile_options(qyst PRIVATE $<$<CONFIG:Debug>:-O0 -ggdb3>)
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
target_compile_options(qyst PRIVATE
-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wformat=2
-Wformat-security -Wnull-dereference -Walloca -Wvla -Warray-bounds
-Wimplicit-fallthrough -Wshift-overflow -Wcast-qual -Wstrict-prototypes
-Wmissing-prototypes -Wundef -Wswitch-default -Wswitch-enum -Wcast-align
)
target_compile_options(qyst PRIVATE $<$<CONFIG:Debug>:-O0 -g3>)
endif()
if(UNIX)
target_link_libraries(qyst PRIVATE m)
endif()
if(MINGW)
# No compiler runtime DLLs in the package.
target_link_options(qyst PRIVATE -static-libgcc)
target_link_options(sexp PRIVATE -static-libgcc)
endif()
if(WIN32)
set_target_properties(qyst PROPERTIES WIN32_EXECUTABLE TRUE)
if(QYST_ICON_ICO)
configure_file(packaging/qyst.rc.in ${CMAKE_CURRENT_BINARY_DIR}/qyst.rc @ONLY)
target_sources(qyst PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/qyst.rc)
endif()
endif()
#-----------------------------------------------------------------------------
# Layout / packaging.
# The game loads assets relative to SDL_GetBasePath() (see src/qyst.c), so
# data/ must sit next to the executable -- or in Contents/Resources inside
# the macOS bundle, where SDL_GetBasePath() points.
#-----------------------------------------------------------------------------
if(APPLE AND QYST_BUNDLE)
set_target_properties(qyst PROPERTIES
OUTPUT_NAME "Qyst"
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_BUNDLE_NAME "Qyst"
MACOSX_BUNDLE_GUI_IDENTIFIER "io.github.malespiaut.qyst"
MACOSX_BUNDLE_BUNDLE_VERSION "${QYST_VERSION_NUMERIC}"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${QYST_VERSION_NUMERIC}"
MACOSX_BUNDLE_COPYRIGHT "© 2026 Marc-Alexandre Espiaut"
INSTALL_RPATH "@executable_path/../Frameworks"
BUILD_WITH_INSTALL_RPATH TRUE
)
if(QYST_ICON_ICNS)
set_target_properties(qyst PROPERTIES MACOSX_BUNDLE_ICON_FILE "qyst.icns")
target_sources(qyst PRIVATE ${QYST_ICON_ICNS})
set_source_files_properties(${QYST_ICON_ICNS} PROPERTIES
MACOSX_PACKAGE_LOCATION Resources)
endif()
install(TARGETS qyst BUNDLE DESTINATION .)
install(DIRECTORY data DESTINATION Qyst.app/Contents/Resources)
# Install the real library under its soname: TARGET_SONAME_FILE is a
# symlink, and install(FILES) would copy it dangling.
install(FILES $<TARGET_FILE:sexp>
DESTINATION Qyst.app/Contents/Frameworks
RENAME $<TARGET_SONAME_FILE_NAME:sexp>)
set(QYST_DOC_DESTINATION Qyst.app/Contents/Resources)
else()
set_target_properties(qyst PROPERTIES INSTALL_RPATH "$ORIGIN")
install(TARGETS qyst RUNTIME DESTINATION .)
install(TARGETS sexp
RUNTIME DESTINATION . # .dll on Windows
LIBRARY DESTINATION . # .so/.dylib elsewhere
)
install(DIRECTORY data DESTINATION .)
set(QYST_DOC_DESTINATION .)
# Convenience for running straight from the build tree.
add_custom_command(TARGET qyst POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/data $<TARGET_FILE_DIR:qyst>/data
VERBATIM)
endif()
install(FILES LICENSE README.md DESTINATION ${QYST_DOC_DESTINATION})
install(FILES ${sfsexp_SOURCE_DIR}/COPYING
DESTINATION ${QYST_DOC_DESTINATION}
RENAME LICENSE.sfsexp.txt)