forked from ddnet/ddnet
-
Notifications
You must be signed in to change notification settings - Fork 10
/
CMakeLists.txt
3629 lines (3418 loc) · 108 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.12...3.27.4)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15 CACHE INTERNAL "Minimum macOS deployment version")
if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.15)
message(WARNING "Building for macOS < 10.15 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()
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_PROCESSOR}" MATCHES "arm"
OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "aarch64"
OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "ARM64")
if(TARGET_BITS STREQUAL "32")
set(TARGET_CPU_ARCHITECTURE "arm")
else()
set(TARGET_CPU_ARCHITECTURE "arm64")
endif()
else()
if(TARGET_BITS STREQUAL "32")
set(TARGET_CPU_ARCHITECTURE "x86")
else()
set(TARGET_CPU_ARCHITECTURE "x86_64")
endif()
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(TARGET_OS "windows")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
set(TARGET_OS "linux")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(TARGET_OS "mac")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Haiku")
set(TARGET_OS "haiku")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(TARGET_OS "android")
endif()
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.18)
include(CheckLinkerFlag)
endif()
include(CheckSymbolExists)
if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Emscripten"))
include(CheckAtomic)
endif()
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)
set(AUTO_VULKAN_BACKEND ON)
if(TARGET_OS STREQUAL "windows")
set(AUTO_DEPENDENCIES_DEFAULT ON)
if(TARGET_CPU_ARCHITECTURE STREQUAL "x86")
set(AUTO_VULKAN_BACKEND OFF)
endif()
elseif(TARGET_OS STREQUAL "mac")
set(AUTO_VULKAN_BACKEND OFF)
endif()
option(WEBSOCKETS "Enable websockets support" OFF)
option(MYSQL "Enable mysql support" OFF)
option(TEST_MYSQL "Test mysql support in unit tests (also sets -DMYSQL=ON)" OFF)
option(AUTOUPDATE "Enable the autoupdater" OFF)
option(INFORM_UPDATE "Inform about available updates" ON)
option(VIDEORECORDER "Enable video recording support via FFmpeg" ON)
option(UPNP "Enable UPnP support" OFF)
option(ANTIBOT "Enable support for a dynamic anticheat library (not provided, see src/antibot for interface if you want to implement your own)" OFF)
option(HEADLESS_CLIENT "Build the client without graphics" OFF)
option(CLIENT "Compile client" ON)
option(SERVER "Compile server" ON)
option(TOOLS "Compile tools" ON)
option(DOWNLOAD_GTEST "Download and compile GTest" ${AUTO_DEPENDENCIES_DEFAULT})
option(STEAM "Build the Steam release version" OFF)
option(DISCORD "Enable Discord rich presence support" OFF)
option(DISCORD_DYNAMIC "Enable discovering Discord rich presence libraries at runtime (Linux only)" OFF)
option(PREFER_BUNDLED_LIBS "Prefer bundled libraries over system libraries" ${AUTO_DEPENDENCIES_DEFAULT})
option(DEV "Don't generate stuff necessary for packaging" OFF)
option(VULKAN "Enable the vulkan backend" ${AUTO_VULKAN_BACKEND})
option(EXCEPTION_HANDLING "Enable exception handling (only works with Windows as of now)" OFF)
option(IPO "Enable interprocedural optimizations" OFF)
option(FUSE_LD "Linker to use" OFF)
option(SECURITY_COMPILER_FLAGS "Whether to set security-relevant compiler flags like -D_FORTIFY_SOURCE=2 and -fstack-protector-strong" ON)
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
include(${PROJECT_SOURCE_DIR}/cmake/toolchains/Emscripten.toolchain)
endif()
if(TEST_MYSQL)
set(MYSQL ON)
endif()
# Set version if not explicitly set
if(NOT VERSION)
set(VERSION ${PROJECT_VERSION})
endif()
set(OpenGL_GL_PREFERENCE LEGACY)
# 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(IPO)
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_output)
if(ipo_supported)
message(STATUS "IPO is enabled")
set(ENABLE_IPO TRUE)
else()
message(WARNING "IPO is not supported: ${ipo_output}")
endif()
endif()
if(NOT "${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
# Remove version.h generated by previous build code
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/src/game/version.h)
endif()
set(SERVER_EXECUTABLE DDNet-Server CACHE STRING "Name of the built server executable")
set(CLIENT_EXECUTABLE DDNet CACHE STRING "Name of the build client executable")
########################################################################
# Compiler flags
########################################################################
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()
function(add_cxx_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_cxx_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()
function(add_linker_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}")
if(CMAKE_VERSION VERSION_LESS 3.18)
set(${CONFIG_VARIABLE} OFF)
else()
check_linker_flag(C "${CHECKED_FLAG}" ${CONFIG_VARIABLE})
endif()
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_cxx_compiler_flag_if_supported(OUR_FLAGS -fdiagnostics-color=always)
add_cxx_compiler_flag_if_supported(OUR_FLAGS -fcolor-diagnostics)
endif()
if(NOT MSVC AND NOT HAIKU)
if(NOT TARGET_OS STREQUAL "mac")
if(NOT FUSE_LD STREQUAL OFF)
add_linker_flag_if_supported(OUR_FLAGS_LINK -fuse-ld=${FUSE_LD})
if(FLAG_SUPPORTED_fuse_ld_${FUSE_LD})
message(STATUS "Using ${FUSE_LD} linker")
endif()
else()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR NOT ENABLE_IPO)
# GCC+LTO: pthread_create has failed: Resource temporarily unavailable
add_linker_flag_if_supported(OUR_FLAGS_LINK -fuse-ld=mold)
if(FLAG_SUPPORTED_fuse_ld_mold)
message(STATUS "Using mold linker")
else()
# Does not support GCC+LTO
add_linker_flag_if_supported(OUR_FLAGS_LINK -fuse-ld=lld)
if(FLAG_SUPPORTED_fuse_ld_lld)
message(STATUS "Using lld linker")
else()
add_linker_flag_if_supported(OUR_FLAGS_LINK -fuse-ld=gold)
if(FLAG_SUPPORTED_fuse_ld_gold)
message(STATUS "Using gold linker")
endif()
endif()
endif()
else()
add_linker_flag_if_supported(OUR_FLAGS_LINK -fuse-ld=gold)
if(FLAG_SUPPORTED_fuse_ld_gold)
message(STATUS "Using gold linker")
endif()
endif()
endif()
endif()
if(TARGET_OS STREQUAL "mac")
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -std=gnu++17)
endif()
if(SECURITY_COMPILER_FLAGS)
# Protect the stack pointer.
add_cxx_compiler_flag_if_supported(OUR_FLAGS -fstack-protector-strong)
if(MINGW)
add_linker_flag_if_supported(OUR_FLAGS_LINK -lssp)
endif()
endif()
# Disable exceptions as DDNet does not use them.
add_cxx_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_cxx_compiler_flag_if_supported(OUR_FLAGS -ffloat-store)
endif()
# We assume that char is signed in various places in the code. In particular,
# the Str.StrToInts test will fail when char is not signed and names containing
# special characters will be displayed incorrectly on servers.
add_cxx_compiler_flag_if_supported(OUR_FLAGS -fsigned-char)
# Don't insert timestamps into PEs to keep the build reproducible.
if(TARGET_OS STREQUAL "windows")
add_cxx_compiler_flag_if_supported(OUR_FLAGS_LINK -Wl,--no-insert-timestamp)
endif()
if(TARGET_OS STREQUAL "mac")
add_cxx_compiler_flag_if_supported(OUR_FLAGS -stdlib=libc++)
endif()
if(EXCEPTION_HANDLING)
add_cxx_compiler_flag_if_supported(OUR_FLAGS -DCONF_EXCEPTION_HANDLING)
# use the frame pointer (frame pointer usage is disabled by default in
# some architectures like x86_64 and for some optimization levels; and it
# may be impossible to walk the call stack without it)
add_cxx_compiler_flag_if_supported(OUR_FLAGS -fno-omit-frame-pointer)
endif()
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wall)
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wextra)
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wno-psabi) # parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<CCommandProcessorFragment_Vulkan::SMemoryBlock<1>*, std::vector<CCommandProcessorFragment_Vulkan::SMemoryBlock<1>, std::allocator<CCommandProcessorFragment_Vulkan::SMemoryBlock<1> > > >’ changed in GCC 7.1
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wno-unused-parameter)
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wno-missing-field-initializers)
if(CMAKE_BUILD_TYPE STREQUAL DEBUG)
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wformat=2) # Warn about format strings.
else()
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wno-format) # Don't warn about format strings in release mode since our `str_format` optimization is incompatible with it.
endif()
add_c_compiler_flag_if_supported(OUR_FLAGS_DEP -Wno-implicit-function-declaration)
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wno-nullability-completeness) # Mac OS build on github
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wduplicated-cond)
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wduplicated-branches)
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wlogical-op)
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wrestrict)
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wshadow-all) # clang
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wshadow=global) # gcc
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wthread-safety)
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wthread-safety-negative)
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wsuggest-override)
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wdynamic-class-memaccess) # clang
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wclass-memaccess) # gcc
add_linker_flag_if_supported(OUR_FLAGS_LINK -Wno-alloc-size-larger-than) # save.cpp with LTO
# add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wdouble-promotion) # Many occurrences
# add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wnull-dereference) # Many occurrences
# add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -Wuseless-cast) # TODO: Enable for C++ code except gtest
endif()
if(MSVC)
if(EXCEPTION_HANDLING)
add_cxx_compiler_flag_if_supported(OUR_FLAGS /DCONF_EXCEPTION_HANDLING)
endif()
endif()
if(NOT MSVC AND NOT HAIKU AND SECURITY_COMPILER_FLAGS)
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)
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()
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)
set(CHECKSUM_SRC ${CHECKSUM_SRC} ${${VAR}} PARENT_SCOPE)
endfunction()
set(CHECKSUM_SRC)
function(set_own_rpath TARGET)
if(NOT TARGET_OS STREQUAL "windows" AND NOT TARGET_OS STREQUAL "mac")
set_property(TARGET ${TARGET} PROPERTY BUILD_RPATH "$ORIGIN")
set_property(TARGET ${TARGET} PROPERTY INSTALL_RPATH "$ORIGIN/../lib/ddnet")
endif()
endfunction()
########################################################################
# INITIALIZE TARGET LISTS
########################################################################
set(TARGETS_OWN)
set(TARGETS_DEP)
set(TARGETS_LINK) # Targets with a linking stage.
########################################################################
# DEPENDENCIES
########################################################################
if((CMAKE_OSX_ARCHITECTURES STREQUAL "arm64;x86_64" OR CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64;arm64") AND TARGET_OS STREQUAL "mac")
set(FAT ON)
else()
set(FAT OFF)
endif()
if(FAT)
set(LIB_DIR "${TARGET_OS}/libfat")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
set(LIB_DIR "webasm/libwasm")
elseif(TARGET_CPU_ARCHITECTURE STREQUAL "arm" OR TARGET_CPU_ARCHITECTURE STREQUAL "arm64")
set(LIB_DIR "${TARGET_OS}/lib${TARGET_CPU_ARCHITECTURE}")
else()
set(LIB_DIR "${TARGET_OS}/lib${TARGET_BITS}")
endif()
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 "ddnet-libs/${NAME}/${LIB_DIR}")
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(TMP_TARGET_OS ${TARGET_OS})
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
set(TMP_TARGET_OS webasm)
endif()
set("HINTS_${VARIABLE}_INCLUDEDIR" "ddnet-libs/${NAME}/include" "ddnet-libs/${NAME}/include/${TMP_TARGET_OS}" PARENT_SCOPE)
endif()
endfunction()
if(CMAKE_CROSSCOMPILING)
if(TARGET_OS STREQUAL "android" OR CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
# be more aggressive with android toolchain
set(CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH NO_CMAKE_SYSTEM_PATH NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
else()
set(CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH NO_CMAKE_SYSTEM_PATH)
endif()
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()
if(TARGET_OS STREQUAL "android")
find_package(Android)
endif()
find_package(ZLIB)
find_package(Crypto)
find_package(Curl)
if(CLIENT AND VIDEORECORDER)
find_package(FFMPEG)
endif()
find_package(Freetype)
if(DOWNLOAD_GTEST)
find_package(Git)
endif()
if(NOT(TARGET_OS STREQUAL "android"))
find_package(GLEW)
endif()
find_package(GTest)
if(UPNP)
find_package(Miniupnpc)
endif()
if(MYSQL)
find_package(MySQL)
else()
set(MYSQL_LIBRARIES)
endif()
find_package(Ogg)
find_package(Opus)
find_package(Opusfile)
find_package(PNG)
find_package(Python3)
find_package(Rust)
find_package(SDL2)
find_package(SQLite3)
if(DISCORD)
find_package(DiscordSdk)
endif()
if(UNIX)
# Use -pthread instead of -lpthread to draw dependencies other than libpthread
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
endif()
find_package(Threads)
find_package(Wavpack)
if(WEBSOCKETS)
find_package(Websockets)
else()
set(WEBSOCKETS_LIBRARIES)
set(WEBSOCKETS_INCLUDE_DIRS)
endif()
if(EXCEPTION_HANDLING)
find_package(ExceptionHandling)
endif()
if(SECURITY_COMPILER_FLAGS)
find_package(SSP)
endif()
if(TARGET_OS AND TARGET_OS STREQUAL "mac")
find_program(CMAKE_OTOOL otool)
find_program(DMGBUILD dmgbuild)
endif()
set(VULKAN_SHADER_FILE_LIST "" CACHE STRING "Vulkan shader file list")
set(VULKAN_SHADER_FILE_SHA256 "" CACHE STRING "Vulkan shader file hash")
if(CLIENT AND VULKAN)
find_package(Vulkan)
include(cmake/BuildVulkanShaders.cmake)
else()
set(VULKAN_LIBRARIES)
set(VULKAN_INCLUDE_DIRS)
endif()
message(STATUS "******** ${CMAKE_PROJECT_NAME} ********")
set(TARGET "Target OS: ${TARGET_OS} ${CMAKE_SYSTEM_PROCESSOR}")
if(TARGET_OS STREQUAL "mac")
set(TARGET "${TARGET} (SDK: ${CMAKE_OSX_SYSROOT}, architectures: ${CMAKE_OSX_ARCHITECTURES})")
endif()
message(STATUS ${TARGET})
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER}")
message(STATUS "Rust version: ${RUST_VERSION_STRING}")
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(CLIENT AND VIDEORECORDER)
show_dependency_status("FFmpeg" FFMPEG)
endif()
show_dependency_status("Freetype" FREETYPE)
if(DOWNLOAD_GTEST)
show_dependency_status("Git" GIT)
endif()
show_dependency_status("Glew" GLEW)
show_dependency_status("GTest" GTEST)
if(TARGET_OS AND TARGET_OS STREQUAL "mac")
show_dependency_status("Dmgbuild" DMGBUILD)
endif()
if(UPNP)
show_dependency_status("Miniupnpc" MINIUPNPC)
endif()
if(MYSQL)
show_dependency_status("MySQL" MYSQL)
endif()
show_dependency_status("Ogg" OGG)
show_dependency_status("OpenSSL Crypto" CRYPTO)
show_dependency_status("Opus" OPUS)
show_dependency_status("Opusfile" OPUSFILE)
show_dependency_status("PNG" PNG)
show_dependency_status("Python3" Python3)
show_dependency_status("SDL2" SDL2)
show_dependency_status("SQLite3" SQLite3)
show_dependency_status("Wavpack" WAVPACK)
show_dependency_status("Zlib" ZLIB)
if(DISCORD)
show_dependency_status("DiscordSdk" DiscordSdk)
endif()
if(WEBSOCKETS)
show_dependency_status("Websockets" WEBSOCKETS)
endif()
if(CLIENT AND VULKAN)
show_dependency_status("Vulkan" VULKAN)
endif()
if(NOT(CURL_FOUND))
message(SEND_ERROR "You must install Curl to compile ${CMAKE_PROJECT_NAME}")
endif()
if(NOT(Python3_FOUND))
message(SEND_ERROR "You must install Python to compile ${CMAKE_PROJECT_NAME}")
endif()
if(NOT(RUST_FOUND))
message(SEND_ERROR "You must install Rust and Cargo to compile ${CMAKE_PROJECT_NAME}")
endif()
if(NOT(SQLite3_FOUND))
message(SEND_ERROR "You must install SQLite3 to compile ${CMAKE_PROJECT_NAME}")
endif()
if(MYSQL AND NOT(MYSQL_FOUND))
message(SEND_ERROR "You must install MySQL to compile the ${CMAKE_PROJECT_NAME} server with MySQL support")
endif()
if(WEBSOCKETS AND NOT(WEBSOCKETS_FOUND))
message(SEND_ERROR "You must install libwebsockets to compile the ${CMAKE_PROJECT_NAME} server with websocket support")
endif()
if(UPNP AND NOT(MINIUPNPC_FOUND))
message(SEND_ERROR "You must install miniupnpc to compile the ${CMAKE_PROJECT_NAME} server with UPnP support")
endif()
if(DISCORD AND NOT(DISCORDSDK_FOUND))
message(SEND_ERROR "You must install the Discord SDK to compile the ${CMAKE_PROJECT_NAME} client with Discord support")
endif()
if(DISCORD_DYNAMIC)
if(TARGET_OS STREQUAL "windows" OR TARGET_OS STREQUAL "mac")
message(SEND_ERROR "Dynamically loading the Discord SDK is only supported on Linux")
endif()
if(NOT DISCORD)
message(SEND_ERROR "You must enable the DISCORD flag if you want to link the Discord SDK")
endif()
endif()
if(NOT(PNG_FOUND))
message(SEND_ERROR "You must install libpng to compile ${CMAKE_PROJECT_NAME}")
endif()
if(CLIENT AND NOT(FREETYPE_FOUND))
message(SEND_ERROR "You must install Freetype to compile the ${CMAKE_PROJECT_NAME} client")
endif()
if(CLIENT AND NOT(OGG_FOUND))
message(SEND_ERROR "You must install Ogg to compile the ${CMAKE_PROJECT_NAME} client")
endif()
if(CLIENT AND NOT(OPUS_FOUND))
message(SEND_ERROR "You must install Opus to compile the ${CMAKE_PROJECT_NAME} client")
endif()
if(CLIENT AND NOT(OPUSFILE_FOUND))
message(SEND_ERROR "You must install Opusfile to compile the ${CMAKE_PROJECT_NAME} client")
endif()
if(CLIENT AND NOT(SDL2_FOUND))
message(SEND_ERROR "You must install SDL2 to compile the ${CMAKE_PROJECT_NAME} client")
endif()
if(TARGET_OS STREQUAL "android" AND CLIENT AND NOT(CRYPTO_FOUND))
message(SEND_ERROR "You must install OpenSSL to compile the ${CMAKE_PROJECT_NAME} client")
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(CLIENT AND VULKAN AND NOT(VULKAN_FOUND))
message(SEND_ERROR "You must install Vulkan libraries to compile the ${CMAKE_PROJECT_NAME} client")
endif()
if(TARGET_OS STREQUAL "windows")
set(PLATFORM_CLIENT)
set(PLATFORM_CLIENT_LIBS opengl32 winmm imm32)
set(PLATFORM_LIBS)
list(APPEND PLATFORM_LIBS shlwapi) # PathIsRelativeW
list(APPEND PLATFORM_LIBS version ws2_32) # Windows sockets
list(APPEND PLATFORM_LIBS bcrypt userenv) # for Rust (https://github.com/rust-lang/rust/issues/91974)
list(APPEND PLATFORM_LIBS ole32) # CoInitialize(Ex)
list(APPEND PLATFORM_LIBS shell32)
list(APPEND PLATFORM_LIBS ntdll) # https://github.com/ddnet/ddnet/issues/6725
elseif(TARGET_OS STREQUAL "mac")
find_library(CARBON Carbon)
find_library(COCOA Cocoa)
find_library(OPENGL OpenGL)
find_library(SECURITY Security)
set(PLATFORM_CLIENT
src/macos/client.mm
src/macos/notifications.mm
)
set(PLATFORM_CLIENT_LIBS ${COCOA} ${OPENGL})
set(PLATFORM_LIBS ${CARBON} ${SECURITY})
elseif(TARGET_OS STREQUAL "haiku")
set(PLATFORM_CLIENT)
find_package(OpenGL)
set(PLATFORM_LIBS GL network)
set(PLATFORM_CLIENT_LIBS ${OPENGL_gl_LIBRARY})
set(PLATFORM_CLIENT_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR})
elseif(TARGET_OS STREQUAL "android")
set(PLATFORM_CLIENT
src/android/android_main.cpp
)
set(PLATFORM_LIBS ${TW_ANDROID_LIBS})
set(PLATFORM_CLIENT_LIBS ${PLATFORM_LIBS})
set(PLATFORM_CLIENT_INCLUDE_DIRS)
else()
find_package(Notify)
find_package(OpenGL)
set(PLATFORM_CLIENT_LIBS ${OPENGL_gl_LIBRARY} ${NOTIFY_LIBRARIES})
set(PLATFORM_CLIENT_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR} ${NOTIFY_INCLUDE_DIRS})
set(PLATFORM_CLIENT)
if(TARGET_OS STREQUAL "linux")
set(PLATFORM_LIBS)
list(APPEND PLATFORM_LIBS rt) # clock_gettime for glibc < 2.17
list(APPEND PLATFORM_LIBS dl) # for Rust
else()
set(PLATFORM_LIBS)
endif()
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
set(PLATFORM_CLIENT_LIBS GL)
set(PLATFORM_CLIENT_INCLUDE_DIRS "")
set(CMAKE_EXECUTABLE_SUFFIX ".html")
endif()
########################################################################
# DOWNLOAD GTEST
########################################################################
if(NOT(GTEST_FOUND) AND DOWNLOAD_GTEST)
set(DDNET_GTEST_VERSION 3d73dee972d0db344bda9b659836612aba6a3564)
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()
# 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 gmock)
set_property(TARGET ${target} PROPERTY MSVC_RUNTIME_LIBRARY MultiThreaded$<${DBG}:Debug>)
# `/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 /w)
endforeach()
endif()
set(GTEST_LIBRARIES gtest gmock)
set(GTEST_INCLUDE_DIRS)
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()
########################################################################
# RUST
########################################################################
set_glob(RUST_BASE GLOB_RECURSE "rs;toml" src/base
Cargo.toml
color.rs
lib.rs
rust.rs
)
set_glob(RUST_ENGINE_INTERFACE GLOB "rs;toml" src/engine
Cargo.toml
console.rs
lib.rs
)
set_glob(RUST_ENGINE_SHARED GLOB_RECURSE "rs;toml" src/engine/shared
Cargo.toml
build.rs
config.rs
lib.rs
rust_version.rs
)
set_src(RUST_BRIDGE_SHARED GLOB_RECURSE src/rust-bridge
cpp/console.cpp
cpp/console.h
engine/shared/rust_version.cpp
engine/shared/rust_version.h
)
set_glob(RUST_MASTERSRV GLOB "rs;toml" src/mastersrv/src
addr.rs
locations.rs
main.rs
)
add_library(rust-bridge-shared EXCLUDE_FROM_ALL OBJECT ${RUST_BRIDGE_SHARED})
list(APPEND TARGETS_OWN rust-bridge-shared)
if(TARGET_OS STREQUAL "android")
set(CARGO_BUILD_DIR "${CARGO_NDK_TARGET}/")
set(CARGO_BUILD ${CMAKE_COMMAND} -E env CARGO_TARGET_DIR=${PROJECT_BINARY_DIR} DDNET_TEST_NO_LINK=1 ${RUST_CARGO} ndk --manifest-path "${PROJECT_SOURCE_DIR}/Cargo.toml" -t ${CARGO_NDK_TARGET} -p ${CARGO_NDK_API} build)
set(CARGO_TEST ${CMAKE_COMMAND} -E env CARGO_TARGET_DIR=${PROJECT_BINARY_DIR} ${RUST_CARGO} ndk -t ${CARGO_NDK_TARGET} -p ${CARGO_NDK_API} test)
else()
set(CARGO_BUILD_DIR "")
set(CARGO_BUILD ${CMAKE_COMMAND} -E env CARGO_TARGET_DIR=${PROJECT_BINARY_DIR} DDNET_TEST_NO_LINK=1 ${RUST_CARGO} build --manifest-path "${PROJECT_SOURCE_DIR}/Cargo.toml")
set(CARGO_TEST ${CMAKE_COMMAND} -E env CARGO_TARGET_DIR=${PROJECT_BINARY_DIR} ${RUST_CARGO} test)
endif()
if(MSVC)
list(INSERT CARGO_BUILD 0 ${CMAKE_COMMAND} -E env $<$<CONFIG:Debug>:CFLAGS=/MTd> $<$<CONFIG:Debug>:CXXFLAGS=/MTd>)
list(INSERT CARGO_TEST 0 ${CMAKE_COMMAND} -E env RUSTFLAGS=-Ctarget-feature=+crt-static)
endif()
if(RUST_NIGHTLY)
list(APPEND CARGO_BUILD -Z build-std=std,panic_abort)
endif()
if(NOT CMAKE_OSX_ARCHITECTURES AND (DEFINED CMAKE_RUST_COMPILER_TARGET OR RUST_NIGHTLY))
if(DEFINED CMAKE_RUST_COMPILER_TARGET)
list(APPEND CARGO_TEST --target ${CMAKE_RUST_COMPILER_TARGET})
set(RUST_TARGET ${CMAKE_RUST_COMPILER_TARGET})
else()
set(RUST_TARGET ${RUST_TARGET_HOST})
endif()
list(APPEND CARGO_BUILD --target ${RUST_TARGET})
set(CARGO_BUILD_DIR "${RUST_TARGET}/")
endif()
set(CARGO_BUILD_DIR_DEBUG "${CARGO_BUILD_DIR}debug")
set(CARGO_BUILD_DIR_RELEASE "${CARGO_BUILD_DIR}release")
if(GENERATOR_IS_MULTI_CONFIG)
if(CMAKE_VERSION VERSION_LESS 3.20)
message(SEND_ERROR "Multi-config generators only supported from CMake 3.20 and up")
else()
set(CARGO_BUILD_DIR "${CARGO_BUILD_DIR}$<$<CONFIG:Debug>:debug>$<$<NOT:$<CONFIG:Debug>>:release>")
endif()
else()
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(CARGO_BUILD_DIR "${CARGO_BUILD_DIR_DEBUG}")
else()
set(CARGO_BUILD_DIR "${CARGO_BUILD_DIR_RELEASE}")
endif()
endif()
list(APPEND CARGO_BUILD $<$<NOT:$<CONFIG:Debug>>:--release>)
if(CMAKE_OSX_ARCHITECTURES)
set(RUST_OSX_ARCHITECTURES)
foreach(arch ${CMAKE_OSX_ARCHITECTURES})
if(${arch} STREQUAL arm64)
list(APPEND RUST_OSX_ARCHITECTURES aarch64-apple-darwin)
elseif(${arch} STREQUAL x86_64)
list(APPEND RUST_OSX_ARCHITECTURES x86_64-apple-darwin)
else()
message(SEND_ERROR "CMAKE_OSX_ARCHITECTURES' architecture ${arch} unknown, can't build Rust code (known: arm64, x86_64)")
endif()
endforeach()
endif()
set(RUST_SRC
${RUST_BASE}
${RUST_ENGINE_INTERFACE}
${RUST_ENGINE_SHARED}
Cargo.toml
Cargo.lock
)
set(RUST_TARGETS engine_shared)
if(NOT CMAKE_OSX_ARCHITECTURES)
set(RUST_OUTPUTS)
foreach(rust_target ${RUST_TARGETS})
set(LIBRARY_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}ddnet_${rust_target}${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(rust_${rust_target} STATIC IMPORTED GLOBAL)
add_custom_target(rust_${rust_target}_target DEPENDS "${PROJECT_BINARY_DIR}/${CARGO_BUILD_DIR}/${LIBRARY_NAME}")
add_dependencies(rust_${rust_target} rust_${rust_target}_target)
set_target_properties(rust_${rust_target} PROPERTIES
IMPORTED_LOCATION "${PROJECT_BINARY_DIR}/${CARGO_BUILD_DIR_RELEASE}/${LIBRARY_NAME}"
IMPORTED_LOCATION_DEBUG "${PROJECT_BINARY_DIR}/${CARGO_BUILD_DIR_DEBUG}/${LIBRARY_NAME}"
)
list(APPEND RUST_OUTPUTS "${PROJECT_BINARY_DIR}/${CARGO_BUILD_DIR}/${LIBRARY_NAME}")
endforeach()
add_custom_command(
OUTPUT ${RUST_OUTPUTS}
COMMAND ${CARGO_BUILD}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
USES_TERMINAL
DEPENDS ${RUST_SRC}
)
else()
foreach(rust_target ${RUST_TARGETS})
set(LIBRARY_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}ddnet_${rust_target}${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(rust_${rust_target} STATIC IMPORTED GLOBAL)
set_target_properties(rust_${rust_target} PROPERTIES
IMPORTED_LOCATION "${PROJECT_BINARY_DIR}/${CARGO_BUILD_DIR_RELEASE}/${LIBRARY_NAME}"
IMPORTED_LOCATION_DEBUG "${PROJECT_BINARY_DIR}/${CARGO_BUILD_DIR_DEBUG}/${LIBRARY_NAME}"
)
add_custom_target(rust_${rust_target}_target DEPENDS "${PROJECT_BINARY_DIR}/${CARGO_BUILD_DIR}/${LIBRARY_NAME}")
add_dependencies(rust_${rust_target} rust_${rust_target}_target)
set(ARCH_LIBRARIES)
foreach(arch ${RUST_OSX_ARCHITECTURES})
list(APPEND ARCH_LIBRARIES "${PROJECT_BINARY_DIR}/${arch}/${CARGO_BUILD_DIR}/${LIBRARY_NAME}")
endforeach()
add_custom_command(
OUTPUT "${PROJECT_BINARY_DIR}/${CARGO_BUILD_DIR}/${LIBRARY_NAME}"
COMMAND lipo ${ARCH_LIBRARIES} -create -output "${PROJECT_BINARY_DIR}/${CARGO_BUILD_DIR}/${LIBRARY_NAME}"
DEPENDS ${ARCH_LIBRARIES}
)
endforeach()
foreach(arch ${RUST_OSX_ARCHITECTURES})
set(RUST_OUTPUTS)
foreach(rust_target ${RUST_TARGETS})
set(LIBRARY_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}ddnet_${rust_target}${CMAKE_STATIC_LIBRARY_SUFFIX}")
list(APPEND RUST_OUTPUTS "${PROJECT_BINARY_DIR}/${arch}/${CARGO_BUILD_DIR}/${LIBRARY_NAME}")
endforeach()
add_custom_command(
OUTPUT ${RUST_OUTPUTS}
COMMAND ${CARGO_BUILD} --target=${arch}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
USES_TERMINAL
DEPENDS ${RUST_SRC}
)
endforeach()
endif()
########################################################################
# DATA
########################################################################
set(EXPECTED_DATA
announcement.txt
arrow.png