]> git.bts.cx Git - benzene.git/blob - CMakeLists.txt
Sprites
[benzene.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.12)
2
3 if(PLAYDATE_DEVICE)
4 set(PROJECT_LANGUAGES C ASM CXX)
5 elseif(APPLE)
6 set(PROJECT_LANGUAGES C OBJC CXX)
7 else()
8 # Some error needs to go here, and more platforms...
9 endif()
10
11 set(CMAKE_CXX_STANDARD 11)
12
13 project(benzene ${PROJECT_LANGUAGES})
14
15 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/sun/runtime EXCLUDE_FROM_ALL)
16
17 if(PLAYDATE_DEVICE)
18 # Playdate is software renderer
19 elseif(APPLE)
20 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/sdl EXCLUDE_FROM_ALL)
21 else()
22 # Some error needs to go here, and more platforms...
23 endif()
24
25 set(BENZENE_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
26 set(BENZENE_SOURCES
27 ${BENZENE_SRC_DIR}/bz/impl.c
28
29 ${BENZENE_SRC_DIR}/bz/audio/ogg.h
30 ${BENZENE_SRC_DIR}/bz/audio/ogg.c
31 ${BENZENE_SRC_DIR}/bz/audio/playback.h
32 ${BENZENE_SRC_DIR}/bz/audio/playback_internal.h
33 ${BENZENE_SRC_DIR}/bz/audio/playback.c
34 ${BENZENE_SRC_DIR}/bz/audio/speech.h
35 ${BENZENE_SRC_DIR}/bz/audio/speech.cpp
36 ${BENZENE_SRC_DIR}/bz/audio/wav.h
37 ${BENZENE_SRC_DIR}/bz/audio/wav.c
38
39 ${BENZENE_SRC_DIR}/bz/collision/collision.h
40 ${BENZENE_SRC_DIR}/bz/collision/collision.c
41 ${BENZENE_SRC_DIR}/bz/collision/particle_collision.h
42 ${BENZENE_SRC_DIR}/bz/collision/particle_collision.c
43
44 ${BENZENE_SRC_DIR}/bz/debug/assert.h
45 ${BENZENE_SRC_DIR}/bz/debug/assert.c
46 ${BENZENE_SRC_DIR}/bz/debug/log.h
47 ${BENZENE_SRC_DIR}/bz/debug/log.c
48 ${BENZENE_SRC_DIR}/bz/debug/perfgraph.h
49 ${BENZENE_SRC_DIR}/bz/debug/perfgraph.c
50
51 ${BENZENE_SRC_DIR}/bz/fx/agent_simulation.h
52 ${BENZENE_SRC_DIR}/bz/fx/agent_simulation_internal.h
53 ${BENZENE_SRC_DIR}/bz/fx/agent_simulation.c
54 ${BENZENE_SRC_DIR}/bz/fx/particle_simulation.h
55 ${BENZENE_SRC_DIR}/bz/fx/particle_simulation_internal.h
56 ${BENZENE_SRC_DIR}/bz/fx/particle_simulation.c
57 ${BENZENE_SRC_DIR}/bz/fx/particle_system.h
58 ${BENZENE_SRC_DIR}/bz/fx/particle_system_internal.h
59 ${BENZENE_SRC_DIR}/bz/fx/particle_system.c
60
61 ${BENZENE_SRC_DIR}/bz/game/actor.h
62 ${BENZENE_SRC_DIR}/bz/game/actor_internal.h
63 ${BENZENE_SRC_DIR}/bz/game/actor.c
64 ${BENZENE_SRC_DIR}/bz/game/scene.h
65 ${BENZENE_SRC_DIR}/bz/game/scene_internal.h
66 ${BENZENE_SRC_DIR}/bz/game/scene.c
67 ${BENZENE_SRC_DIR}/bz/game/scene_identifiers.cpp
68 ${BENZENE_SRC_DIR}/bz/game/tilemap.h
69 ${BENZENE_SRC_DIR}/bz/game/tilemap_internal.h
70 ${BENZENE_SRC_DIR}/bz/game/tilemap.c
71
72 ${BENZENE_SRC_DIR}/bz/gfx/aseprite.h
73 ${BENZENE_SRC_DIR}/bz/gfx/aseprite_internal.h
74 ${BENZENE_SRC_DIR}/bz/gfx/aseprite.c
75 ${BENZENE_SRC_DIR}/bz/gfx/draw_queue.h
76 ${BENZENE_SRC_DIR}/bz/gfx/draw_queue.c
77 ${BENZENE_SRC_DIR}/bz/gfx/drawing.h
78 ${BENZENE_SRC_DIR}/bz/gfx/drawing.c
79 ${BENZENE_SRC_DIR}/bz/gfx/font.h
80 ${BENZENE_SRC_DIR}/bz/gfx/font_internal.h
81 ${BENZENE_SRC_DIR}/bz/gfx/font.c
82 ${BENZENE_SRC_DIR}/bz/gfx/gfx.h
83 ${BENZENE_SRC_DIR}/bz/gfx/gfx_internal.h
84 ${BENZENE_SRC_DIR}/bz/gfx/gfx.c
85 ${BENZENE_SRC_DIR}/bz/gfx/particle_drawing.h
86 ${BENZENE_SRC_DIR}/bz/gfx/particle_drawing.c
87 ${BENZENE_SRC_DIR}/bz/gfx/tilemap.h
88 ${BENZENE_SRC_DIR}/bz/gfx/tilemap_internal.h
89 ${BENZENE_SRC_DIR}/bz/gfx/tilemap.c
90
91 ${BENZENE_SRC_DIR}/bz/input/input.h
92 ${BENZENE_SRC_DIR}/bz/input/input_internal.h
93 ${BENZENE_SRC_DIR}/bz/input/input.c
94 ${BENZENE_SRC_DIR}/bz/input/input_id.h
95 ${BENZENE_SRC_DIR}/bz/input/input_id_internal.h
96 ${BENZENE_SRC_DIR}/bz/input/platform.h
97
98 ${BENZENE_SRC_DIR}/bz/math/math.h
99 ${BENZENE_SRC_DIR}/bz/math/math.c
100 ${BENZENE_SRC_DIR}/bz/math/matrix.h
101 ${BENZENE_SRC_DIR}/bz/math/matrix.c
102 ${BENZENE_SRC_DIR}/bz/math/random.h
103 ${BENZENE_SRC_DIR}/bz/math/random.c
104 ${BENZENE_SRC_DIR}/bz/math/vector.h
105 ${BENZENE_SRC_DIR}/bz/math/vector.c
106
107 ${BENZENE_SRC_DIR}/bz/memory/allocator.h
108 ${BENZENE_SRC_DIR}/bz/memory/allocator.c
109 ${BENZENE_SRC_DIR}/bz/memory/arena.h
110 ${BENZENE_SRC_DIR}/bz/memory/arena_internal.h
111 ${BENZENE_SRC_DIR}/bz/memory/arena.c
112
113 ${BENZENE_SRC_DIR}/bz/renderer/palette.h
114 ${BENZENE_SRC_DIR}/bz/renderer/palette_internal.h
115 ${BENZENE_SRC_DIR}/bz/renderer/palette.c
116 ${BENZENE_SRC_DIR}/bz/renderer/render_pass.h
117 ${BENZENE_SRC_DIR}/bz/renderer/render_pass_internal.h
118 ${BENZENE_SRC_DIR}/bz/renderer/renderer.h
119 ${BENZENE_SRC_DIR}/bz/renderer/renderer_internal.h
120 ${BENZENE_SRC_DIR}/bz/renderer/renderer.c
121
122 ${BENZENE_SRC_DIR}/bz/resources/resource.h
123 ${BENZENE_SRC_DIR}/bz/resources/resource.c
124
125 ${BENZENE_SRC_DIR}/bz/scripting/bindings.h
126 ${BENZENE_SRC_DIR}/bz/scripting/bindings_internal.h
127 ${BENZENE_SRC_DIR}/bz/scripting/bindings.cpp
128 ${BENZENE_SRC_DIR}/bz/scripting/environment.h
129 ${BENZENE_SRC_DIR}/bz/scripting/environment_internal.h
130 ${BENZENE_SRC_DIR}/bz/scripting/environment.c
131 ${BENZENE_SRC_DIR}/bz/scripting/script.h
132 ${BENZENE_SRC_DIR}/bz/scripting/script_internal.h
133 ${BENZENE_SRC_DIR}/bz/scripting/script.c
134 ${BENZENE_SRC_DIR}/bz/scripting/static_crc32.hpp
135
136 ${BENZENE_SRC_DIR}/bz/types/common.h
137 ${BENZENE_SRC_DIR}/bz/types/identifier.h
138 ${BENZENE_SRC_DIR}/bz/types/identifier.c
139 ${BENZENE_SRC_DIR}/bz/types/point.h
140 ${BENZENE_SRC_DIR}/bz/types/rect.h
141 ${BENZENE_SRC_DIR}/bz/types/size.h
142 ${BENZENE_SRC_DIR}/bz/types/user_parameter.h
143 )
144
145 if(PLAYDATE_DEVICE)
146 set(PLATFORM_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src_platform/playdate)
147 set(BENZENE_PLATFORM_SOURCES
148 ${PLATFORM_SRC_DIR}/bz/debug/assert.c
149 ${PLATFORM_SRC_DIR}/bz/debug/log.c
150 ${PLATFORM_SRC_DIR}/bz/debug/perfgraph.c
151
152 ${PLATFORM_SRC_DIR}/bz/gfx/gfx_platform.h
153 ${PLATFORM_SRC_DIR}/bz/gfx/gfx_platform.c
154
155 ${PLATFORM_SRC_DIR}/bz/input/input.c
156
157 ${PLATFORM_SRC_DIR}/bz/memory/arena.c
158
159 ${PLATFORM_SRC_DIR}/bz/renderer/renderer.c
160
161 ${PLATFORM_SRC_DIR}/bz/resources/resource.c
162
163 ${PLATFORM_SRC_DIR}/playdate/entrypoint.h
164 ${PLATFORM_SRC_DIR}/playdate/entrypoint.c
165 )
166 else()
167 set(PLATFORM_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src_platform/sdl)
168 set(BENZENE_PLATFORM_SOURCES
169 ${PLATFORM_SRC_DIR}/bz/audio/playback.c
170
171 ${PLATFORM_SRC_DIR}/bz/debug/assert.c
172 ${PLATFORM_SRC_DIR}/bz/debug/log.c
173 ${PLATFORM_SRC_DIR}/bz/debug/perfgraph.c
174
175 ${PLATFORM_SRC_DIR}/bz/gfx/gfx_platform.h
176 ${PLATFORM_SRC_DIR}/bz/gfx/gfx_platform.c
177
178 ${PLATFORM_SRC_DIR}/bz/input/input.c
179
180 ${PLATFORM_SRC_DIR}/bz/memory/arena.c
181
182 ${PLATFORM_SRC_DIR}/bz/renderer/renderer.c
183
184 ${PLATFORM_SRC_DIR}/bz/resources/file_system_internal.h
185 ${PLATFORM_SRC_DIR}/bz/resources/resource.c
186
187 ${PLATFORM_SRC_DIR}/main.c
188 )
189 endif()
190
191 if(NOT PLAYDATE_DEVICE)
192 set(PHYSFS_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/physfs/)
193 set(PHYSFS_SOURCES
194 ${PHYSFS_SRC_DIR}/src/physfs.c
195 ${PHYSFS_SRC_DIR}/src/physfs.h
196 ${PHYSFS_SRC_DIR}/src/physfs_archiver_7z.c
197 ${PHYSFS_SRC_DIR}/src/physfs_archiver_dir.c
198 ${PHYSFS_SRC_DIR}/src/physfs_archiver_grp.c
199 ${PHYSFS_SRC_DIR}/src/physfs_archiver_hog.c
200 ${PHYSFS_SRC_DIR}/src/physfs_archiver_iso9660.c
201 ${PHYSFS_SRC_DIR}/src/physfs_archiver_mvl.c
202 ${PHYSFS_SRC_DIR}/src/physfs_archiver_qpak.c
203 ${PHYSFS_SRC_DIR}/src/physfs_archiver_slb.c
204 ${PHYSFS_SRC_DIR}/src/physfs_archiver_unpacked.c
205 ${PHYSFS_SRC_DIR}/src/physfs_archiver_vdf.c
206 ${PHYSFS_SRC_DIR}/src/physfs_archiver_wad.c
207 ${PHYSFS_SRC_DIR}/src/physfs_archiver_zip.c
208 ${PHYSFS_SRC_DIR}/src/physfs_byteorder.c
209 ${PHYSFS_SRC_DIR}/src/physfs_casefolding.h
210 ${PHYSFS_SRC_DIR}/src/physfs_internal.h
211 ${PHYSFS_SRC_DIR}/src/physfs_lzmasdk.h
212 ${PHYSFS_SRC_DIR}/src/physfs_miniz.h
213 ${PHYSFS_SRC_DIR}/src/physfs_platform_android.c
214 ${PHYSFS_SRC_DIR}/src/physfs_platform_os2.c
215 ${PHYSFS_SRC_DIR}/src/physfs_platform_posix.c
216 ${PHYSFS_SRC_DIR}/src/physfs_platform_qnx.c
217 ${PHYSFS_SRC_DIR}/src/physfs_platform_unix.c
218 ${PHYSFS_SRC_DIR}/src/physfs_platform_windows.c
219 ${PHYSFS_SRC_DIR}/src/physfs_platforms.h
220 ${PHYSFS_SRC_DIR}/src/physfs_unicode.c
221 )
222 if(APPLE)
223 list(APPEND PHYSFS_SOURCES ${PHYSFS_SRC_DIR}/src/physfs_platform_apple.m)
224 endif()
225 endif()
226
227 set(PARSON_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/parson/)
228 set(PARSON_SOURCES
229 ${PARSON_SRC_DIR}/parson.h
230 ${PARSON_SRC_DIR}/parson.c
231 )
232
233 set(PCG_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/pcg-c-basic/)
234 set(PCG_SOURCES
235 ${PCG_SRC_DIR}/pcg_basic.h
236 ${PCG_SRC_DIR}/pcg_basic.c
237 )
238
239 set(CRC_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/snippets_org_crc/)
240 set(CRC_SOURCES
241 ${CRC_SRC_DIR}/crc.h
242 ${CRC_SRC_DIR}/crc.c
243 )
244
245 set(SOLOUD_SPEECH_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/soloud_speech/)
246 set(SOLOUD_SPEECH_SOURCES
247 ${SOLOUD_SPEECH_SRC_DIR}/darray.h
248 ${SOLOUD_SPEECH_SRC_DIR}/darray.cpp
249 ${SOLOUD_SPEECH_SRC_DIR}/klatt.h
250 ${SOLOUD_SPEECH_SRC_DIR}/klatt.cpp
251 ${SOLOUD_SPEECH_SRC_DIR}/resonator.h
252 ${SOLOUD_SPEECH_SRC_DIR}/resonator.cpp
253 ${SOLOUD_SPEECH_SRC_DIR}/tts.h
254 ${SOLOUD_SPEECH_SRC_DIR}/tts.cpp
255 )
256
257
258 add_library(benzene STATIC ${BENZENE_SOURCES})
259 set_property(TARGET benzene PROPERTY C_STANDARD 11)
260
261 if(PLAYDATE_DEVICE)
262 # NB: This is copied out of the Playdate SDK. Check for correctness on update.
263
264 set(ENVSDK $ENV{PLAYDATE_SDK_PATH})
265
266 if (NOT ${ENVSDK} STREQUAL "")
267 # Convert path from Windows
268 file(TO_CMAKE_PATH ${ENVSDK} SDK)
269 else()
270 execute_process(
271 COMMAND bash -c "egrep '^\\s*SDKRoot' $HOME/.Playdate/config"
272 COMMAND head -n 1
273 COMMAND cut -c9-
274 OUTPUT_VARIABLE SDK
275 OUTPUT_STRIP_TRAILING_WHITESPACE
276 )
277 endif()
278
279 if (NOT EXISTS ${SDK})
280 message(FATAL_ERROR "SDK Path not found; set ENV value PLAYDATE_SDK_PATH")
281 return()
282 endif()
283
284 ##
285
286 include_directories("${SDK}/C_API")
287 set(PDC "${SDK}/bin/pdc" -sdkpath "${SDK}")
288
289 add_compile_definitions(TARGET_EXTENSION=1)
290
291 set(HEAP_SIZE 8388208)
292 set(STACK_SIZE 61800)
293 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -x assembler-with-cpp -D__HEAP_SIZE=${HEAP_SIZE} -D__STACK_SIZE=${STACK_SIZE}")
294
295 set(MCFLAGS -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -D__FPU_USED=1)
296
297 target_compile_definitions(benzene PUBLIC TARGET_PLAYDATE=1)
298 target_compile_options(benzene PUBLIC -Wall -Wno-unknown-pragmas -Wdouble-promotion)
299 # target_compile_options(benzene PUBLIC $<$<CONFIG:DEBUG>:-O2>)
300 # target_compile_options(benzene PUBLIC $<$<CONFIG:RELEASE>:-O2>)
301 target_compile_options(benzene PUBLIC -O2)
302
303 target_compile_options(benzene PUBLIC ${MCFLAGS})
304 target_compile_options(benzene PUBLIC -falign-functions=16 -fomit-frame-pointer)
305 target_compile_options(benzene PUBLIC -gdwarf-2)
306 target_compile_options(benzene PUBLIC -fverbose-asm)
307 target_compile_options(benzene PUBLIC -ffunction-sections -fdata-sections)
308 target_compile_options(benzene PUBLIC -mword-relocations -fno-common)
309
310 #target_compile_options(benzene PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>)
311
312 target_link_options(benzene PUBLIC ${MCFLAGS})
313
314 target_link_options(benzene PUBLIC -specs=nosys.specs)
315
316 # target_compile_options(benzene PUBLIC "-funroll-loops")
317
318 target_compile_options(benzene PUBLIC "-nostdlib")
319 # target_compile_options(benzene PUBLIC "-nostdinc")
320 target_compile_options(benzene PUBLIC "-nodefaultlibs")
321
322 elseif(APPLE)
323
324 endif()
325
326 if(PLAYDATE_DEVICE)
327 target_sources(benzene PRIVATE ${BENZENE_PLATFORM_SOURCES} ${PARSON_SOURCES} ${PCG_SOURCES} ${CRC_SOURCES})
328 else()
329 target_sources(benzene PRIVATE ${BENZENE_PLATFORM_SOURCES} ${PHYSFS_SOURCES} ${PARSON_SOURCES} ${PCG_SOURCES} ${CRC_SOURCES} ${SOLOUD_SPEECH_SOURCES})
330 endif()
331
332 target_precompile_headers(benzene PRIVATE ${BENZENE_SRC_DIR}/bz/common.pch)
333
334 target_link_libraries(benzene PRIVATE sun)
335 target_include_directories(benzene PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/sun/runtime/src)
336
337 if(PLAYDATE_DEVICE)
338
339 else()
340 if(TARGET SDL2::SDL2main)
341 target_link_libraries(benzene PRIVATE SDL2::SDL2main)
342 endif()
343
344 # FIXME, Ideally we want to use the DLLs so that Steam etc. can patch
345 #target_link_libraries(benzene PRIVATE SDL2::SDL2)
346 target_link_libraries(benzene PRIVATE SDL2::SDL2-static)
347 endif()
348
349 if(APPLE)
350 target_link_libraries(benzene PRIVATE "-framework Foundation")
351 target_link_libraries(benzene PRIVATE "-framework IOKit")
352 endif()
353
354 target_include_directories(benzene PRIVATE ${GAME_SRC_DIR})
355 target_include_directories(benzene PRIVATE ${BENZENE_SRC_DIR})
356 target_include_directories(benzene PRIVATE ${PLATFORM_SRC_DIR})
357 target_include_directories(benzene PRIVATE ${PARSON_SRC_DIR})
358 target_include_directories(benzene PRIVATE ${PCG_SRC_DIR})
359 target_include_directories(benzene PRIVATE ${CRC_SRC_DIR})
360 target_include_directories(benzene PRIVATE ${SOLOUD_SPEECH_SRC_DIR})
361 target_include_directories(benzene PRIVATE ${PHYSFS_SRC_DIR}/src)
362 target_include_directories(benzene PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/stb)