forked from diasurgical/devilutionX
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
1728 lines (1598 loc) · 55.2 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
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
cmake_minimum_required(VERSION 3.13)
foreach(_policy CMP0083 CMP0092 CMP0111 CMP0126 CMP0135)
if(POLICY ${_policy})
cmake_policy(SET ${_policy} NEW)
set(CMAKE_POLICY_DEFAULT_${_policy} NEW)
endif()
endforeach()
# Projects added via `add_subdirectory` or `FetchContent` may have a lower
# `cmake_minimum_required` than we set here. Set policies that we require
# to their new value so that they still apply.
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
if(NINTENDO_3DS)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake/ctr")
endif()
if(NOT VERSION_NUM)
include(git)
get_git_tag(VERSION_NUM)
if(NOT VERSION_SUFFIX)
get_git_commit_hash(GIT_COMMIT_HASH)
set(VERSION_SUFFIX "$<$<NOT:$<CONFIG:Release>>:-${GIT_COMMIT_HASH}>")
if(VERSION_SUFFIX AND NOT VERSION_NUM)
set(VERSION_NUM untagged)
endif()
endif()
endif()
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()
string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" PROJECT_VERSION_NUM ${VERSION_NUM} )
if(PROJECT_VERSION_NUM)
project(DevilutionX
VERSION ${PROJECT_VERSION_NUM}
LANGUAGES C CXX)
else()
project(DevilutionX
LANGUAGES C CXX)
endif()
string(TOLOWER ${PROJECT_NAME} project_name)
if(NINTENDO_SWITCH)
include(switch_defs)
endif()
if(VITA)
include("$ENV{VITASDK}/share/vita.cmake" REQUIRED)
include(vita_defs)
endif()
set(TARGET_PLATFORM host CACHE STRING "Target platform")
set_property(CACHE TARGET_PLATFORM PROPERTY STRINGS host lepus retrofw rg350 gkd350h cpigamesh windows9x windowsXP)
if(TARGET_PLATFORM STREQUAL "lepus")
include(lepus_defs)
elseif(TARGET_PLATFORM STREQUAL "retrofw")
include(retrofw_defs)
elseif(TARGET_PLATFORM STREQUAL "rg350")
include(rg350_defs)
elseif(TARGET_PLATFORM STREQUAL "gkd350h")
include(gkd350h_defs)
elseif(TARGET_PLATFORM STREQUAL "cpigamesh")
include(cpigamesh_defs)
elseif(TARGET_PLATFORM STREQUAL "windows9x")
include(windows9x_defs)
elseif(TARGET_PLATFORM STREQUAL "windowsXP")
include(windowsXP_defs)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD|OpenBSD|DragonFly|NetBSD")
if(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
add_definitions(-D_NETBSD_SOURCE)
else()
add_definitions(-D_BSD_SOURCE)
set(UBSAN OFF)
endif()
set(ASAN OFF)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
# Some notable Darwin (macOS kernel) versions are:
# 8.x == macOS 10.4 (Tiger)
# 9.x == macOS 10.5 (Leopard)
#
# Importantly, a lot of the APIs first appeared in version 9, including
# the feature availability API (the <Availability.h> header).
#
# For Darwin 8 and below, we have to rely on the kernel version
# to detect available APIs.
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_SYSTEM_VERSION}")
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\2" DARWIN_MINOR_VERSION "${CMAKE_SYSTEM_VERSION}")
endif()
if(WIN32)
set(ASAN OFF)
set(UBSAN OFF)
if(DEFINED _WIN32_WINNT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WIN32_WINNT=${_WIN32_WINNT}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_WIN32_WINNT=${_WIN32_WINNT}")
endif()
if(DEFINED WINVER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWINVER=${WINVER}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWINVER=${WINVER}")
endif()
set(USE_PATCH ON)
endif()
if(HAIKU)
set(ASAN OFF)
set(UBSAN OFF)
endif()
if(AMIGA)
include(amiga_defs)
endif()
if(NINTENDO_3DS)
include(n3ds_defs)
endif()
if(PS4)
include(ps4_defs)
endif()
if(PS5)
include(ps5_defs)
endif()
if(ANDROID)
include(android_defs)
endif()
if(IOS)
include(ios_defs)
endif()
include(CMakeDependentOption)
include(out_of_tree)
macro(cmake_conditional_option NAME DESCRIPTION)
if(${ARGN})
option(${NAME} ${DESCRIPTION} ON)
else()
option(${NAME} ${DESCRIPTION} OFF)
endif()
endmacro()
macro(cmake_debug_option NAME DESCRIPTION)
cmake_conditional_option(${NAME} ${DESCRIPTION} CMAKE_BUILD_TYPE STREQUAL "Debug")
endmacro()
macro(cmake_release_option NAME DESCRIPTION)
cmake_conditional_option(${NAME} ${DESCRIPTION} NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
endmacro()
cmake_debug_option(ASAN "Enable address sanitizer")
cmake_debug_option(UBSAN "Enable undefined behaviour sanitizer")
cmake_dependent_option(TSAN "Enable thread sanitizer" OFF "NOT ASAN" OFF)
cmake_debug_option(DEBUG_MODE "Enable debug mode in engine")
option(DEV_MODE "Enable development mode in engine" OFF)
option(GPERF "Build with GPerfTools profiler" OFF)
cmake_dependent_option(GPERF_HEAP_FIRST_GAME_ITERATION "Save heap profile of the first game iteration" OFF "GPERF" OFF)
option(DISABLE_LTO "Disable link-time optimization" OFF)
option(DISABLE_STRIP "Disable binary-stripping" OFF)
option(PIE "Generate position-independent code" OFF)
option(CPACK "Configure CPack" ON)
option(USE_LD_MOLD "Use mold linker(GNU|Clang)" OFF)
option(MACOSX_STANDALONE_APP_BUNDLE "Generate a portable app bundle to use on other devices (requires sudo)" OFF)
option(WIN_NSIS "Generate an NSIS installer" OFF)
option(USE_SDL1 "Use SDL1.2 instead of SDL2" OFF)
option(NOSOUND "Disable sound support" OFF)
option(STREAM_ALL_AUDIO "Stream all the audio. For extremely RAM-constrained platforms." OFF)
option(NOWIDESCREEN "Disable widescreen support" OFF)
option(NONET "Disable network support" OFF)
cmake_dependent_option(INET_MODE "Enable validation of network messages" OFF "NOT NONET" OFF)
cmake_dependent_option(ADAPTIVE_NETUPDATE "Build adaptive network support" ON "NOT NONET" OFF)
cmake_dependent_option(NETENCRYPT "Encrypt network messages" ON "NOT NONET" OFF)
cmake_dependent_option(TCPIP "Build with tcp/ip support" ON "NOT NONET" OFF)
cmake_dependent_option(ZEROTIER "Build with zerotier support" ON "NOT NONET AND NOT HOSTONLY" OFF)
cmake_dependent_option(NOHOSTING "Disable support for host-only games" ON "TCPIP" ON)
cmake_dependent_option(HOSTONLY "Disable support for non host-only games" OFF "TCPIP AND NOT NOHOSTING" OFF)
cmake_dependent_option(DISABLE_EXCEPTIONS "Disable exceptions" ON "NONET" OFF)
option(RUN_TESTS "Build and run tests" OFF)
option(HELLFIRE "Build hellfire version" OFF)
option(USE_PATCH "Create executable to patch assets" OFF)
option(CREATE_MPQONE "Merge assets if necessary" OFF)
cmake_dependent_option(USE_MPQONE "Force the use of merged assets" OFF "NOT CREATE_MPQONE" ON)
option(HAS_JOYSTICK "Enable joystick support" ON)
option(HAS_DPAD "Enable D-Pad support" ON)
option(HAS_KBCTRL "Enable keyboard controller support" OFF)
cmake_dependent_option(HAS_GAMECTRL "Enable game controller support" ON "NOT USE_SDL1" OFF)
cmake_dependent_option(HAS_TOUCHPAD "Enable touchpad support" ON "NOT USE_SDL1" OFF)
option(SCREEN_READER_INTEGRATION "Build with screen reader support" OFF)
if(NOT NONET)
option(DEVILUTIONX_SYSTEM_LIBSODIUM "Use system-provided libsodium" OFF)
cmake_conditional_option(DEVILUTIONX_STATIC_LIBSODIUM "Link static libsodium" NOT ${DEVILUTIONX_SYSTEM_LIBSODIUM})
endif()
if(NOT USE_SDL1)
option(DEVILUTIONX_SYSTEM_SDL2 "Use system-provided SDL2" OFF)
cmake_conditional_option(DEVILUTIONX_STATIC_SDL2 "Link static SDL2" NOT ${DEVILUTIONX_SYSTEM_SDL2})
endif()
if(HELLFIRE)
set(MPQONE \"hellone.mpq\")
else()
set(MPQONE \"diablone.mpq\")
endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # for clang-tidy
set(CMAKE_THREAD_PREFER_PTHREAD ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
if(PIE)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
endif()
# Remove unused symbols in non-debug mode.
# This is useful even with LTO (-84 KiB with MinSizeRel).
#
# PS4 toolchain crashes in `create-fself` when linking with these flags, so we exclude it:
# https://github.com/PacBrew/ps4-openorbis/issues/8
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT PS4)
# For some reason, adding to CMAKE_CXX_FLAGS results in a slightly smaller
# binary than using `add_compile/link_options`
add_compile_options("$<$<NOT:$<CONFIG:Debug>>:-ffunction-sections;-fdata-sections>")
if(APPLE)
add_link_options("$<$<NOT:$<CONFIG:Debug>>:LINKER:-dead_strip>")
else()
add_link_options("$<$<NOT:$<CONFIG:Debug>>:LINKER:--gc-sections,--as-needed>")
endif()
if(USE_LD_MOLD)
if(NOT CMAKE_CROSSCOMPILING)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12)
find_program(
LD_MOLD_PATH
ld
PATHS
${CMAKE_INSTALL_PREFIX}/libexec/mold
ENV LD_MOLD_PATH
NO_DEFAULT_PATH
)
if(NOT LD_MOLD_PATH STREQUAL "LD_MOLD_PATH-NOTFOUND")
get_filename_component(_mold_dir ${LD_MOLD_PATH} DIRECTORY)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -B${_mold_dir}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -B${_mold_dir}")
else()
message(WARNING "-- Cannot use mold linker: mold ld directory not found")
endif()
else()
#elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=mold")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=mold")
endif()
else()
message(WARNING "-- Mold linker is disabled due to CMAKE_CROSSCOMPILING")
endif()
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# -fipa-pta and -fdevirtualize-at-ltrans improve performance.
add_compile_options("$<$<NOT:$<CONFIG:Debug>>:-fipa-pta;-fdevirtualize-at-ltrans>")
endif()
# Not a genexp because CMake doesn't support it
# https://gitlab.kitware.com/cmake/cmake/-/issues/20546
if(NOT DISABLE_LTO)
# LTO if supported:
include(CheckIPOSupported)
check_ipo_supported(RESULT is_ipo_supported OUTPUT lto_error)
if(is_ipo_supported)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL ON)
endif()
endif()
find_package(Threads REQUIRED)
if(NINTENDO_3DS)
find_package(CITRO3D REQUIRED)
#find_package(FREETYPE REQUIRED)
#find_package(BZIP2 REQUIRED)
#find_package(Tremor REQUIRED)
#find_package(OGG REQUIRED)
#find_package(MIKMOD REQUIRED)
#find_package(MAD REQUIRED)
#find_package(PNG REQUIRED)
endif()
if(AMIGA)
#find_package(Freetype REQUIRED)
find_package(ZLIB REQUIRED)
endif()
if(NOT NONET)
if(DEVILUTIONX_SYSTEM_LIBSODIUM)
set(sodium_USE_STATIC_LIBS ${DEVILUTIONX_STATIC_LIBSODIUM})
find_package(sodium REQUIRED)
else()
add_subdirectory(3rdParty/libsodium)
endif()
endif()
if(USE_SDL1)
find_package(SDL 1.2.10 REQUIRED)
include_directories(${SDL_INCLUDE_DIR})
elseif(DEVILUTIONX_SYSTEM_SDL2)
find_package(SDL2 REQUIRED)
if(TARGET SDL2::SDL2)
set(SDL2_MAIN SDL2::SDL2main)
elseif(TARGET SDL2::SDL2-static)
# On some distros, such as vitasdk, only the SDL2::SDL2-static target is available.
# Alias to SDL2::SDL2 because some finder scripts may refer to SDL2::SDL2.
if(CMAKE_VERSION VERSION_LESS "3.18")
# Aliasing local targets is not supported on CMake < 3.18, so make it global.
set_target_properties(SDL2::SDL2-static PROPERTIES IMPORTED_GLOBAL TRUE)
endif()
add_library(SDL2::SDL2 ALIAS SDL2::SDL2-static)
set(SDL2_MAIN SDL2::SDL2main)
else()
# Assume an older Debian derivate that comes with an sdl2-config.cmake
# that only defines `SDL2_LIBRARIES` (as -lSDL2) and `SDL2_INCLUDE_DIRS`.
add_library(SDL2_lib INTERFACE)
target_link_libraries(SDL2_lib INTERFACE ${SDL2_LIBRARIES})
target_include_directories(SDL2_lib INTERFACE ${SDL2_INCLUDE_DIRS})
# Can't define an INTERFACE target with ::, so alias instead
add_library(SDL2::SDL2 ALIAS SDL2_lib)
endif()
else()
add_subdirectory(3rdParty/SDL2)
set(SDL2_MAIN SDL2::SDL2main)
endif()
if(NOT NOSOUND)
add_library(SDL2_mixer STATIC
3rdParty/SDL2_mixer/src/effect_position.c
3rdParty/SDL2_mixer/src/effects_internal.c
3rdParty/SDL2_mixer/src/mixer.c
3rdParty/SDL2_mixer/src/music.c
3rdParty/SDL2_mixer/src/utils.c
3rdParty/SDL2_mixer/src/codecs/music_wav.c)
target_compile_definitions(SDL2_mixer PRIVATE MUSIC_WAV)
if(USE_SDL1)
target_link_libraries(SDL2_mixer PRIVATE ${SDL_LIBRARY})
else()
target_link_libraries(SDL2_mixer PRIVATE SDL2::SDL2)
endif()
# include with 'BEFORE' to handle 'smart' environments where SDL(2)_INCLUDE_DIR
# contains SDL(2)_mixer...
#target_include_directories(SDL2_mixer PUBLIC 3rdParty/SDL2_mixer/include)
include_directories(BEFORE PUBLIC 3rdParty/SDL2_mixer/include)
set(SDL_MIXER_LIBRARY SDL2_mixer)
endif()
if(TCPIP)
add_subdirectory(3rdParty/asio)
target_compile_definitions(asio INTERFACE ASIO_STANDALONE ASIO_NO_TYPEID ASIO_DISABLE_FILE ASIO_CONCURRENCY_HINT_DEFAULT=1 ASIO_NO_EXCEPTIONS)
if(NINTENDO_3DS)
target_compile_definitions(asio INTERFACE ASIO_DISABLE_THREADS=ON ASIO_HAS_UNISTD_H=ON)
# Missing headers and declarations provided by DevilutionX
target_include_directories(asio BEFORE INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/Source/platform/ctr/asio/include)
elseif(NINTENDO_SWITCH)
# Enables a number of header file definitions required by ASIO
target_compile_definitions(asio INTERFACE _DEFAULT_SOURCE=ON)
# Missing headers and declarations provided by DevilutionX
target_include_directories(asio BEFORE INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/Source/platform/switch/asio/include)
endif()
endif()
if(ZEROTIER)
add_subdirectory(3rdParty/libzt)
endif()
if(SCREEN_READER_INTEGRATION)
if(WIN32)
add_subdirectory(3rdParty/tolk)
#target_compile_definitions(libdevilutionx PRIVATE Tolk)
set(SCREEN_READER_LIBRARY Tolk)
else()
find_package(Speechd REQUIRED)
include_directories(PUBLIC ${Speechd_INCLUDE_DIRS})
set(SCREEN_READER_LIBRARY Speechd)
endif()
endif()
add_library(smacker STATIC
3rdParty/libsmacker/smacker.c)
target_include_directories(smacker PUBLIC 3rdParty/libsmacker)
#if(WIN32)
# add_subdirectory(3rdParty/find_steam_game)
#endif()
add_library(Radon STATIC
3rdParty/Radon/Radon/source/File.cpp
3rdParty/Radon/Radon/source/Key.cpp
3rdParty/Radon/Radon/source/Named.cpp
3rdParty/Radon/Radon/source/Section.cpp)
target_include_directories(Radon PUBLIC 3rdParty/Radon/Radon/include)
add_library(StormLib STATIC
3rdParty/StormLib/src/FileStream.cpp
3rdParty/StormLib/src/SBaseCommon.cpp
3rdParty/StormLib/src/SBaseFileTable.cpp
3rdParty/StormLib/src/SBaseSubTypes.cpp
3rdParty/StormLib/src/SCompression.cpp
3rdParty/StormLib/src/SFileExtractFile.cpp
3rdParty/StormLib/src/SFileFindFile.cpp
3rdParty/StormLib/src/SFileGetFileInfo.cpp
3rdParty/StormLib/src/SFileOpenArchive.cpp
3rdParty/StormLib/src/SFileOpenFileEx.cpp
3rdParty/StormLib/src/SFileReadFile.cpp)
#if(WIN32)
## Enable Unicode for StormLib wchar_t* file APIs
#target_compile_definitions(StormLib PRIVATE -DUNICODE -D_UNICODE)
#endif()
add_library(PKWare STATIC
3rdParty/PKWare/explode.cpp
3rdParty/PKWare/implode.cpp
3rdParty/PKWare/pkware.cpp)
target_include_directories(PKWare PUBLIC 3rdParty/PKWare)
set(devilutionx_SRCS
Source/appfat.cpp
Source/automap.cpp
Source/capture.cpp
Source/codec.cpp
Source/control.cpp
Source/cursor.cpp
Source/debug.cpp
Source/diablo.cpp
#Source/doom.cpp
Source/drlg_l1.cpp
Source/drlg_l2.cpp
Source/drlg_l3.cpp
Source/drlg_l4.cpp
#Source/dthread.cpp
Source/dx.cpp
Source/effects.cpp
Source/encrypt.cpp
Source/engine.cpp
Source/error.cpp
Source/gamemenu.cpp
Source/gameui.cpp
Source/gendung.cpp
Source/gmenu.cpp
Source/help.cpp
Source/init.cpp
Source/interfac.cpp
Source/inv.cpp
Source/itemdat.cpp
Source/items.cpp
Source/lighting.cpp
Source/loadsave.cpp
Source/main.cpp
Source/mainmenu.cpp
Source/minitext.cpp
Source/misdat.cpp
Source/missiles.cpp
Source/monstdat.cpp
Source/monster.cpp
Source/movie.cpp
Source/mpqapi.cpp
Source/msg.cpp
Source/multi.cpp
Source/nthread.cpp
Source/objdat.cpp
Source/objects.cpp
Source/pack.cpp
Source/palette.cpp
Source/path.cpp
Source/pfile.cpp
Source/player.cpp
Source/plrmsg.cpp
Source/portal.cpp
Source/questdat.cpp
Source/quests.cpp
Source/scrollrt.cpp
Source/sha.cpp
Source/sound.cpp
Source/spelldat.cpp
Source/spells.cpp
Source/stores.cpp
Source/sync.cpp
Source/textdat.cpp
Source/themes.cpp
#Source/tmsg.cpp
Source/town.cpp
Source/towners.cpp
#Source/track.cpp
Source/trigs.cpp
Source/controls/axis_direction.cpp
Source/controls/controller.cpp
Source/controls/controller_motion.cpp
Source/controls/devices/game_controller.cpp
Source/controls/devices/joystick.cpp
Source/controls/devices/kbcontroller.cpp
Source/controls/game_controls.cpp
Source/controls/modifier_hints.cpp
Source/controls/plrctrls.cpp
Source/controls/touch.cpp
Source/DiabloUI/credits.cpp
#Source/DiabloUI/credits_lines.cpp
Source/DiabloUI/diabloui.cpp
Source/DiabloUI/dialogs.cpp
#Source/DiabloUI/errorart.cpp
Source/DiabloUI/hostgame.cpp
Source/DiabloUI/mainmenu.cpp
Source/DiabloUI/progress.cpp
Source/DiabloUI/scrollbar.cpp
Source/DiabloUI/selconn.cpp
Source/DiabloUI/selgame.cpp
Source/DiabloUI/selhero.cpp
Source/DiabloUI/selok.cpp
Source/DiabloUI/selyesno.cpp
Source/DiabloUI/settingsmenu.cpp
Source/DiabloUI/text.cpp
Source/DiabloUI/text_draw.cpp
Source/DiabloUI/title.cpp
Source/dvlnet/abstract_net.cpp
Source/dvlnet/base_client.cpp
Source/dvlnet/frame_queue.cpp
Source/dvlnet/loopback.cpp
Source/dvlnet/packet.cpp
Source/dvlnet/protocol_zt.cpp
Source/dvlnet/tcp_client.cpp
Source/dvlnet/tcp_server.cpp
Source/dvlnet/tcpd_client.cpp
Source/dvlnet/tcp_host.cpp
Source/dvlnet/zerotier_native.cpp
Source/dvlnet/zerotier_lwip.cpp
Source/dvlnet/zt_client.cpp
Source/engine/render/cel_render.cpp
Source/engine/render/cl2_render.cpp
Source/engine/render/dun_render.cpp
Source/engine/render/raw_render.cpp
Source/engine/render/text_render.cpp
Source/miniwin/misc_msg.cpp
Source/storm/storm.cpp
Source/storm/storm_cfg.cpp
Source/storm/storm_net.cpp
Source/storm/storm_svid.cpp
Source/utils/display.cpp
Source/utils/paths.cpp
Source/utils/screen_reader.cpp
Source/utils/sdl2_to_1_2_backports.cpp
Source/utils/soundsample.cpp
Source/utils/thread.cpp
Source/utils/utf8.cpp)
if(IOS)
list(APPEND devilutionx_SRCS Source/platform/ios/ios_paths.m)
endif()
if(NINTENDO_SWITCH)
list(APPEND devilutionx_SRCS
Source/platform/switch/docking.cpp
Source/platform/switch/keyboard.cpp
Source/platform/switch/network.cpp
Source/platform/switch/random.cpp
Source/platform/switch/romfs.cpp
Source/platform/switch/asio/pause.c
Source/platform/switch/asio/net/if.c
Source/platform/switch/asio/sys/signal.c)
endif()
if(VITA)
list(APPEND devilutionx_SRCS
Source/platform/vita/random.cpp
Source/platform/vita/network.cpp
Source/platform/vita/keyboard.cpp)
endif()
if(NINTENDO_3DS)
list(APPEND devilutionx_SRCS
Source/platform/ctr/system.cpp
Source/platform/ctr/keyboard.cpp
Source/platform/ctr/display.cpp
Source/platform/ctr/messagebox.cpp
Source/platform/ctr/random.cpp
Source/platform/ctr/sockets.cpp
Source/platform/ctr/asio/net/if.c
Source/platform/ctr/asio/sys/socket.c
Source/platform/ctr/asio/sys/uio.c)
endif()
if(RUN_TESTS)
list(APPEND devilutionx_SRCS
test/appfat_test.cpp
test/automap_test.cpp
test/codec_test.cpp
test/control_test.cpp
test/cursor_test.cpp
test/diablo_test.cpp
test/doom_test.cpp
test/drlg_l1_test.cpp
test/drlg_l2_test.cpp
test/drlg_l3_test.cpp
test/drlg_l4_test.cpp
test/effects_test.cpp
test/file_util_test.cpp
test/gfx_test.cpp
test/lighting_test.cpp
test/missiles_test.cpp
test/player_test.cpp
test/projectile_test.cpp
test/scrollrt_test.cpp
test/stores_test.cpp)
endif()
set(BIN_TARGET ${project_name})
if(NINTENDO_3DS)
set(BIN_TARGET ${BIN_TARGET}.elf)
endif()
if(ANDROID)
add_library(${BIN_TARGET} SHARED ${devilutionx_SRCS})
else()
set(BIN_SOURCES ${devilutionx_SRCS})
if(APPLE)
list(APPEND BIN_SOURCES
Packaging/apple/AppIcon.icns
Packaging/apple/LaunchScreen.storyboard)
elseif(WIN32)
list(APPEND BIN_SOURCES Packaging/windows/devilutionx.exe.manifest)
if(HELLFIRE)
list(APPEND BIN_SOURCES Packaging/windows/hellfire.rc)
else()
list(APPEND BIN_SOURCES Packaging/windows/devilutionx.rc)
endif()
endif()
add_executable(${BIN_TARGET}
WIN32
MACOSX_BUNDLE
${BIN_SOURCES})
endif()
if(USE_PATCH AND NOT ANDROID)
set(DEVIL_PATCHER devil_patcher)
set(devil_patcher_SRCS
tools/patcher/appfat.cpp
tools/patcher/control.cpp
tools/patcher/cursor.cpp
tools/patcher/diablo.cpp
tools/patcher/drlp_l1.cpp
tools/patcher/drlp_l2.cpp
tools/patcher/drlp_l3.cpp
tools/patcher/drlp_l4.cpp
tools/patcher/dx.cpp
tools/patcher/effects.cpp
tools/patcher/encrypt.cpp
tools/patcher/engine.cpp
tools/patcher/init.cpp
tools/patcher/lighting.cpp
tools/patcher/main.cpp
tools/patcher/mainmenu.cpp
tools/patcher/mpqapi.cpp
tools/patcher/palette.cpp
tools/patcher/patchdung.cpp
tools/patcher/scrollrt.cpp
tools/patcher/sound.cpp
tools/patcher/townp.cpp
tools/patcher/controls/axis_direction.cpp
tools/patcher/controls/controller.cpp
tools/patcher/controls/controller_motion.cpp
tools/patcher/controls/devices/game_controller.cpp
tools/patcher/controls/devices/joystick.cpp
tools/patcher/controls/devices/kbcontroller.cpp
tools/patcher/controls/game_controls.cpp
tools/patcher/controls/touch.cpp
tools/patcher/DiabloUI/checker.cpp
tools/patcher/DiabloUI/diabloui.cpp
tools/patcher/DiabloUI/dialogs.cpp
tools/patcher/DiabloUI/mainmenu.cpp
tools/patcher/DiabloUI/merger.cpp
tools/patcher/DiabloUI/patcher.cpp
tools/patcher/DiabloUI/progress.cpp
tools/patcher/DiabloUI/scrollbar.cpp
tools/patcher/DiabloUI/selok.cpp
tools/patcher/DiabloUI/selyesno.cpp
tools/patcher/DiabloUI/text.cpp
tools/patcher/DiabloUI/text_draw.cpp
tools/patcher/DiabloUI/title.cpp
tools/patcher/engine/render/cel_render.cpp
tools/patcher/engine/render/cl2_render.cpp
tools/patcher/engine/render/dun_render.cpp
tools/patcher/engine/render/text_render.cpp
tools/patcher/miniwin/misc_msg.cpp
tools/patcher/storm/storm.cpp
tools/patcher/storm/storm_cfg.cpp
tools/patcher/utils/display.cpp
tools/patcher/utils/paths.cpp
tools/patcher/utils/screen_reader.cpp
tools/patcher/utils/sdl2_to_1_2_backports.cpp
tools/patcher/utils/soundsample.cpp)
if(IOS)
list(APPEND devil_patcher_SRCS tools/patcher/platform/ios/ios_paths.m)
endif()
if(NINTENDO_SWITCH)
list(APPEND devil_patcher_SRCS
tools/patcher/platform/switch/docking.cpp
tools/patcher/platform/switch/romfs.cpp)
endif()
if(NINTENDO_3DS)
list(APPEND devil_patcher_SRCS
tools/patcher/platform/ctr/system.cpp
tools/patcher/platform/ctr/display.cpp
tools/patcher/platform/ctr/messagebox.cpp)
endif()
set(PATCHER_SOURCES ${devil_patcher_SRCS})
if(APPLE)
list(APPEND PATCHER_SOURCES
Packaging/apple/AppIcon.icns
Packaging/apple/LaunchScreen.storyboard)
elseif(WIN32)
list(APPEND PATCHER_SOURCES Packaging/windows/devilutionx.exe.manifest)
if(HELLFIRE)
list(APPEND PATCHER_SOURCES Packaging/windows/hellfire.rc)
else()
list(APPEND PATCHER_SOURCES Packaging/windows/devilutionx.rc)
endif()
endif()
add_executable(${DEVIL_PATCHER}
WIN32
MACOSX_BUNDLE
${PATCHER_SOURCES})
target_link_libraries(${DEVIL_PATCHER} PRIVATE
PKWare
StormLib
#smacker
Radon)
if(USE_SDL1)
target_link_libraries(${DEVIL_PATCHER} PRIVATE
${SDL_LIBRARY})
else()
target_link_libraries(${DEVIL_PATCHER} PRIVATE
${SDL2_MAIN}
SDL2::SDL2)
endif()
if(NOT NOSOUND)
target_link_libraries(${DEVIL_PATCHER} PRIVATE ${SDL_MIXER_LIBRARY})
endif()
if(SCREEN_READER_INTEGRATION)
target_link_libraries(${DEVIL_PATCHER} PRIVATE ${SCREEN_READER_LIBRARY})
endif()
target_include_directories(${DEVIL_PATCHER} PRIVATE
tools/patcher
${CMAKE_BINARY_DIR})
endif()
if(CMAKE_STRIP AND NOT DISABLE_STRIP)
add_custom_command(
TARGET ${BIN_TARGET} POST_BUILD
DEPENDS ${BIN_TARGET}
COMMAND $<$<OR:$<CONFIG:Release>,$<CONFIG:MinSizeRel>>:${CMAKE_STRIP}>
ARGS $<TARGET_FILE:${BIN_TARGET}>)
if(DEVIL_PATCHER)
add_custom_command(
TARGET ${DEVIL_PATCHER} POST_BUILD
DEPENDS ${DEVIL_PATCHER}
COMMAND $<$<OR:$<CONFIG:Release>,$<CONFIG:MinSizeRel>>:${CMAKE_STRIP}>
ARGS $<TARGET_FILE:${DEVIL_PATCHER}>)
endif()
endif()
# Use file GENERATE instead of configure_file because configure_file
# does not support generator expressions.
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(is_multi_config)
set(CONFIG_PATH $<CONFIG>/config.h)
target_include_directories(${BIN_TARGET} PRIVATE ${CMAKE_BINARY_DIR}/$<CONFIG>)
if(DEVIL_PATCHER)
target_include_directories(${DEVIL_PATCHER} PRIVATE ${CMAKE_BINARY_DIR}/$<CONFIG>)
endif()
else()
set(CONFIG_PATH config.h)
endif()
file(GENERATE OUTPUT ${CONFIG_PATH} CONTENT
"#pragma once
#define PROJECT_NAME \"${PROJECT_NAME}\"
#define PROJECT_VERSION \"$<IF:$<OR:$<BOOL:${VERSION_NUM}>,$<BOOL:${VERSION_SUFFIX}>>,${VERSION_NUM}${VERSION_SUFFIX},?>\"
")
if(RUN_TESTS)
include(CTest)
include(GoogleTest)
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
add_definitions(-DRUN_TESTS)
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_definitions(-fprofile-arcs -ftest-coverage)
endif()
target_link_libraries(${BIN_TARGET} PRIVATE -fprofile-arcs ${GTEST_LIBRARIES})
gtest_add_tests(${BIN_TARGET} "" AUTO)
endif()
if(GPERF)
find_package(Gperftools REQUIRED)
if(GPERF_HEAP_FIRST_GAME_ITERATION)
set(GPERF_HEAP_MAIN ON)
endif()
# Compile with information about file and line numbers for everything
# even in non-Debug build types.
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compile_options("$<$<NOT:$<CONFIG:Debug>>:-g2>")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Use the more size-efficient `-gmlt` option on clang.
add_compile_options("$<$<NOT:$<CONFIG:Debug>>:-gmlt>")
endif()
endif()
target_include_directories(${BIN_TARGET} PRIVATE
Source
${CMAKE_BINARY_DIR})
target_link_libraries(${BIN_TARGET} PUBLIC Threads::Threads)
target_link_libraries(${BIN_TARGET} PRIVATE
PKWare
StormLib
smacker
Radon)
#if(WIN32)
# target_link_libraries(libdevilutionx PUBLIC find_steam_game)
#endif()
if(NOT NONET)
target_link_libraries(${BIN_TARGET} PRIVATE sodium)
endif()
if(TCPIP)
target_link_libraries(${BIN_TARGET} PRIVATE asio)
endif()
if(ZEROTIER)
target_link_libraries(${BIN_TARGET} PRIVATE zt)
endif()
# Defines without value
foreach(
def_name
USE_SDL1
HELLFIRE
USE_PATCH
USE_MPQONE
CREATE_MPQONE
NOSOUND
STREAM_ALL_AUDIO
NOWIDESCREEN
NONET
INET_MODE
NETENCRYPT
ADAPTIVE_NETUPDATE
NOHOSTING
HOSTONLY
TCPIP
ZEROTIER
HAS_GAMECTRL
HAS_DPAD
HAS_TOUCHPAD
HAS_KBCTRL
HAS_JOYSTICK
SCREEN_READER_INTEGRATION
PREFILL_PLAYER_NAME
NOMEMCCPY
DEBUG_MODE
DEV_MODE
GPERF
GPERF_HEAP_MAIN
GPERF_HEAP_FIRST_GAME_ITERATION
)
if(${def_name})
list(APPEND def_list ${def_name})
endif()
endforeach(def_name)
# Defines with value
foreach(
def_name
MPQONE
ASSET_MPL
DEFAULT_WIDTH
DEFAULT_HEIGHT
SCREEN_WIDTH
SCREEN_HEIGHT
#TTF_FONT_DIR
#TTF_FONT_NAME
#WINVER
#_WIN32_WINNT
SDL1_VIDEO_MODE_BPP
SDL1_VIDEO_MODE_FLAGS
SDL1_VIDEO_MODE_SVID_FLAGS
SDL1_FORCE_SVID_VIDEO_MODE
KBCTRL_BUTTON_DPAD_LEFT
KBCTRL_BUTTON_DPAD_RIGHT
KBCTRL_BUTTON_DPAD_UP
KBCTRL_BUTTON_DPAD_DOWN
KBCTRL_BUTTON_B
KBCTRL_BUTTON_A
KBCTRL_BUTTON_Y
KBCTRL_BUTTON_X
KBCTRL_BUTTON_LEFTSTICK
KBCTRL_BUTTON_RIGHTSTICK
KBCTRL_BUTTON_RIGHTSHOULDER
KBCTRL_BUTTON_LEFTSHOULDER
KBCTRL_BUTTON_TRIGGERLEFT
KBCTRL_BUTTON_TRIGGERRIGHT
KBCTRL_BUTTON_START
KBCTRL_BUTTON_BACK
KBCTRL_IGNORE_1
JOY_AXIS_LEFTX
JOY_AXIS_LEFTY
JOY_AXIS_RIGHTX
JOY_AXIS_RIGHTY
JOY_HAT_DPAD_UP_HAT
JOY_HAT_DPAD_UP
JOY_HAT_DPAD_DOWN_HAT
JOY_HAT_DPAD_DOWN
JOY_HAT_DPAD_LEFT_HAT
JOY_HAT_DPAD_LEFT
JOY_HAT_DPAD_RIGHT_HAT
JOY_HAT_DPAD_RIGHT
JOY_BUTTON_DPAD_LEFT
JOY_BUTTON_DPAD_RIGHT
JOY_BUTTON_DPAD_UP
JOY_BUTTON_DPAD_DOWN
JOY_BUTTON_B
JOY_BUTTON_A
JOY_BUTTON_Y
JOY_BUTTON_X
JOY_BUTTON_LEFTSTICK
JOY_BUTTON_RIGHTSTICK
JOY_BUTTON_RIGHTSHOULDER
JOY_BUTTON_LEFTSHOULDER
JOY_BUTTON_TRIGGERLEFT
JOY_BUTTON_TRIGGERRIGHT
JOY_BUTTON_START
JOY_BUTTON_BACK
DARWIN_MAJOR_VERSION
DARWIN_MINOR_VERSION
)
if(DEFINED ${def_name})
list(APPEND def_list ${def_name}=${${def_name}})
endif()
endforeach(def_name)
target_compile_definitions(${BIN_TARGET} PRIVATE ${def_list})
target_compile_definitions(smacker PRIVATE ${def_list})
if(DEVIL_PATCHER)
target_compile_definitions(${DEVIL_PATCHER} PRIVATE ${def_list})
endif()
if(UBSAN)
target_compile_options(${BIN_TARGET} PUBLIC -fsanitize=undefined)
target_link_libraries(${BIN_TARGET} PUBLIC -fsanitize=undefined)
endif()
if(TSAN)
target_compile_options(${BIN_TARGET} PUBLIC -fsanitize=thread)
target_link_libraries(${BIN_TARGET} PUBLIC -fsanitize=thread)
elseif(ASAN)
target_compile_options(${BIN_TARGET} PUBLIC "-fsanitize=address;-fsanitize-recover=address")
target_link_libraries(${BIN_TARGET} PUBLIC "-fsanitize=address;-fsanitize-recover=address")
endif()
if(USE_SDL1)
target_link_libraries(${BIN_TARGET} PRIVATE
${SDL_LIBRARY})
else()
target_link_libraries(${BIN_TARGET} PRIVATE
${SDL2_MAIN}
SDL2::SDL2)
endif()
if(NOT NOSOUND)
target_link_libraries(${BIN_TARGET} PRIVATE ${SDL_MIXER_LIBRARY})
endif()
if(SCREEN_READER_INTEGRATION)
target_link_libraries(${BIN_TARGET} PRIVATE ${SCREEN_READER_LIBRARY})
endif()