forked from TeeworldsCN/ddnet-pvp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1535 lines (1399 loc) · 44.8 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 2.8.12...3.19.1)
if(CMAKE_VERSION VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_VERSION})
endif()
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9 CACHE INTERNAL "")
if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.9)
message(WARNING "Building for macOS <= 10.9 is not supported")
endif()
file(STRINGS src/game/version.h VERSION_LINE
LIMIT_COUNT 1
REGEX "^#define GAME_RELEASE_VERSION "
)
if(VERSION_LINE MATCHES "\"([0-9]+)\\.([0-9]+)\\.([0-9]+)\"")
set(VERSION_MAJOR ${CMAKE_MATCH_1})
set(VERSION_MINOR ${CMAKE_MATCH_2})
set(VERSION_PATCH ${CMAKE_MATCH_3})
elseif(VERSION_LINE MATCHES "\"([0-9]+)\\.([0-9]+)\"")
set(VERSION_MAJOR ${CMAKE_MATCH_1})
set(VERSION_MINOR ${CMAKE_MATCH_2})
set(VERSION_PATCH "0")
else()
message(FATAL_ERROR "Couldn't parse version from src/game/version.h")
endif()
# Extra support for CMake pre-3.0
if(NOT POLICY CMP0048)
set(PROJECT_VERSION_MAJOR ${VERSION_MAJOR})
set(PROJECT_VERSION_MINOR ${VERSION_MINOR})
set(PROJECT_VERSION_PATCH ${VERSION_PATCH})
if(VERSION_PATCH STREQUAL "0")
set(PROJECT_VERSION ${VERSION_MAJOR}.${VERSION_MINOR})
else()
set(PROJECT_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
endif()
endif()
if(VERSION_PATCH STREQUAL "0")
project(DDNet VERSION ${VERSION_MAJOR}.${VERSION_MINOR})
else()
project(DDNet VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
endif()
set(ORIGINAL_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
set(ORIGINAL_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
set(ORIGINAL_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
set(OWN_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_MODULE_PATH ${OWN_CMAKE_MODULE_PATH})
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(TARGET_BITS "32")
else()
set(TARGET_BITS "64")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(TARGET_OS "windows")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(TARGET_OS "linux")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(TARGET_OS "mac")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Haiku")
set(TARGET_OS "haiku")
endif()
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckSymbolExists)
check_symbol_exists(__i386 "" TARGET_ARCH_X86_i386)
if(TARGET_ARCH_X86_i386)
set(TARGET_ARCH x86)
else()
set(TARGET_ARCH)
endif()
set(AUTO_DEPENDENCIES_DEFAULT OFF)
if(TARGET_OS STREQUAL "windows")
set(AUTO_DEPENDENCIES_DEFAULT ON)
elseif(TARGET_OS STREQUAL "linux")
endif()
option(WEBSOCKETS "Enable websockets support" OFF)
option(MYSQL "Enable mysql support" OFF)
option(UPNP "Enable UPnP support" OFF)
option(ANTIBOT "Enable support for a dynamic anticheat library" OFF)
option(DOWNLOAD_GTEST "Download and compile GTest" OFF)
option(PREFER_BUNDLED_LIBS "Prefer bundled libraries over system libraries" ${AUTO_DEPENDENCIES_DEFAULT})
option(DEV "Don't generate stuff necessary for packaging" OFF)
# Set version if not explicitly set
if(NOT VERSION)
set(VERSION ${PROJECT_VERSION})
endif()
# Set the default build type to Release
if(NOT(CMAKE_BUILD_TYPE))
if(NOT(DEV))
set(CMAKE_BUILD_TYPE Release)
else()
set(CMAKE_BUILD_TYPE Debug)
endif()
endif()
if(NOT(CMAKE_BUILD_TYPE MATCHES "^(Release|Debug|RelWithDebInfo|MinSizeRel)$"))
message(WARNING "Unknown CMAKE_BUILD_TYPE, should be one of Release, Debug, RelWithDebInfo or MinSizeRel")
endif()
set(DBG $<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>)
if(CMAKE_VERSION VERSION_LESS 3.0)
configure_file(src/game/version.h vd.h)
else()
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
src/game/version.h
)
endif()
set(SERVER_EXECUTABLE DDNet-Server CACHE STRING "Name of the built server executable")
########################################################################
# Compiler flags
########################################################################
# Add macro _GNU_SOURCE for build in alpine
add_definitions( -D_GNU_SOURCE)
function(add_c_compiler_flag_if_supported VARIABLE FLAG)
if(ARGC GREATER 2)
set(CHECKED_FLAG "${ARGV2}")
else()
set(CHECKED_FLAG "${FLAG}")
endif()
string(REGEX REPLACE "[^A-Za-z0-9]" "_" CONFIG_VARIABLE "FLAG_SUPPORTED${CHECKED_FLAG}")
check_c_compiler_flag("${CHECKED_FLAG}" ${CONFIG_VARIABLE})
if(${CONFIG_VARIABLE})
if(${VARIABLE})
set("${VARIABLE}" "${${VARIABLE}};${FLAG}" PARENT_SCOPE)
else()
set("${VARIABLE}" "${FLAG}" PARENT_SCOPE)
endif()
endif()
endfunction()
# Force compiler colors on when using ninja. Ninja filters the colors out when
# it's not printing to a terminal on its own.
if(CMAKE_GENERATOR STREQUAL "Ninja")
add_c_compiler_flag_if_supported(OUR_FLAGS -fdiagnostics-color=always)
add_c_compiler_flag_if_supported(OUR_FLAGS -fcolor-diagnostics)
endif()
if(NOT MSVC AND NOT HAIKU)
if(CMAKE_VERSION VERSION_LESS 3.1 OR TARGET_OS STREQUAL "mac")
check_cxx_compiler_flag(-std=gnu++11 FLAG_SUPPORTED_std_gnu__11)
if(FLAG_SUPPORTED_std_gnu__11)
if(CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
else()
set(CMAKE_CXX_FLAGS -std=gnu++11)
endif()
endif()
endif()
# Protect the stack pointer.
# -fstack-protector-all doesn't work on MinGW.
add_c_compiler_flag_if_supported(OUR_FLAGS -fstack-protector-all)
# Disable exceptions as DDNet does not use them.
add_c_compiler_flag_if_supported(OUR_FLAGS -fno-exceptions)
# Inaccurate floating point numbers cause problems on mingw-w64-gcc when
# compiling for x86, might cause problems elsewhere. So don't store floats
# in registers but keep them at higher accuracy.
if(TARGET_ARCH STREQUAL "x86")
add_c_compiler_flag_if_supported(OUR_FLAGS -ffloat-store)
endif()
# Don't insert timestamps into PEs to keep the build reproducible.
if(TARGET_OS STREQUAL "windows")
add_c_compiler_flag_if_supported(OUR_FLAGS_LINK -Wl,--no-insert-timestamp)
endif()
if(TARGET_OS STREQUAL "mac")
add_c_compiler_flag_if_supported(OUR_FLAGS -stdlib=libc++)
endif()
add_c_compiler_flag_if_supported(OUR_FLAGS_OWN -Wall)
if(CMAKE_VERSION VERSION_GREATER 3.3 OR CMAKE_VERSION VERSION_EQUAL 3.3)
add_c_compiler_flag_if_supported(OUR_FLAGS_OWN
$<$<COMPILE_LANGUAGE:C>:-Wdeclaration-after-statement>
-Wdeclaration-after-statement
)
endif()
add_c_compiler_flag_if_supported(OUR_FLAGS_OWN -Wextra)
add_c_compiler_flag_if_supported(OUR_FLAGS_OWN -Wno-unused-parameter)
add_c_compiler_flag_if_supported(OUR_FLAGS_OWN -Wno-missing-field-initializers)
add_c_compiler_flag_if_supported(OUR_FLAGS_OWN -Wformat=2) # Warn about format strings.
add_c_compiler_flag_if_supported(OUR_FLAGS_DEP -Wno-implicit-function-declaration)
add_c_compiler_flag_if_supported(OUR_FLAGS_OWN -Wno-nullability-completeness) # Mac OS build on github
add_c_compiler_flag_if_supported(OUR_FLAGS_OWN -Wduplicated-cond)
add_c_compiler_flag_if_supported(OUR_FLAGS_OWN -Wduplicated-branches)
add_c_compiler_flag_if_supported(OUR_FLAGS_OWN -Wlogical-op)
add_c_compiler_flag_if_supported(OUR_FLAGS_OWN -Wrestrict)
add_c_compiler_flag_if_supported(OUR_FLAGS_OWN -Wthread-safety)
# TODO: Enable for C++ code except gtest
#add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN "-Wuseless-cast")
endif()
if(NOT MSVC AND NOT HAIKU)
check_c_compiler_flag("-O2;-Wp,-Werror;-D_FORTIFY_SOURCE=2" DEFINE_FORTIFY_SOURCE) # Some distributions define _FORTIFY_SOURCE by themselves.
endif()
########################################################################
# COMMON FUNCTIONS
########################################################################
function(set_glob VAR GLOBBING EXTS DIRECTORY) # ...
set(GLOBS)
foreach(ext ${EXTS})
list(APPEND GLOBS "${DIRECTORY}/*.${ext}")
endforeach()
file(${GLOBBING} GLOB_RESULT ${GLOBS})
list(SORT GLOB_RESULT)
set(FILES)
foreach(file ${ARGN})
list(APPEND FILES "${PROJECT_SOURCE_DIR}/${DIRECTORY}/${file}")
endforeach()
if(NOT FILES STREQUAL GLOB_RESULT)
message(AUTHOR_WARNING "${VAR} does not contain every file from directory ${DIRECTORY}")
set(LIST_BUT_NOT_GLOB)
if(POLICY CMP0057)
cmake_policy(SET CMP0057 NEW)
foreach(file ${FILES})
if(NOT file IN_LIST GLOB_RESULT)
list(APPEND LIST_BUT_NOT_GLOB ${file})
endif()
endforeach()
if(LIST_BUT_NOT_GLOB)
message(AUTHOR_WARNING "Entries only present in ${VAR}: ${LIST_BUT_NOT_GLOB}")
endif()
set(GLOB_BUT_NOT_LIST)
foreach(file ${GLOB_RESULT})
if(NOT file IN_LIST FILES)
list(APPEND GLOB_BUT_NOT_LIST ${file})
endif()
endforeach()
if(GLOB_BUT_NOT_LIST)
message(AUTHOR_WARNING "Entries only present in ${DIRECTORY}: ${GLOB_BUT_NOT_LIST}")
endif()
if(NOT LIST_BUT_NOT_GLOB AND NOT GLOB_BUT_NOT_LIST)
message(AUTHOR_WARNING "${VAR} is not alphabetically sorted")
endif()
endif()
endif()
set(${VAR} ${FILES} PARENT_SCOPE)
endfunction()
function(set_src VAR GLOBBING DIRECTORY) # ...
set_glob(${VAR} ${GLOBBING} "c;cpp;h" ${DIRECTORY} ${ARGN})
set(${VAR} ${${VAR}} PARENT_SCOPE)
endfunction()
function(set_own_rpath TARGET)
if(NOT TARGET_OS STREQUAL "windows" AND NOT TARGET_OS STREQUAL "mac")
if(CMAKE_VERSION VERSION_GREATER 3.8 OR CMAKE_VERSION VERSION_EQUAL 3.8)
set_property(TARGET ${TARGET} PROPERTY BUILD_RPATH "$ORIGIN")
endif()
set_property(TARGET ${TARGET} PROPERTY INSTALL_RPATH "$ORIGIN/../lib/ddnet")
endif()
endfunction()
if(NOT TARGET_OS STREQUAL "windows" AND NOT TARGET_OS STREQUAL "mac" AND CMAKE_VERSION VERSION_LESS 3.8)
if(ANTIBOT)
message(STATUS "Can't set BUILD_RPATH in CMake before 3.8, pass -Wl,-rpath,'$ORIGIN' manually if you wish to emulate this. Or just install a newer version of CMake...")
endif()
endif()
########################################################################
# INITIALIZE TARGET LISTS
########################################################################
set(TARGETS_OWN)
set(TARGETS_DEP)
set(TARGETS_LINK) # Targets with a linking stage.
########################################################################
# DEPENDENCIES
########################################################################
function(set_extra_dirs_lib VARIABLE NAME)
set("PATHS_${VARIABLE}_LIBDIR" PARENT_SCOPE)
set("HINTS_${VARIABLE}_LIBDIR" PARENT_SCOPE)
if(PREFER_BUNDLED_LIBS)
set(TYPE HINTS)
else()
set(TYPE PATHS)
endif()
if(TARGET_BITS AND TARGET_OS)
set(DIR "libs/${NAME}/${TARGET_OS}/lib${TARGET_BITS}")
set("${TYPE}_${VARIABLE}_LIBDIR" "${DIR}" PARENT_SCOPE)
set("EXTRA_${VARIABLE}_LIBDIR" "${DIR}" PARENT_SCOPE)
endif()
endfunction()
function(set_extra_dirs_include VARIABLE NAME LIBRARY)
set("PATHS_${VARIABLE}_INCLUDEDIR" PARENT_SCOPE)
set("HINTS_${VARIABLE}_INCLUDEDIR" PARENT_SCOPE)
is_bundled(IS_BUNDLED "${LIBRARY}")
if(IS_BUNDLED)
set("HINTS_${VARIABLE}_INCLUDEDIR" "libs/${NAME}/include" "libs/${NAME}/include/${TARGET_OS}" PARENT_SCOPE)
endif()
endfunction()
if(CMAKE_CROSSCOMPILING)
set(CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH NO_CMAKE_SYSTEM_PATH)
else()
set(CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH)
endif()
function(is_bundled VARIABLE PATH)
if(PATH)
string(FIND "${PATH}" "${PROJECT_SOURCE_DIR}" LOCAL_PATH_POS)
if(LOCAL_PATH_POS EQUAL 0 AND TARGET_BITS AND TARGET_OS)
set("${VARIABLE}" ON PARENT_SCOPE)
else()
set("${VARIABLE}" OFF PARENT_SCOPE)
endif()
else()
set("${VARIABLE}" OFF PARENT_SCOPE)
endif()
endfunction()
if(NOT CMAKE_CROSSCOMPILING)
# Check for PkgConfig once so all the other `find_package` calls can do it
# quietly.
find_package(PkgConfig)
endif()
find_package(ZLIB)
find_package(Crypto)
find_package(Curl)
if(DOWNLOAD_GTEST)
find_package(Git)
endif()
find_package(GTest)
if(UPNP)
find_package(Miniupnpc)
endif()
if(MYSQL)
find_package(MySQL)
else()
set(MYSQL_LIBRARIES)
endif()
find_package(Pnglite)
find_package(PythonInterp 3)
find_package(SQLite3)
if(UNIX)
# Use -pthread instead of -lpthread to draw dependencies other than libpthread
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
endif()
find_package(Threads)
if(WEBSOCKETS)
find_package(Websockets)
else()
set(WEBSOCKETS_LIBRARIES)
set(WEBSOCKETS_INCLUDE_DIRS)
endif()
if(TARGET_OS AND TARGET_OS STREQUAL "mac")
find_program(CMAKE_OTOOL otool)
find_program(DMG dmg)
find_program(HFSPLUS hfsplus)
find_program(NEWFS_HFS newfs_hfs)
if(DMG AND HFSPLUS AND NEWFS_HFS)
set(DMGTOOLS_FOUND ON)
else()
set(DMGTOOLS_FOUND OFF)
endif()
find_program(HDIUTIL hdiutil)
if(HDIUTIL)
set(HDIUTIL_FOUND ON)
else()
set(HDIUTIL_FOUND OFF)
endif()
endif()
message(STATUS "******** DDNet ********")
if(NOT TARGET_OS STREQUAL "mac")
message(STATUS "Target OS: ${TARGET_OS} ${TARGET_BITS}bit")
else()
message(STATUS "Target OS: ${TARGET_OS} ${TARGET_BITS}bit (SDK: ${CMAKE_OSX_SYSROOT})")
endif()
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Dependencies:")
function(show_dependency_status OUTPUT_NAME NAME)
if(${NAME}_FOUND)
if(${NAME}_BUNDLED)
message(STATUS " * ${OUTPUT_NAME} not found (using bundled version)")
else()
message(STATUS " * ${OUTPUT_NAME} found")
endif()
else()
message(STATUS " * ${OUTPUT_NAME} not found")
endif()
endfunction()
show_dependency_status("Curl" CURL)
if(TARGET_OS AND TARGET_OS STREQUAL "mac")
show_dependency_status("Dmg tools" DMGTOOLS)
endif()
if(DOWNLOAD_GTEST)
show_dependency_status("Git" GIT)
endif()
show_dependency_status("GTest" GTEST)
if(TARGET_OS AND TARGET_OS STREQUAL "mac")
show_dependency_status("Hdiutil" HDIUTIL)
endif()
if(UPNP)
show_dependency_status("Miniupnpc" MINIUPNPC)
endif()
if(MYSQL)
show_dependency_status("MySQL" MYSQL)
endif()
show_dependency_status("OpenSSL Crypto" CRYPTO)
show_dependency_status("Pnglite" PNGLITE)
show_dependency_status("PythonInterp" PYTHONINTERP)
show_dependency_status("SQLite3" SQLite3)
show_dependency_status("Zlib" ZLIB)
if(WEBSOCKETS)
show_dependency_status("Websockets" WEBSOCKETS)
endif()
if(NOT(PYTHONINTERP_FOUND))
message(SEND_ERROR "You must install Python to compile DDNet")
endif()
if(NOT(SQLite3_FOUND))
message(SEND_ERROR "You must install SQLite3 to compile DDNet")
endif()
if(MYSQL AND NOT(MYSQL_FOUND))
message(SEND_ERROR "You must install MySQL to compile the DDNet server with MySQL support")
endif()
if(WEBSOCKETS AND NOT(WEBSOCKETS_FOUND))
message(SEND_ERROR "You must install libwebsockets to compile the DDNet server with websocket support")
endif()
if(UPNP AND NOT(MINIUPNPC_FOUND))
message(SEND_ERROR "You must install miniupnpc to compile the DDNet server with UPnP support")
endif()
if(NOT(GTEST_FOUND))
if(DOWNLOAD_GTEST)
if(GIT_FOUND)
message(STATUS "Automatically downloading GTest to be able to run tests")
else()
set(DOWNLOAD_GTEST OFF)
message(WARNING "To automatically download GTest, you have to install Git")
endif()
else()
message(STATUS "To run the tests, you have to install GTest")
endif()
endif()
if(TARGET_OS STREQUAL "windows")
set(PLATFORM_LIBS ws2_32) # Windows sockets
elseif(TARGET_OS STREQUAL "mac")
find_library(SECURITY Security)
set(PLATFORM_LIBS ${CARBON} ${SECURITY})
else()
if(TARGET_OS STREQUAL "linux")
set(PLATFORM_LIBS rt) # clock_gettime for glibc < 2.17
else()
set(PLATFORM_LIBS)
endif()
endif()
########################################################################
# DOWNLOAD GTEST
########################################################################
if(NOT(GTEST_FOUND) AND DOWNLOAD_GTEST)
set(DDNET_GTEST_VERSION release-1.10.0) # 703bd9caab50b139428cea1aaff9974ebee5742e
configure_file(cmake/Download_GTest_CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/googletest-download
)
if(result)
message(WARNING "CMake step for googletest failed: ${result}")
set(DOWNLOAD_GTEST OFF)
else()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/googletest-download
)
if(result)
message(WARNING "Build step for googletest failed: ${result}")
set(DOWNLOAD_GTEST OFF)
else()
file(GLOB_RECURSE DDNET_GTEST_CMAKELISTS ${CMAKE_BINARY_DIR}/googletest-src/CMakeLists.txt)
foreach(file ${DDNET_GTEST_CMAKELISTS})
file(READ ${file} CONTENTS)
string(REPLACE "cmake_minimum_required(VERSION 2.6.4)" "cmake_minimum_required(VERSION 2.8.12...3.19.1)" CONTENTS "${CONTENTS}")
string(REPLACE "cmake_minimum_required(VERSION 2.6.4)" "cmake_minimum_required(VERSION 2.8.12...3.19.1)" CONTENTS "${CONTENTS}")
string(REPLACE "cmake_minimum_required(VERSION 2.8.8)" "cmake_minimum_required(VERSION 2.8.12...3.19.1)" CONTENTS "${CONTENTS}")
file(WRITE ${file} "${CONTENTS}")
endforeach()
# Prevent overriding the parent project's compiler/linker settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Add googletest directly to our build. This defines the gtest target.
add_subdirectory(
${PROJECT_BINARY_DIR}/googletest-src
${PROJECT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL
)
if(MSVC)
foreach(target gtest)
# `/w` disables all warnings. This is needed because `gtest` enables
# `/WX` (equivalent of `-Werror`) for some reason, breaking builds
# when MSVS adds new warnings.
target_compile_options(${target} PRIVATE $<$<NOT:${DBG}>:/MT> $<${DBG}:/MTd> /w)
endforeach()
endif()
set(GTEST_LIBRARIES gtest)
set(GTEST_INCLUDE_DIRS)
if(CMAKE_VERSION VERSION_LESS 2.8.11)
set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include")
endif()
endif()
endif()
endif()
########################################################################
# DEPENDENCY COMPILATION
########################################################################
set_src(DEP_JSON_SRC GLOB src/engine/external/json-parser json.c json.h)
add_library(json EXCLUDE_FROM_ALL OBJECT ${DEP_JSON_SRC})
set_src(DEP_MD5_SRC GLOB src/engine/external/md5 md5.c md5.h)
add_library(md5 EXCLUDE_FROM_ALL OBJECT ${DEP_MD5_SRC})
list(APPEND TARGETS_DEP json md5)
set(DEP_JSON $<TARGET_OBJECTS:json>)
set(DEP_MD5)
if(NOT CRYPTO_FOUND)
set(DEP_MD5 $<TARGET_OBJECTS:md5>)
endif()
########################################################################
# DATA
########################################################################
set(EXPECTED_DATA
censorlist.txt
languages/arabic.txt
languages/belarusian.txt
languages/bosnian.txt
languages/brazilian_portuguese.txt
languages/bulgarian.txt
languages/catalan.txt
languages/chuvash.txt
languages/czech.txt
languages/danish.txt
languages/dutch.txt
languages/finnish.txt
languages/french.txt
languages/german.txt
languages/greek.txt
languages/hungarian.txt
languages/index.txt
languages/italian.txt
languages/japanese.txt
languages/korean.txt
languages/kyrgyz.txt
languages/license.txt
languages/norwegian.txt
languages/persian.txt
languages/polish.txt
languages/portuguese.txt
languages/romanian.txt
languages/russian.txt
languages/serbian.txt
languages/serbian_cyrillic.txt
languages/simplified_chinese.txt
languages/slovak.txt
languages/spanish.txt
languages/swedish.txt
languages/traditional_chinese.txt
languages/turkish.txt
languages/ukrainian.txt
maps/license.txt
maps/mega_std_collection.map
maps/mega_std_collection.map.cfg
maps7/license.txt
maps7/mega_std_collection.map
wordlist.txt
)
set_glob(DATA GLOB_RECURSE "json;map;png;txt;vert;cfg" data ${EXPECTED_DATA})
########################################################################
# COPY DATA AND DLLS
########################################################################
foreach(datafile ${DATA})
file(RELATIVE_PATH OUT ${PROJECT_SOURCE_DIR}/data ${datafile})
get_filename_component(DESTINATION data/${OUT} PATH)
file(MAKE_DIRECTORY ${DESTINATION})
file(COPY ${datafile} DESTINATION ${DESTINATION})
endforeach()
set(COPY_FILES
${CURL_COPY_FILES}
${SQLite3_COPY_FILES}
${WEBSOCKETS_COPY_FILES}
)
file(COPY ${COPY_FILES} DESTINATION .)
########################################################################
# CODE GENERATION
########################################################################
function(generate_source output_file script_parameter)
add_custom_command(OUTPUT ${output_file}
COMMAND ${PYTHON_EXECUTABLE} datasrc/compile.py ${script_parameter}
> "${PROJECT_BINARY_DIR}/${output_file}"
DEPENDS
datasrc/compile.py
datasrc/content.py
datasrc/datatypes.py
datasrc/network.py
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
endfunction()
function(generate_source7 output_file script_parameter)
add_custom_command(OUTPUT ${output_file}
COMMAND ${PYTHON_EXECUTABLE} -m datasrc.seven.compile ${script_parameter}
> "${PROJECT_BINARY_DIR}/${output_file}"
DEPENDS
datasrc/seven/compile.py
datasrc/seven/content.py
datasrc/seven/datatypes.py
datasrc/seven/network.py
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
endfunction()
function(generate_maps output_file)
add_custom_command(OUTPUT ${output_file}
COMMAND ${PYTHON_EXECUTABLE} datasrc/crosscompile.py
> "${PROJECT_BINARY_DIR}/${output_file}"
DEPENDS
datasrc/compile.py
datasrc/content.py
datasrc/datatypes.py
datasrc/network.py
datasrc/seven/compile.py
datasrc/seven/content.py
datasrc/seven/datatypes.py
datasrc/seven/network.py
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
endfunction()
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/src/game/generated/")
execute_process(COMMAND git rev-parse --git-dir
ERROR_QUIET
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE PROJECT_GIT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE PROJECT_GIT_DIR_ERROR
)
if(NOT PROJECT_GIT_DIR_ERROR)
set(GIT_REVISION_EXTRA_DEPS
${PROJECT_GIT_DIR}/index
${PROJECT_GIT_DIR}/logs/HEAD
)
endif()
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src/game/generated/git_revision.cpp
COMMAND ${PYTHON_EXECUTABLE}
scripts/git_revision.py
> ${PROJECT_BINARY_DIR}/src/game/generated/git_revision.cpp
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
DEPENDS
${GIT_REVISION_EXTRA_DEPS}
scripts/git_revision.py
)
generate_source("src/game/generated/protocol.cpp" "network_source")
generate_source("src/game/generated/protocol.h" "network_header")
generate_source("src/game/generated/server_data.cpp" "server_content_source")
generate_source("src/game/generated/server_data.h" "server_content_header")
generate_source7("src/game/generated/protocol7.cpp" "network_source")
generate_source7("src/game/generated/protocol7.h" "network_header")
generate_maps("src/game/generated/protocolglue.h")
add_custom_command(OUTPUT "src/game/generated/wordlist.h"
COMMAND ${PYTHON_EXECUTABLE} scripts/wordlist.py > ${PROJECT_BINARY_DIR}/src/game/generated/wordlist.h
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
DEPENDS
scripts/wordlist.py
)
########################################################################
# SHARED
########################################################################
# Sources
set_src(BASE GLOB_RECURSE src/base
color.h
detect.h
dynamic.h
hash.c
hash.h
hash_bundled.c
hash_ctxt.h
hash_libtomcrypt.c
hash_openssl.c
math.h
system.c
system.h
tl/algorithm.h
tl/allocator.h
tl/array.h
tl/base.h
tl/range.h
tl/sorted_array.h
tl/string.h
tl/threading.h
unicode/confusables.c
unicode/confusables_data.h
unicode/tolower.c
unicode/tolower_data.h
vmath.h
)
set_src(ENGINE_INTERFACE GLOB src/engine
antibot.h
config.h
console.h
demo.h
engine.h
graphics.h
kernel.h
map.h
masterserver.h
message.h
server.h
storage.h
uuid.h
warning.h
)
set_src(ENGINE_SHARED GLOB src/engine/shared
compression.cpp
compression.h
config.cpp
config.h
config_variables.h
console.cpp
console.h
datafile.cpp
datafile.h
demo.cpp
demo.h
econ.cpp
econ.h
engine.cpp
fifo.cpp
fifo.h
filecollection.cpp
filecollection.h
global_uuid_manager.cpp
huffman.cpp
huffman.h
image_manipulation.cpp
image_manipulation.h
jobs.cpp
jobs.h
json.cpp
json.h
kernel.cpp
linereader.cpp
linereader.h
map.cpp
map.h
masterserver.cpp
memheap.cpp
memheap.h
message.h
netban.cpp
netban.h
network.cpp
network.h
network_client.cpp
network_conn.cpp
network_console.cpp
network_console_conn.cpp
network_server.cpp
packer.cpp
packer.h
protocol.h
protocol_ex.cpp
protocol_ex.h
protocol_ex_msgs.h
ringbuffer.cpp
ringbuffer.h
snapshot.cpp
snapshot.h
storage.cpp
uuid_manager.cpp
uuid_manager.h
websockets.cpp
websockets.h
)
set_src(GAME_SHARED GLOB src/game
bezier.cpp
bezier.h
collision.cpp
collision.h
ddracechat.h
ddracecommands.h
extrainfo.cpp
extrainfo.h
gamecore.cpp
gamecore.h
layers.cpp
layers.h
localization.cpp
localization.h
mapitems.cpp
mapitems.h
mapitems_ex.cpp
mapitems_ex.h
mapitems_ex_types.h
prng.cpp
prng.h
teamscore.cpp
teamscore.h
tuning.h
variables.h
version.h
voting.h
)
# A bit hacky, but these are needed to register all the UUIDs, even for stuff
# that doesn't link game.
set(ENGINE_UUID_SHARED
src/game/generated/protocolglue.h
src/game/generated/protocol7.cpp
src/game/generated/protocol7.h
src/game/generated/protocol.cpp
src/game/generated/protocol.h
src/game/mapitems_ex.cpp
src/game/mapitems_ex.h
src/game/mapitems_ex_types.h
)
foreach(s ${GAME_SHARED})
if(s MATCHES "mapitems_(ex.cpp|ex.h|ex_types.h)$")
list(REMOVE_ITEM GAME_SHARED ${s})
endif()
endforeach()
list(REMOVE_ITEM GAME_SHARED ${ENGINE_UUID_SHARED})
set(GAME_GENERATED_SHARED
src/game/generated/git_revision.cpp
src/game/generated/protocol.h
src/game/generated/protocol7.h
src/game/generated/protocolglue.h
)
set(DEPS ${DEP_JSON} ${DEP_MD5} ${ZLIB_DEP})
# Libraries
set(LIBS
${CRYPTO_LIBRARIES}
${WEBSOCKETS_LIBRARIES}
${ZLIB_LIBRARIES}
${PLATFORM_LIBS}
# Add pthreads (on non-Windows) at the end, so that other libraries can depend
# on it.
${CMAKE_THREAD_LIBS_INIT}
)
# Targets
add_library(engine-shared EXCLUDE_FROM_ALL OBJECT ${ENGINE_INTERFACE} ${ENGINE_SHARED} ${ENGINE_UUID_SHARED} ${BASE})
add_library(game-shared EXCLUDE_FROM_ALL OBJECT ${GAME_SHARED} ${GAME_GENERATED_SHARED})
list(APPEND TARGETS_OWN engine-shared game-shared)
########################################################################
# SERVER
########################################################################
# Sources
set_src(ANTIBOT_SRC GLOB src/antibot
antibot_data.h
antibot_interface.h
antibot_null.cpp
)
set_src(ENGINE_SERVER GLOB_RECURSE src/engine/server
antibot.cpp
antibot.h
authmanager.cpp
authmanager.h
databases/connection.cpp
databases/connection.h
databases/connection_pool.cpp
databases/connection_pool.h
databases/mysql.cpp
databases/sqlite.cpp
name_ban.cpp
name_ban.h
register.cpp
register.h
server.cpp
server.h
sql_string_helpers.cpp
sql_string_helpers.h
upnp.cpp
upnp.h
)
set_src(GAME_SERVER GLOB_RECURSE src/game/server
alloc.h
ddracechat.cpp
ddracecommands.cpp
entities/character.cpp
entities/character.h
entities/door.cpp
entities/door.h
entities/dragger.cpp
entities/dragger.h
entities/dumbentity.cpp
entities/dumbentity.h
entities/flag.cpp
entities/flag.h
entities/gun.cpp
entities/gun.h
entities/laser.cpp
entities/laser.h
entities/light.cpp
entities/light.h
entities/pickup.cpp
entities/pickup.h
entities/plasma.cpp
entities/plasma.h
entities/projectile.cpp
entities/projectile.h
entities/textentity.cpp
entities/textentity.h
entity.cpp
entity.h
eventhandler.cpp
eventhandler.h
gamecontext.cpp
gamecontext.h
gamecontroller.cpp
gamecontroller.h
gamemodes.h
gamemodes/catch.cpp
gamemodes/catch.h
gamemodes/ctf.cpp
gamemodes/ctf.h
gamemodes/dm.cpp
gamemodes/dm.h
gamemodes/instagib.cpp
gamemodes/instagib.h
gamemodes/lms.cpp
gamemodes/lms.h
gamemodes/lts.cpp
gamemodes/lts.h
gamemodes/tdm.cpp
gamemodes/tdm.h
gameworld.cpp
gameworld.h
player.cpp
player.h
teams.cpp
teams.h
teeinfo.cpp
teeinfo.h
weapon.cpp
weapon.h
weapons.h
weapons/explodinglaser.cpp
weapons/explodinglaser.h
weapons/grenade.cpp
weapons/grenade.h
weapons/hammer.cpp
weapons/hammer.h