forked from ZQuestClassic/ZQuestClassic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
608 lines (507 loc) · 23.3 KB
/
CMakeLists.txt
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo CACHE STRING INTERNAL FORCE)
project (ZeldaClassic)
set(USE_PCH FALSE CACHE BOOL "Use precompiled headers")
set(UNITY_BUILD FALSE CACHE BOOL "Unity build")
set(WANT_SENTRY FALSE CACHE BOOL "Include Sentry for crash dump handling")
set(SENTRY_RELEASE_TAG "" CACHE STRING "Release tag for sentry")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# This allows outputs to be run where they are by putting their libaries in
# the same folder.
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# Hide various test-related targets created by GME cmake so they
# don't clutter up the Solution file. https://gitlab.kitware.com/cmake/cmake/-/issues/21730
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()
if(APPLE)
# Makes binaries look in their directory for shared libraries.
list(APPEND CMAKE_BUILD_RPATH "@loader_path")
endif()
function(enable_unity_build UB_SUFFIX SOURCE_VARIABLE_NAME)
set(files ${${SOURCE_VARIABLE_NAME}})
# Generate a unique filename for the unity build translation unit
set(unit_build_file ${CMAKE_CURRENT_BINARY_DIR}/UB_${UB_SUFFIX}.cpp)
# Exclude all translation units from compilation
set_source_files_properties(${files} PROPERTIES HEADER_FILE_ONLY true)
# Open the ub file
FILE(WRITE ${unit_build_file} "// Unity Build generated by CMake\n")
FILE(APPEND ${unit_build_file} "#include \"${CMAKE_SOURCE_DIR}/src/precompiled.h\"\n")
# Add include statement for each translation unit
foreach(source_file ${files} )
FILE( APPEND ${unit_build_file} "#include <${CMAKE_CURRENT_SOURCE_DIR}/${source_file}>\n")
endforeach(source_file)
# Complement list of translation units with the name of ub
set(${SOURCE_VARIABLE_NAME} ${${SOURCE_VARIABLE_NAME}} ${unit_build_file} PARENT_SCOPE)
endfunction(enable_unity_build)
#############################################################
# Allegro
#############################################################
# SDL WIP:
# cmake .. -DALLEGRO_SDL=on -DWANT_NATIVE_DIALOG=off
# https://github.com/liballeg/allegro5/issues/1335
if(NOT APPLE)
add_definitions(-DALLEGRO_NO_MAGIC_MAIN)
endif()
add_definitions(-DALLEGRO_KCM_AUDIO_SRC)
# Needed to build on Mac, otherwise get this error:
# aintern_bitmap.h:154:33: error: unknown type name 'ALLEGRO_BITMAP_WRAP'
add_definitions(-DALLEGRO_UNSTABLE)
option(SHARED "" ON)
include(FetchContent)
FetchContent_Declare(
allegro5
GIT_REPOSITORY https://github.com/liballeg/allegro5.git
GIT_TAG ff0bff067f5ba480d8ba50f360505d89c27fe0e5
)
FetchContent_GetProperties(allegro5)
if(NOT allegro5_POPULATED)
FetchContent_Populate(allegro5)
option(WANT_TESTS "" OFF)
option(WANT_EXAMPLES "" OFF)
option(WANT_DEMO "" OFF)
option(WANT_DOCS "" OFF)
add_subdirectory(${allegro5_SOURCE_DIR} ${allegro5_BINARY_DIR} EXCLUDE_FROM_ALL)
# Allegro 5 CMakeLists sets CMAKE_CONFIGURATION_TYPES in a way that doesn't work for us,
# so set it back to our value.
set(CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo CACHE STRING INTERNAL FORCE)
endif()
# These include files are typically copied into the correct places via allegro's install
# target, but we do it manually because we are compiling from source.
file(COPY ${allegro5_SOURCE_DIR}/addons/font/allegro5/allegro_font.h
DESTINATION ${allegro5_SOURCE_DIR}/include/allegro5
)
file(COPY ${allegro5_SOURCE_DIR}/addons/primitives/allegro5/allegro_primitives.h
DESTINATION ${allegro5_SOURCE_DIR}/include/allegro5
)
file(COPY ${allegro5_SOURCE_DIR}/addons/audio/allegro5/allegro_audio.h
DESTINATION ${allegro5_SOURCE_DIR}/include/allegro5
)
file(COPY ${allegro5_SOURCE_DIR}/addons/audio/allegro5/internal/aintern_audio.h
DESTINATION ${allegro5_SOURCE_DIR}/include/allegro5/internal
)
file(COPY ${allegro5_SOURCE_DIR}/addons/image/allegro5/allegro_image.h
DESTINATION ${allegro5_SOURCE_DIR}/include/allegro5
)
file(COPY ${allegro5_SOURCE_DIR}/addons/acodec/allegro5/allegro_acodec.h
DESTINATION ${allegro5_SOURCE_DIR}/include/allegro5
)
file(COPY ${allegro5_SOURCE_DIR}/addons/native_dialog/allegro5/allegro_native_dialog.h
DESTINATION ${allegro5_SOURCE_DIR}/include/allegro5
)
include_directories(${allegro5_SOURCE_DIR}/include)
include_directories(${allegro5_BINARY_DIR}/include)
add_subdirectory(allegro-legacy EXCLUDE_FROM_ALL)
add_library(allegro_with_legacy INTERFACE)
target_include_directories(allegro_with_legacy INTERFACE ${allegro5_SOURCE_DIR}/include ${allegro5_BINARY_DIR}/include)
target_include_directories(allegro_with_legacy INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/allegro-legacy/include ${CMAKE_CURRENT_BINARY_DIR}/allegro-legacy/include)
target_link_libraries(allegro_with_legacy INTERFACE allegro-legacy allegro_primitives allegro_image allegro_dialog allegro_main)
#############################################################
# Header and source file lists
#############################################################
include_directories(./include/zlib123)
include_directories(./src)
if(MSVC)
# include_directories(./src/msvcCompat)
endif()
set(ZCSOUNDSOURCES
src/zcmusic.cpp
src/zcmusicd.cpp
src/alleg_compat.cpp
)
set(ROMVIEW_MODULES
${CMAKE_SOURCE_DIR}/modules/romview/RomviewCore.txt
${CMAKE_SOURCE_DIR}/modules/romview/RomviewGUI.txt
)
set(ZELDA_MODULES
${CMAKE_SOURCE_DIR}/modules/zelda/ZeldaCore.txt
${CMAKE_SOURCE_DIR}/modules/zelda/ZeldaGUI.txt
${CMAKE_SOURCE_DIR}/modules/zelda/ZeldaSprite.txt
${CMAKE_SOURCE_DIR}/modules/zelda/ZeldaSubscreen.txt
)
set(ZQUEST_MODULES
${CMAKE_SOURCE_DIR}/modules/zquest/ZQuestCore.txt
${CMAKE_SOURCE_DIR}/modules/zquest/ZQuestGUI.txt
${CMAKE_SOURCE_DIR}/modules/zquest/ZQuestMisc.txt
)
set(ZSCRIPT_MODULES
${CMAKE_SOURCE_DIR}/modules/zscript/ParserCore.txt
${CMAKE_SOURCE_DIR}/modules/zscript/ParserSrc.txt
)
set(LAUNCHER_MODULES
${CMAKE_SOURCE_DIR}/modules/launcher/LauncherCore.txt
${CMAKE_SOURCE_DIR}/modules/launcher/LauncherGUI.txt
)
foreach(module ${ROMVIEW_MODULES} ${ZELDA_MODULES} ${ZQUEST_MODULES} ${LAUNCHER_MODULES} ${ZSCRIPT_MODULES})
include(${module})
set_source_files_properties(${module} PROPERTIES HEADER_FILE_ONLY true)
endforeach()
#############################################################
# Build the ZScript parser
#############################################################
find_package(BISON QUIET)
find_package(FLEX QUIET)
if(${BISON_FOUND} AND ${FLEX_FOUND})
if(MSVC)
set(FLEXFLAGS "--wincompat")
endif()
FLEX_TARGET(ZScriptLexer ${CMAKE_SOURCE_DIR}/src/parser/ffscript.lpp ${CMAKE_SOURCE_DIR}/src/parser/lex.yy.cpp COMPILE_FLAGS ${FLEXFLAGS})
BISON_TARGET(ZScriptParser ${CMAKE_SOURCE_DIR}/src/parser/ffscript.ypp ${CMAKE_SOURCE_DIR}/src/parser/y.tab.cpp COMPILE_FLAGS -v)
add_flex_bison_dependency(ZScriptLexer ZScriptParser)
else()
message(FATAL_ERROR "Flex and Bison not found. ZQuest cannot be compiled without these.")
endif()
#############################################################
# Global settings for the different platforms
#############################################################
# Windows
string(TOLOWER "${CMAKE_VS_PLATFORM_NAME}" vs_platform)
if(WIN32)
# Prevents definition of min and max macros, which conflict with std::min and std::max
add_definitions(-DNOMINMAX)
string(REGEX MATCH "MSVC" CMAKE_COMPILER_IS_MSVC "${CMAKE_C_COMPILER_ID}")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.20.2750.8)
message(FATAL_ERROR "MSVC version ${CMAKE_CXX_COMPILER_VERSION} is too old. Must use at least 2019 version 16.0.0")
endif()
endif()
if(MSVC)
# Many of these libraries are compiled for allegro 4, but they should still function thanks to allegro-legacy.
if("${vs_platform}" STREQUAL "win32")
set(IMAGELIBS "$<$<CONFIG:DEBUG>:$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/zlibd.lib>"
"$<$<CONFIG:RELEASE>:$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/zlib.lib>")
endif()
add_compile_options("$<$<CONFIG:DEBUG>:/MTd>")
add_compile_options("$<$<CONFIG:RELEASE>:/MT>")
# REQUIRED or else MSVC throws internal compiler error(!)
add_compile_options("$<$<CONFIG:RELEASE>:/fp:fast>")
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
if(MSVC_VERSION GREATER 1600)
# MSVC 2012, v11 or above
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:LIBCD /SUBSYSTEM:WINDOWS /LARGEADDRESSAWARE /OPT:NOICF")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:LIBCD /SUBSYSTEM:WINDOWS /LARGEADDRESSAWARE /OPT:NOICF")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG")
endif()
if(USE_PCH)
set(ZCPrecompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/zcprecompiled.pch")
set(ZQPrecompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/zqprecompiled.pch")
set_source_files_properties(src/precompiledzc.cpp PROPERTIES COMPILE_FLAGS "/Ycprecompiled.h /Fp\"${ZCPrecompiledBinary}\"" OBJECT_OUTPUTS "${ZCPrecompiledBinary}")
set_source_files_properties(src/precompiledzq.cpp PROPERTIES COMPILE_FLAGS "/Ycprecompiled.h /Fp\"${ZQPrecompiledBinary}\"" OBJECT_OUTPUTS "${ZQPrecompiledBinary}")
list(APPEND ZELDAEXTRASOURCES src/precompiledzc.cpp)
list(APPEND ZQUESTEXTRASOURCES src/precompiledzq.cpp)
endif()
# Linux
elseif(LINUX)
link_directories(/usr/lib/i386-linux-gnu)
link_directories(./libs/linux)
add_definitions(-DALLEGRO_LINUX) # Mistakenly used in the source.
set(IMAGELIBS ldpng png z)
set(SOUNDLIBS aldmb almp3 alogg dumb gme asound)
set(X11_LIBRARIES X11 Xext Xcursor Xxf86vm pthread Xpm dl)
add_compile_options("-m32")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32 -static-libgcc -export-dynamic")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32 -static-libgcc")
endif()
#############################################################
# Allegro Graphics Addons
#############################################################
add_library(algif5 STATIC
allegro-addons/algif5/src/algif.c
allegro-addons/algif5/src/bitmap.c
allegro-addons/algif5/src/gif.c
allegro-addons/algif5/src/lzw.c
)
target_include_directories(algif5 PUBLIC
allegro-addons/algif5/src
)
target_link_libraries(algif5 PUBLIC allegro_with_legacy)
list(APPEND IMAGELIBS algif5)
add_library(al5img STATIC
allegro-addons/al5img/src/al5img.c
)
target_include_directories(al5img PUBLIC
allegro-addons/al5img/include
)
target_link_libraries(al5img PUBLIC allegro_with_legacy algif5)
list(APPEND IMAGELIBS al5img)
#############################################################
# ZConsole
#############################################################
if(WIN32)
add_executable(zconsole src/zconsole/ConsoleLoggerHelper.cpp)
target_link_options(zconsole PRIVATE "/SUBSYSTEM:CONSOLE")
endif()
add_library(zconsolelogger STATIC src/zconsole/ConsoleLogger.cpp src/util.cpp src/process_managment.cpp)
target_include_directories(zconsolelogger INTERFACE src/zconsole)
target_link_libraries(zconsolelogger allegro_with_legacy)
#############################################################
# Sound Library
#############################################################
if(LINUX)
# TODO: Build sound deps from source on linux.
set(BUILD_SOUND_LIBS_FROM_SOURCE OFF)
else()
set(BUILD_SOUND_LIBS_FROM_SOURCE ON)
endif()
if(BUILD_SOUND_LIBS_FROM_SOURCE)
if(WIN32)
set(SOUND_LIB_SHARED STATIC)
else()
set(SOUND_LIB_SHARED SHARED)
endif()
add_library(almp3 ${SOUND_LIB_SHARED}
allegro-addons/almp3/src/almp3.c
allegro-addons/almp3/decoder/common.c
allegro-addons/almp3/decoder/dct64_i386.c
allegro-addons/almp3/decoder/decode_i386.c
allegro-addons/almp3/decoder/interface.c
allegro-addons/almp3/decoder/layer2.c
allegro-addons/almp3/decoder/layer3.c
allegro-addons/almp3/decoder/tabinit.c
)
target_include_directories(almp3 PUBLIC
allegro-addons/almp3/include
allegro-addons/almp3/decoder
)
target_link_libraries(almp3 PUBLIC allegro_with_legacy)
add_library(alogg ${SOUND_LIB_SHARED}
allegro-addons/alogg/decoder/libogg/macos/compat/strdup.c
allegro-addons/alogg/decoder/libogg/src/bitwise.c
allegro-addons/alogg/decoder/libogg/src/framing.c
allegro-addons/alogg/decoder/libvorbis/lib/analysis.c
allegro-addons/alogg/decoder/libvorbis/lib/bitrate.c
allegro-addons/alogg/decoder/libvorbis/lib/block.c
allegro-addons/alogg/decoder/libvorbis/lib/codebook.c
allegro-addons/alogg/decoder/libvorbis/lib/envelope.c
allegro-addons/alogg/decoder/libvorbis/lib/floor0.c
allegro-addons/alogg/decoder/libvorbis/lib/floor1.c
allegro-addons/alogg/decoder/libvorbis/lib/info.c
allegro-addons/alogg/decoder/libvorbis/lib/lookup.c
allegro-addons/alogg/decoder/libvorbis/lib/lpc.c
allegro-addons/alogg/decoder/libvorbis/lib/lsp.c
allegro-addons/alogg/decoder/libvorbis/lib/mapping0.c
allegro-addons/alogg/decoder/libvorbis/lib/mdct.c
allegro-addons/alogg/decoder/libvorbis/lib/psy.c
allegro-addons/alogg/decoder/libvorbis/lib/registry.c
allegro-addons/alogg/decoder/libvorbis/lib/res0.c
allegro-addons/alogg/decoder/libvorbis/lib/sharedbook.c
allegro-addons/alogg/decoder/libvorbis/lib/smallft.c
allegro-addons/alogg/decoder/libvorbis/lib/synthesis.c
allegro-addons/alogg/decoder/libvorbis/lib/vorbisenc.c
allegro-addons/alogg/decoder/libvorbis/lib/vorbisfile.c
allegro-addons/alogg/decoder/libvorbis/lib/window.c
allegro-addons/alogg/src/alogg.c
)
target_include_directories(alogg PUBLIC
allegro-addons/alogg/include
allegro-addons/alogg/decoder
allegro-addons/alogg/decoder/libogg/include
allegro-addons/alogg/decoder/libvorbis/include
allegro-addons/alogg/decoder/libvorbis/lib
)
target_link_libraries(alogg PUBLIC allegro_with_legacy)
FetchContent_Declare(
gme_external
GIT_REPOSITORY https://bitbucket.org/mpyne/game-music-emu.git
GIT_TAG 839ea742c42c4e0fbe4f153621d92e24c20d0799
)
set(GME_YM2612_EMU "Nuked" CACHE STRING "Which YM2612 emulator to use: \"Nuked\" (LGPLv2.1+), \"MAME\" (GPLv2+), or \"GENS\" (LGPLv2.1+)")
FetchContent_MakeAvailable(gme_external)
add_library(gme_headers INTERFACE)
target_include_directories(gme_headers INTERFACE ${gme_external_SOURCE_DIR}/gme)
target_compile_definitions(gme_headers INTERFACE -DVGM_YM2612_NUKED)
option(BUILD_EXAMPLES "" OFF)
set(ALLEGRO_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/allegro-legacy/include)
set(ALLEGRO_LIBRARY allegro_with_legacy)
FetchContent_Declare(
dumb_external
GIT_REPOSITORY https://github.com/kode54/dumb.git
GIT_TAG 396caa4d31859045ccb5ef943fd430ca4026cce8
PATCH_COMMAND git restore . && git apply ${CMAKE_SOURCE_DIR}/allegro-addons/aldumb.patch
)
FetchContent_MakeAvailable(dumb_external)
add_library(dumb_headers INTERFACE)
target_include_directories(dumb_headers INTERFACE ${dumb_external_SOURCE_DIR}/include)
set(SOUNDLIBS almp3 alogg gme gme_headers aldmb dumb dumb_headers)
endif()
if(MSVC AND (MSVC_VERSION GREATER 1600))
set(ZCSOUNDLIBSEXTRA legacy_stdio_definitions)
endif()
add_library(zcsound SHARED ${ZCSOUNDSOURCES})
target_link_libraries(zcsound PUBLIC allegro_with_legacy ${SOUNDLIBS} ${ZCSOUNDLIBSEXTRA})
if(BUILD_SOUND_LIBS_FROM_SOURCE)
target_compile_definitions(zcsound PRIVATE SOUND_LIBS_BUILT_FROM_SOURCE)
else()
include_directories(./include/dumb)
include_directories(./include/alogg)
include_directories(./include/almp3)
include_directories(./include/gme)
endif()
#############################################################
# Romview
#############################################################
# if(MSVC)
# list(APPEND ROMVIEWEXTRASOURCES rv_icon.rc)
# elseif(LINUX)
# list(APPEND ROMVIEWEXTRASOURCES rv_icon.c)
# set(ROMVIEWLIBSEXTRA ${X11_LIBRARIES})
# endif()
# if(UNITY_BUILD)
# enable_unity_build(RomviewCore ROMVIEW_CORE_SOURCES)
# enable_unity_build(RomviewGUI ROMVIEW_GUI_SOURCES)
# endif()
# add_executable(romview ${ROMVIEW_CORE_SOURCES} ${ROMVIEW_GUI_SOURCES} ${ROMVIEWEXTRASOURCES} ${ROMVIEW_MODULES})
# target_link_libraries(romview ${IMAGELIBS} ${ALLEGROLIB} ${SOUNDLIBS} ${ROMVIEWLIBSEXTRA})
#############################################################
# Zelda
#############################################################
if(MSVC)
list(APPEND ZELDAEXTRASOURCES zc_icon.rc)
elseif(LINUX)
list(APPEND ZELDAEXTRASOURCES zc_icon.c src/single_instance_unix.cpp)
set(ZELDALIBSEXTRA ${X11_LIBRARIES})
endif()
if(UNITY_BUILD)
enable_unity_build(ZeldaCore ZELDA_CORE_SOURCES)
enable_unity_build(ZeldaGUI ZELDA_GUI_SOURCES)
enable_unity_build(ZeldaSprite ZELDA_SPRITE_SOURCES)
enable_unity_build(ZeldaSubscreen ZELDA_SUBSCREEN_SOURCES)
endif()
add_executable(zelda ${ZELDA_CORE_SOURCES} ${ZELDA_GUI_SOURCES} ${ZELDA_SPRITE_SOURCES} ${ZELDA_SUBSCREEN_SOURCES} ${ZELDA_SCRIPTING_SOURCES} ${ZELDAEXTRASOURCES} ${ZELDA_MODULES})
target_compile_definitions(zelda PRIVATE IS_PLAYER)
target_link_libraries(zelda PRIVATE allegro_with_legacy)
if(WIN32)
target_link_libraries(zelda PRIVATE zconsolelogger zcsound winmm ${IMAGELIBS} ${ZELDALIBSEXTRA})
elseif(LINUX)
target_link_libraries(zelda PRIVATE zconsolelogger zcsound ${IMAGELIBS} ${ZELDALIBSEXTRA})
elseif(APPLE)
target_link_libraries(zelda PRIVATE zconsolelogger zcsound ${IMAGELIBS} ${ZELDALIBSEXTRA})
endif()
target_link_libraries(zelda PRIVATE allegro_with_legacy)
if(MSVC AND USE_PCH)
set_target_properties(zelda PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h /Fp\"${ZCPrecompiledBinary}\"" OBJECT_DEPENDS "${ZCPrecompiledBinary}")
target_compile_definitions(zelda PRIVATE ZC_PCH)
endif()
#############################################################
# ZQuest
#############################################################
if(MSVC)
list(APPEND ZQUESTEXTRASOURCES zq_icon.rc)
elseif(LINUX)
list(APPEND ZQUESTEXTRASOURCES zq_icon.c src/single_instance_unix.cpp)
set(ZQUESTLIBSEXTRA ${X11_LIBRARIES})
endif()
if(UNITY_BUILD)
enable_unity_build(ZQuestCore ZQUEST_CORE_SOURCES)
enable_unity_build(ZQuestGUI ZQUEST_GUI_SOURCES)
enable_unity_build(ZQuestMisc ZQUEST_MISC_SOURCES)
enable_unity_build(ZQuestZScript PARSER_SOURCES)
endif()
set(Boost_DEBUG ON) # set to ON if you want to see more info in cmake
set(BOOST_ROOT ${CMAKE_SOURCE_DIR}/include/boost_1_74_0)
set(Boost_INCLUDE_DIR ${BOOST_ROOT})
find_package(Boost 1.74.0)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_definitions(-DHAS_BOOST)
add_executable(zquest ${ZQUEST_CORE_SOURCES} ${ZQUEST_GUI_SOURCES} ${ZQUEST_MISC_SOURCES} ${ZQUESTEXTRASOURCES} ${ZQUEST_MODULES})
target_link_libraries(zquest PUBLIC allegro_with_legacy zconsolelogger zcsound ${IMAGELIBS} ${ZQUESTLIBSEXTRA})
if(MSVC AND USE_PCH)
set_target_properties(zquest PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h /Fp\"${ZQPrecompiledBinary}\"" OBJECT_DEPENDS "${ZQPrecompiledBinary}")
target_compile_definitions(zquest PRIVATE ZC_PCH)
endif()
if(MSVC)
target_compile_definitions(zcsound PRIVATE ZCM_DLL)
target_compile_definitions(zelda PRIVATE ZCM_DLL_IMPORT)
target_compile_definitions(zquest PRIVATE ZCM_DLL_IMPORT)
endif()
target_compile_definitions(zquest PRIVATE IS_ZQUEST)
endif()
if(WIN32)
set_source_files_properties(src/dialog/itemeditor.cpp PROPERTIES COMPILE_FLAGS "/bigobj")
endif()
#############################################################
# ZScript parser
#############################################################
if(LINUX)
set(ZSCRIPTLIBSEXTRA ${X11_LIBRARIES})
endif()
if(${BISON_FOUND} AND ${FLEX_FOUND})
add_executable(zscript ${ZSCRIPT_CORE_SOURCES} ${PARSER_SOURCES} ${BISON_ZScriptParser_OUTPUTS} ${FLEX_ZScriptLexer_OUTPUTS} ${ZSCRIPT_MODULES})
target_link_libraries(zscript allegro_with_legacy zconsolelogger ${ZSCRIPTLIBSEXTRA})
target_compile_definitions(zscript PRIVATE IS_PARSER)
endif()
#############################################################
# Launcher
#############################################################
if(MSVC)
list(APPEND LAUNCHEREXTRASOURCES zl_icon.rc)
elseif(LINUX)
list(APPEND LAUNCHEREXTRASOURCES zl_icon.c src/single_instance_unix.cpp)
set(LAUNCHERLIBSEXTRA ${X11_LIBRARIES})
endif()
add_executable(zlauncher ${LAUNCHER_SOURCES} ${LAUNCHER_GUI_SOURCES} ${LAUNCHEREXTRASOURCES})
target_link_libraries(zlauncher PRIVATE allegro_with_legacy zconsolelogger ${LAUNCHERLIBSEXTRA})
target_compile_definitions(zlauncher PRIVATE IS_LAUNCHER)
#############################################################
# Allegro 5 Example
#############################################################
add_executable(al5_example EXCLUDE_FROM_ALL src/al5_example_main.c)
target_include_directories(al5_example PUBLIC ${allegro5_SOURCE_DIR}/include)
target_include_directories(al5_example PUBLIC ${allegro5_BINARY_DIR}/include)
target_link_libraries(al5_example PRIVATE allegro_with_legacy allegro_font allegro_primitives)
#############################################################
# Misc.
#############################################################
set(zc_targets zquest zelda zlauncher zcsound zscript zconsolelogger)
set(zc_apps zquest zelda zlauncher)
set(zc_warnings
-Werror=format
)
foreach(target IN LISTS zc_apps)
target_compile_definitions(${target} PRIVATE ZC_APP_NAME="${target}")
endforeach()
if(WANT_SENTRY)
set(SENTRY_VERSION 0.4.18)
set(SENTRY_BACKEND crashpad)
set(SENTRY_BUILD_SHARED_LIBS OFF)
FetchContent_Declare(sentry URL https://github.com/getsentry/sentry-native/releases/download/${SENTRY_VERSION}/sentry-native.zip)
FetchContent_MakeAvailable(sentry)
foreach(target IN LISTS zc_apps)
target_link_libraries(${target} PRIVATE sentry)
target_compile_definitions(${target} PRIVATE HAS_SENTRY)
target_compile_definitions(${target} PRIVATE SENTRY_RELEASE_TAG="${SENTRY_RELEASE_TAG}")
endforeach()
endif()
if (WIN32)
list(APPEND zc_targets zconsole)
endif()
foreach(target IN LISTS zc_targets)
if(WIN32)
target_compile_definitions(${target} PRIVATE __STDC_LIMIT_MACROS)
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
# Uncomment to autofix. Only works for clang. When done, comment this line out again.
# target_compile_options(${target} PRIVATE -ferror-limit=10000 -Wno-everything ${zc_warnings} "SHELL:-Xclang -fix-what-you-can" "SHELL:-Xclang -fixit-recompile")
endif()
if(NOT CMAKE_COMPILER_IS_MSVC)
target_compile_options(${target} PRIVATE ${zc_warnings})
endif()
endforeach()
#############################################################
# Visual Studio
#############################################################
if (WIN32)
set_property(TARGET ${zc_targets} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "$(ProjectDir)$(Configuration)")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_target_properties(zcsound gme dumb aldmb almp3 alogg PROPERTIES FOLDER Sound)
set_target_properties(allegro allegro_audio allegro_image allegro_font allegro_main allegro_primitives allegro_dialog allegro-legacy al5img algif5 al5_example PROPERTIES FOLDER Allegro)
set_target_properties(zconsole zconsolelogger PROPERTIES FOLDER ZConsole)
if(WANT_SENTRY)
set_target_properties(crashpad_client crashpad_compat crashpad_getopt crashpad_handler crashpad_handler_lib crashpad_minidump crashpad_snapshot crashpad_tools crashpad_util crashpad_zlib mini_chromium sentry PROPERTIES FOLDER Sentry)
endif()
endif()