forked from cerberussnake/comp_hack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
1227 lines (1024 loc) · 48.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
# This file is part of COMP_hack.
#
# Copyright (C) 2010-2020 COMP_hack Team <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
# Option to build the dream (if the folder is there).
OPTION(BUILD_DREAM "Build the dream." ON)
# Our custom cmake modules.
SET(COMP_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
# Include our custom cmake modules.
SET(CMAKE_MODULE_PATH
${COMP_MODULE_PATH}
${CMAKE_SOURCE_DIR}/coveralls-cmake/cmake
)
IF(EXISTS "${CMAKE_SOURCE_DIR}/dream" AND BUILD_DREAM)
SET(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${CMAKE_SOURCE_DIR}/dream/cmake
)
INCLUDE(${CMAKE_SOURCE_DIR}/dream/cmake/init.cmake)
ENDIF(EXISTS "${CMAKE_SOURCE_DIR}/dream" AND BUILD_DREAM)
# Do not build objects while linking to reduce memory usage.
OPTION(LIMIT_LINK_JOBS "Limit number of parallel link jobs." OFF)
SET(MAX_LINK_JOBS "1" CACHE STRING "Maximum number of parallel link jobs.")
IF(LIMIT_LINK_JOBS)
SET_PROPERTY(GLOBAL APPEND PROPERTY JOB_POOLS
link_job_pool=${MAX_LINK_JOBS})
SET(CMAKE_JOB_POOL_LINK link_job_pool)
ENDIF(LIMIT_LINK_JOBS)
#
# START OF VERSION CONSTANTS
#
# Last year the code was changed.
SET(VERSION_YEAR 2019)
# Major release (1 = pixie.)
SET(VERSION_MAJOR 4)
# Minor release (1 = SP1).
SET(VERSION_MINOR 12)
# Patch version (a hotfix).
SET(VERSION_PATCH 2)
# Codename for the version.
SET(VERSION_CODENAME "Wyrd")
#
# END OF VERSION CONSTANTS
#
# Make the code name friendly for the installer filename.
STRING(TOLOWER "${VERSION_CODENAME}" VERSION_CODENAME_C)
STRING(REPLACE " " "-" VERSION_CODENAME_C "${VERSION_CODENAME_C}")
# Use folders to organize the projects and files.
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
# Only show Debug and Release configurations in Visual Studio.
IF(CMAKE_CUSTOM_CONFIGURATION_TYPES)
SET(CMAKE_CONFIGURATION_TYPES "${CMAKE_CUSTOM_CONFIGURATION_TYPES}" CACHE STRING "" FORCE)
ELSEIF(CMAKE_CONFIGURATION_TYPES)
SET(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo" CACHE STRING "" FORCE)
ENDIF()
PROJECT(comp_hack)
# Detect if the host processor is x86 compatible.
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86|X86|amd64|AMD64|x86_64")
SET(X86 TRUE)
ELSE()
SET(X86 FALSE)
ENDIF()
# Print the CMake version for debugging.
MESSAGE("-- CMake version: ${CMAKE_VERSION}")
# Option to build only the updater.
OPTION(UPDATER_ONLY "Build only the updater." OFF)
# Option to build only the channel.
OPTION(CHANNEL_ONLY "Build only the channel." OFF)
# Option to import the channel for install but not to build it.
OPTION(IMPORT_CHANNEL "Import the channel without building." OFF)
# Option to use mbedtls instead of OpenSSL for the main applications.
OPTION(USE_MBED_TLS "Use mbedtls instead of OpenSSL for the main apps." OFF)
# Option to compress and otherwise reduce the size of PDBs.
# See: https://devblogs.microsoft.com/cppblog/shrink-my-program-database-pdb-file/
OPTION(COMPRESS_PDB "Compress the PDB files (Windows builds)." OFF)
# WiX Fails with ICE errors when running CI under a normal user account.
# See: https://stackoverflow.com/questions/1064580/wix-3-0-throws-error-217-while-being-executed-by-continuous-integration
OPTION(WIX_VALIDATION "Enable or disable validation when generating the MSI." ON)
IF(WIN32)
IF(${CMAKE_SIZEOF_VOID_P} EQUAL 4)
SET(CPACK_PACKAGE_FILE_NAME "comp_hack-${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_CODENAME_C}-win32")
ELSE()
SET(CPACK_PACKAGE_FILE_NAME "comp_hack-${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_CODENAME_C}-win64")
ENDIF()
ELSE(WIN32)
SET(CPACK_PACKAGE_FILE_NAME "comp_hack-${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_CODENAME_C}")
ENDIF(WIN32)
SET(CPACK_PACKAGE_NAME "COMP_hack Server (${VERSION_CODENAME})")
SET(CPACK_PACKAGE_VENDOR "COMP_hack Team")
SET(CPACK_PACKAGE_CONTACT "[email protected]")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt")
SET(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
SET(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
SET(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
SET(CPACK_COMPONENTS_ALL runtime lobby world channel tools config webroot datastore docs schema)
SET(CPACK_COMPONENT_RUNTIME_DISPLAY_NAME "C++ Runtime Library")
SET(CPACK_COMPONENT_RUNTIME_DESCRIPTION "Runtime library needed by the software.")
SET(CPACK_COMPONENT_RUNTUME_REQUIRED TRUE)
SET(CPACK_COMPONENT_LOBBY_DISPLAY_NAME "Lobby Server")
SET(CPACK_COMPONENT_LOBBY_DESCRIPTION "Lobby server to manage characters and login accounts.")
SET(CPACK_COMPONENT_WORLD_DISPLAY_NAME "World Server")
SET(CPACK_COMPONENT_WORLD_DESCRIPTION "World server to manage communication between channels.")
SET(CPACK_COMPONENT_CHANNEL_DISPLAY_NAME "Channel Server")
SET(CPACK_COMPONENT_CHANNEL_DESCRIPTION "Channel server to manage gameplay.")
SET(CPACK_COMPONENT_TOOLS_DISPLAY_NAME "Tools")
SET(CPACK_COMPONENT_TOOLS_DESCRIPTION "Tools for debug, development and content creation.")
SET(CPACK_COMPONENT_CONFIG_DISPLAY_NAME "Example Configuration")
SET(CPACK_COMPONENT_CONFIG_DESCRIPTION "Example configuration files to get up and running.")
SET(CPACK_COMPONENT_WEBROOT_DISPLAY_NAME "API Website Files")
SET(CPACK_COMPONENT_WEBROOT_DESCRIPTION "Website files for the internal API (in the lobby). This includes the example account manager site.")
SET(CPACK_COMPONENT_WEBROOT_DEPENDS lobby)
SET(CPACK_COMPONENT_DATASTORE_DISPLAY_NAME "Server Content")
SET(CPACK_COMPONENT_DATASTORE_DESCRIPTION "Server-side content (datastore) that implements all vanilla content.")
SET(CPACK_COMPONENT_DATASTORE_DEPENDS channel)
SET(CPACK_COMPONENT_DOCS_DISPLAY_NAME "Documentation")
SET(CPACK_COMPONENT_DOCS_DESCRIPTION "Documentation for the server.")
SET(CPACK_COMPONENT_SCHEMA_DISPLAY_NAME "BinaryData XML Schema")
SET(CPACK_COMPONENT_SCHEMA_DESCRIPTION "XML schema files (xsd) to validate BinaryData.")
SET(CPACK_COMPONENT_LOBBY_GROUP servers)
SET(CPACK_COMPONENT_WORLD_GROUP servers)
SET(CPACK_COMPONENT_CHANNEL_GROUP servers)
SET(CPACK_COMPONENT_GROUP_SERVERS_DISPLAY_NAME "Servers Applications")
SET(CPACK_COMPONENT_GROUP_SERVERS_DESCRIPTION "Main server applications.")
SET(CPACK_COMPONENT_GROUP_SERVERS_EXPANDED TRUE)
IF(WIN32)
SET(COMP_INSTALL_DIR "/")
IF(UPDATER_ONLY OR CHANNEL_ONLY)
SET(CPACK_GENERATOR "ZIP")
ELSE()
SET(CPACK_GENERATOR "WIX;ZIP")
ENDIF()
#SET(CPACK_WIX_ROOT "C:\\Program Files (x86)\\WiX Toolset v3.11")
SET(CPACK_WIX_UPGRADE_GUID "A253D8BE-ED6C-43EF-A1C5-F378F269C9E4")
SET(CPACK_WIX_PRODUCT_ICON "${CMAKE_SOURCE_DIR}/tools/bdpatch/res/bdpatch.ico")
SET(CPACK_WIX_UI_BANNER "${CMAKE_SOURCE_DIR}/contrib/wix-banner.png")
SET(CPACK_WIX_UI_DIALOG "${CMAKE_SOURCE_DIR}/contrib/wix-background.png")
SET(CPACK_WIX_PROGRAM_MENU_FOLDER "COMP_hack")
SET(CPACK_WIX_PROPERTY_ARPHELPLINK "https://github.com/comphack/comp_hack")
SET(CPACK_WIX_PATCH_FILE "${CMAKE_SOURCE_DIR}/contrib/services.wxs")
IF(NOT WIX_VALIDATION)
SET(CPACK_WIX_LIGHT_EXTRA_FLAGS "-sval")
ENDIF(NOT WIX_VALIDATION)
SET(CPACK_WIX_EXTENSIONS "WixFirewallExtension")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "COMP_hack")
SET(CPACK_PACKAGE_EXECUTABLES "comp_capgrep;Capture Analysis;comp_logger;Capture Logger;comp_cathedral;Cathedral of Content")
SET(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
IF(NOT CHANNEL_ONLY)
INCLUDE(InstallRequiredSystemLibraries)
INSTALL(
PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
DESTINATION /
COMPONENT runtime
)
FIND_PACKAGE(Qt5Widgets REQUIRED)
IF(Qt5Widgets_FOUND AND WIN32 AND TARGET Qt5::qmake AND NOT TARGET Qt5::windeployqt)
GET_TARGET_PROPERTY(_qt5_qmake_location Qt5::qmake IMPORTED_LOCATION)
EXECUTE_PROCESS(
COMMAND "${_qt5_qmake_location}" -query QT_INSTALL_PREFIX
RESULT_VARIABLE return_code
OUTPUT_VARIABLE qt5_install_prefix
OUTPUT_STRIP_TRAILING_WHITESPACE)
SET(imported_location "${qt5_install_prefix}/bin/windeployqt.exe")
IF(EXISTS ${imported_location})
ADD_EXECUTABLE(Qt5::windeployqt IMPORTED)
SET_TARGET_PROPERTIES(Qt5::windeployqt PROPERTIES
IMPORTED_LOCATION ${imported_location})
ENDIF()
ENDIF()
INSTALL(FILES
"${CMAKE_SOURCE_DIR}/contrib/winconfig/lobby.xml"
"${CMAKE_SOURCE_DIR}/contrib/winconfig/channel.xml"
"${CMAKE_SOURCE_DIR}/contrib/winconfig/world.xml"
"${CMAKE_SOURCE_DIR}/contrib/winconfig/setup.xml"
"${CMAKE_SOURCE_DIR}/contrib/winconfig/newcharacter.xml"
"${CMAKE_SOURCE_DIR}/contrib/testing/config/constants.xml"
DESTINATION config COMPONENT config)
INSTALL(DIRECTORY
"${CMAKE_SOURCE_DIR}/contrib/webroot"
DESTINATION / COMPONENT webroot)
INSTALL(DIRECTORY "${CMAKE_SOURCE_DIR}/datastore/"
DESTINATION datastore COMPONENT datastore
PATTERN ".git*" EXCLUDE)
INSTALL(FILES "${CMAKE_SOURCE_DIR}/contrib/KEEP"
DESTINATION database COMPONENT config)
INSTALL(FILES "${CMAKE_SOURCE_DIR}/contrib/KEEP"
DESTINATION logs COMPONENT config)
SET_PROPERTY(INSTALL config/lobby.xml PROPERTY
CPACK_WIX_ACL "Everyone=GenericAll")
SET_PROPERTY(INSTALL config/channel.xml PROPERTY
CPACK_WIX_ACL "Everyone=GenericAll")
SET_PROPERTY(INSTALL config/world.xml PROPERTY
CPACK_WIX_ACL "Everyone=GenericAll")
SET_PROPERTY(INSTALL config/setup.xml PROPERTY
CPACK_WIX_ACL "Everyone=GenericAll")
SET_PROPERTY(INSTALL config/newcharacter.xml PROPERTY
CPACK_WIX_ACL "Everyone=GenericAll")
SET_PROPERTY(INSTALL config/constants.xml PROPERTY
CPACK_WIX_ACL "Everyone=GenericAll")
SET_PROPERTY(INSTALL database PROPERTY
CPACK_WIX_ACL "Everyone=GenericAll")
SET_PROPERTY(INSTALL logs PROPERTY
CPACK_WIX_ACL "Everyone=GenericAll")
ENDIF(NOT CHANNEL_ONLY)
ELSE()
SET(COMP_INSTALL_DIR "bin")
SET(CPACK_GENERATOR "TGZ;TBZ2;DEB")
ENDIF()
IF(NOT WIN32)
INCLUDE(GNUInstallDirs)
ENDIF(NOT WIN32)
# Enable the CPack module for building installers.
INCLUDE(CPack)
# Utilities to add and remove compiler flags.
INCLUDE(${COMP_MODULE_PATH}/flags.cmake)
# Utilities for building with MSVC.
INCLUDE(${COMP_MODULE_PATH}/msvc.cmake)
# Option to combine packets into one source to build.
OPTION(SINGLE_SOURCE_PACKETS "Combine all packets into one source file." OFF)
# Option to compile all objgen objects into one source file.
OPTION(SINGLE_OBJGEN "Compile all objgen objects into one source file." OFF)
# Use Cotire to generate pre-compiled headers.
OPTION(USE_COTIRE "Use cotire to build with pre-compiled headers." OFF)
IF(USE_COTIRE)
INCLUDE(cotire)
ENDIF(USE_COTIRE)
# Option to disable build warnings/errors.
OPTION(NO_WARNINGS "Disable the compiler warnings and errors." OFF)
# Option to disable all tests.
OPTION(DISABLE_TESTING "Disable all tests." OFF)
# Option for the static runtime on Windows.
OPTION(USE_STATIC_RUNTIME "Use the static MSVC runtime." OFF)
# Option to use pre-built objgen & libcomp.
OPTION(USE_PREBUILT_LIBCOMP "Use pre-built objgen and libcomp" OFF)
IF(WIN32)
OPTION(GENERATE_DOCUMENTATION "Generate documentation for the project." OFF)
ELSE()
OPTION(GENERATE_DOCUMENTATION "Generate documentation for the project." ON)
ENDIF()
# Make sure MSVC uses the right runtime.
IF(USE_STATIC_RUNTIME)
MSVC_RUNTIME(STATIC)
ELSE()
MSVC_RUNTIME(DYNAMIC)
ENDIF()
IF(WIN32)
OPTION(WINDOWS_SERVICE "Build the servers as a Windows service." OFF)
IF(WINDOWS_SERVICE)
ADD_DEFINITIONS(-DWIN32_SERV=1)
ENDIF()
ENDIF()
# http://stackoverflow.com/questions/14933172/
IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# Require at least GCC 4.9.
IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
MESSAGE(FATAL_ERROR "GCC version must be at least 4.9!")
ENDIF()
MESSAGE("-- Using libstdc++")
ADD_COMPILER_FLAGS(AUTO -fno-strict-aliasing)
ELSEIF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
SET(SPECIAL_COMPILER_FLAGS "-stdlib=libc++")
# Require at least Clang 3.4.
IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
MESSAGE(FATAL_ERROR "Clang version must be at least 3.4!")
ENDIF()
MESSAGE("-- Using libc++")
ELSEIF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# There is nothing special needed for MSVC.
ELSE()
MESSAGE(WARNING "You are using an unsupported compiler!")
ENDIF()
INCLUDE(${COMP_MODULE_PATH}/DetermineOS.cmake)
# If code coverage should be generated.
OPTION(COVERALLS "Generate coveralls code coverage data." OFF)
# If code coverage should be uploaded.
OPTION(COVERALLS_UPLOAD "Upload coverage results after collecting them." OFF)
IF(COVERALLS)
INCLUDE(Coveralls)
ENDIF(COVERALLS)
# If the build should be optimized.
OPTION(BUILD_OPTIMIZED "Build an optimized release of the server." ON)
IF(BUILD_OPTIMIZED)
SET(BUILD_VALGRIND_FRIENDLY OFF)
ELSE()
SET(BUILD_VALGRIND_FRIENDLY ON)
ENDIF()
OPTION(BUILD_BINARIES32 "Build with 32-bit binaries." OFF)
# Include all build code for external projects.
IF(EXISTS "${CMAKE_SOURCE_DIR}/binaries")
MESSAGE("-- Using pre-built binaries")
SET(USE_EXTERNAL_BINARIES TRUE)
SET(BINARIES_PATH "${CMAKE_SOURCE_DIR}/binaries")
ELSEIF(EXISTS "${CMAKE_SOURCE_DIR}/binaries32" AND BUILD_BINARIES32)
MESSAGE("-- Using pre-built binaries (32-bit)")
SET(USE_EXTERNAL_BINARIES TRUE)
SET(BINARIES_PATH "${CMAKE_SOURCE_DIR}/binaries32")
ELSEIF(EXISTS "${CMAKE_SOURCE_DIR}/binaries64")
MESSAGE("-- Using pre-built binaries (64-bit)")
SET(USE_EXTERNAL_BINARIES TRUE)
SET(BINARIES_PATH "${CMAKE_SOURCE_DIR}/binaries64")
ELSE()
MESSAGE("-- Building external binaries")
SET(USE_EXTERNAL_BINARIES FALSE)
ENDIF()
INCLUDE(${COMP_MODULE_PATH}/external.cmake)
IF(EXISTS "${CMAKE_SOURCE_DIR}/dream" AND BUILD_DREAM)
INCLUDE(${CMAKE_SOURCE_DIR}/dream/cmake/external.cmake)
ENDIF(EXISTS "${CMAKE_SOURCE_DIR}/dream" AND BUILD_DREAM)
# PDB not found for library.
ADD_LINKER_FLAGS(AUTO /ignore:4099)
# Shrink the size of PDBs.
IF(COMPRESS_PDB)
ADD_LINKER_FLAGS(AUTO /incremental:no /Gy /Gw /opt:ref /opt:icf /pdbcompress)
ENDIF(COMPRESS_PDB)
# Object file level parallelism for MSVC.
ADD_COMPILER_FLAGS(AUTO /MP)
# UTF-8 source encoding for MSVC.
ADD_COMPILER_FLAGS(AUTO /utf-8 /bigobj)
# Build for Windows 7 and higher.
# See: https://msdn.microsoft.com/en-us/library/6sehtctf.aspx
ADD_COMPILER_FLAGS(WIN32 -DWINVER=0x601 -D_WIN32_WINNT=0x0601)
# Don't use full boost, just asio.
ADD_DEFINITIONS(-DASIO_STANDALONE)
# Include more Sqrat types from libcomp.
ADD_DEFINITIONS(
-DSQRAT_EXTRA_TYPES_INCLUDE=<SqratTypesInclude.h>
-DSQRAT_EXTRA_TYPES_SOURCE=<SqratTypesSource.h>
-DSQRAT_EXTRA_TYPES_NONREF=<SqratTypesNonRef.h>
)
# SQLite3 is included in the source repo.
SET(SQLITE3_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/deps/sqlite3")
# Sqrat is included as a submodule (it's header only).
SET(SQRAT_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/deps/sqrat/include")
SET(SQRAT_DEFINES "-DSCRAT_USE_CXX11_OPTIMIZATIONS=1")
# Enable testing.
IF(NOT DISABLE_TESTING)
INCLUDE(CTest)
ENDIF(NOT DISABLE_TESTING)
# Determine if the system is big or little endian.
INCLUDE(TestBigEndian)
TEST_BIG_ENDIAN(LIBCOMP_ENDIAN)
IF(${LIBCOMP_ENDIAN})
ADD_DEFINITIONS(-DLIBCOMP_BIGENDIAN)
ELSE(${LIBCOMP_ENDIAN})
ADD_DEFINITIONS(-DLIBCOMP_LITTLEENDIAN)
ENDIF(${LIBCOMP_ENDIAN})
# Require C++14 to build the project.
SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)
# Default Linux (gcc/clang) builds to debug and MinGW builds to release.
IF(NOT MSVC)
# Ensure C++14 support is on.
ADD_CXX_FLAGS(AUTO -std=c++14)
IF(NOT ("${SPECIAL_COMPILER_FLAGS}" STREQUAL ""))
ADD_CXX_FLAGS(AUTO "${SPECIAL_COMPILER_FLAGS}")
ENDIF()
# Determine basic gcc/clang/mingw flags for release mode.
IF(BUILD_OPTIMIZED)
IF(X86)
ADD_COMPILER_FLAGS(AUTO -O3 -msse3)
ELSE()
ADD_COMPILER_FLAGS(AUTO -O3)
ENDIF()
ENDIF(BUILD_OPTIMIZED)
# Strip release builds.
ADD_LINKER_FLAGS_RELEASE(AUTO -s)
ENDIF(NOT MSVC)
# Disable MSVC warnings about the secure CRT functions.
ADD_COMPILER_FLAGS(WIN32 -D_CRT_SECURE_NO_WARNINGS)
# Specifies the kind of exception handling with MSVC.
ADD_COMPILER_FLAGS(AUTO /EHsc)
# If we are building in debug mode, define the debug flag.
ADD_COMPILER_FLAGS_DEBUG(AUTO -DCOMP_HACK_DEBUG)
# If we are using gcc/clang/mingw, enable warnings under debug mode.
IF(NO_WARNINGS)
ADD_COMPILER_FLAGS(AUTO -g)
ELSE()
ADD_COMPILER_FLAGS(AUTO -Werror -Wall -Wextra -Wshadow
-Wconversion -Wsign-conversion -g)
ENDIF()
# Ignore the warning about mixed use of override.
ADD_COMPILER_FLAGS(AUTO -Wno-inconsistent-missing-override)
# Warning level 4 and treat warnings as errors (MSVC).
# ADD_COMPILER_FLAGS(AUTO /W4 /WX)
# When using gcc/clang/mingw, make sure everything defined is linked into
# the application or library.
IF(NOT APPLE)
ADD_EXE_LINKER_FLAGS(AUTO -Wl,--no-undefined)
ENDIF(NOT APPLE)
# Ignore warnings about unknown attributes (GSL issue) on macosX.
IF(APPLE)
ADD_COMPILER_FLAGS(AUTO -Wno-unknown-attributes)
ENDIF(APPLE)
# Link to the needed frameworks on macOSX
IF(APPLE)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Foundation")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework IOKit")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework ApplicationServices")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -liconv")
ENDIF(APPLE)
# Code coverage flags.
IF(COVERALLS)
ADD_COMPILER_FLAGS(AUTO -g -O0 -fprofile-arcs -ftest-coverage)
REMOVE_COMPILER_FLAGS(-Os -O2 -O3)
ENDIF(COVERALLS)
# Place all executables in the same directory.
SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/bin")
IF(NOT WIN32 AND NOT BSD AND NOT APPLE AND NOT BUILD_EXOTIC)
FIND_PACKAGE(SYSTEMD QUIET)
IF(SYSTEMD_FOUND)
ADD_COMPILER_FLAGS(AUTO ${SYSTEMD_DEFINITIONS} -DHAVE_SYSTEMD=1)
ENDIF(SYSTEMD_FOUND)
ENDIF(NOT WIN32 AND NOT BSD AND NOT APPLE AND NOT BUILD_EXOTIC)
# Add in the build of libobjgen and comp_objgen.
IF(USE_PREBUILT_LIBCOMP)
# We need this for apps that pull in libcomp.
FIND_PACKAGE(Threads REQUIRED)
IF(SYSTEMD_FOUND)
SET(SYSTEMD_INCLUDES ${SYSTEMD_INCLUDE_DIRS})
ENDIF(SYSTEMD_FOUND)
IF(SYSTEMD_FOUND)
SET(SYSTEMD_LIBS ${SYSTEMD_LIBRARIES})
ENDIF(SYSTEMD_FOUND)
IF(WIN32)
SET(WIN32_LIBS comp shlwapi advapi32 iphlpapi psapi shell32
userenv ws2_32 dbghelp)
ENDIF(WIN32)
ADD_EXECUTABLE(comp_objgen IMPORTED)
IF(WIN32)
SET_TARGET_PROPERTIES(comp_objgen PROPERTIES IMPORTED_LOCATION
"${CMAKE_SOURCE_DIR}/deps/libcomp/comp_objgen.exe")
ELSE()
SET_TARGET_PROPERTIES(comp_objgen PROPERTIES IMPORTED_LOCATION
"${CMAKE_SOURCE_DIR}/deps/libcomp/bin/comp_objgen")
ENDIF(WIN32)
IF(WIN32)
ADD_LIBRARY(objgen STATIC IMPORTED)
SET_TARGET_PROPERTIES(objgen PROPERTIES
IMPORTED_LOCATION_RELEASE "${CMAKE_SOURCE_DIR}/deps/libcomp/lib/${CMAKE_STATIC_LIBRARY_PREFIX}objgen${CMAKE_STATIC_LIBRARY_SUFFIX}"
IMPORTED_LOCATION_RELWITHDEBINFO "${CMAKE_SOURCE_DIR}/deps/libcomp/lib/${CMAKE_STATIC_LIBRARY_PREFIX}objgen${CMAKE_STATIC_LIBRARY_SUFFIX}"
IMPORTED_LOCATION_DEBUG "${CMAKE_SOURCE_DIR}/deps/libcomp/lib/${CMAKE_STATIC_LIBRARY_PREFIX}objgen${CMAKE_STATIC_LIBRARY_SUFFIX}")
ELSE()
ADD_LIBRARY(objgen STATIC IMPORTED)
SET_TARGET_PROPERTIES(objgen PROPERTIES IMPORTED_LOCATION
"${CMAKE_SOURCE_DIR}/deps/libcomp/lib/${CMAKE_STATIC_LIBRARY_PREFIX}objgen${CMAKE_STATIC_LIBRARY_SUFFIX}")
ENDIF()
SET_TARGET_PROPERTIES(objgen PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/deps/libcomp/include;${CMAKE_SOURCE_DIR}/libcomp/libobjgen/src")
IF(WIN32)
ADD_LIBRARY(comp STATIC IMPORTED)
SET_TARGET_PROPERTIES(comp PROPERTIES
IMPORTED_LOCATION_RELEASE "${CMAKE_SOURCE_DIR}/deps/libcomp/lib/${CMAKE_STATIC_LIBRARY_PREFIX}comp${CMAKE_STATIC_LIBRARY_SUFFIX}"
IMPORTED_LOCATION_RELWITHDEBINFO "${CMAKE_SOURCE_DIR}/deps/libcomp/lib/${CMAKE_STATIC_LIBRARY_PREFIX}comp${CMAKE_STATIC_LIBRARY_SUFFIX}"
IMPORTED_LOCATION_DEBUG "${CMAKE_SOURCE_DIR}/deps/libcomp/lib/${CMAKE_STATIC_LIBRARY_PREFIX}comp${CMAKE_STATIC_LIBRARY_SUFFIX}")
ELSE()
ADD_LIBRARY(comp STATIC IMPORTED)
SET_TARGET_PROPERTIES(comp PROPERTIES IMPORTED_LOCATION
"${CMAKE_SOURCE_DIR}/deps/libcomp/lib/${CMAKE_STATIC_LIBRARY_PREFIX}comp${CMAKE_STATIC_LIBRARY_SUFFIX}")
ENDIF()
SET_TARGET_PROPERTIES(comp PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/deps/libcomp/include;${CMAKE_SOURCE_DIR}/libcomp/libcomp/src;${ASIO_INCLUDE_DIRS};${SYSTEMD_INCLUDES};${SQRAT_INCLUDE_DIRS};${OPENSSL_INCLUDE_DIR};${CMAKE_BINARY_DIR}/libconfig;${GSL_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "mariadbclient;${OPENSSL_LIBRARIES};${ZLIB_LIBRARIES};${SYSTEM_LIBRARIES};${CMAKE_THREAD_LIBS_INIT};objgen;sqlite3;squirrel;sqstdlib;ttvfs;ttvfs_zip;tinyxml2;physfs;${SYSTEMD_LIBS};${WIN32_LIBS}"
INTERFACE_COMPILE_DEFINITIONS "SCRAT_USE_CXX11_OPTIMIZATIONS=1")
ENDIF(USE_PREBUILT_LIBCOMP)
# List of common include paths for every project using libobjgen.
SET(LIBOBJGEN_INCLUDES
${GSL_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/libcomp/libobjgen/src
# Needed for PushIgnore.h and PopIgnore.h.
${CMAKE_SOURCE_DIR}/libcomp/libcomp/src
)
# List of common include paths for every project using libcomp.
SET(LIBCOMP_INCLUDES
${OPENSSL_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/libcomp/libcomp/src
${CMAKE_BINARY_DIR}/libcomp/libcomp/objgen
)
SET(CHANNEL_DIR ${CMAKE_SOURCE_DIR}/server/channel)
SET(LIBCOMP_DIR ${CMAKE_SOURCE_DIR}/libcomp/libcomp)
SET(COVERALLS_SRCS "" CACHE INTERNAL "Coverage source files")
# Add sources to the coverage source list.
MACRO(COVERALLS_SOURCES)
FOREACH(it ${ARGN})
IF(IS_ABSOLUTE "${it}")
FILE(RELATIVE_PATH filePath "${CMAKE_SOURCE_DIR}"
"${it}")
SET(COVERALLS_SRCS ${COVERALLS_SRCS} "${filePath}"
CACHE INTERNAL "Coverage source files")
ELSE()
FILE(RELATIVE_PATH filePath "${CMAKE_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/${it}")
SET(COVERALLS_SRCS ${COVERALLS_SRCS} "${filePath}"
CACHE INTERNAL "Coverage source files")
ENDIF()
ENDFOREACH()
ENDMACRO()
MACRO(ADD_QT_DEPS target)
# See: https://stackoverflow.com/questions/41193584/deploy-all-qt-dependencies-when-building
IF(TARGET Qt5::windeployqt)
ADD_CUSTOM_COMMAND(TARGET ${target}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/windeployqt"
COMMAND set PATH=%PATH%$<SEMICOLON>${qt5_install_prefix}/bin
COMMAND Qt5::windeployqt --dir "${CMAKE_CURRENT_BINARY_DIR}/windeployqt" "$<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_NAME:${target}>"
)
INSTALL(
DIRECTORY
"${CMAKE_CURRENT_BINARY_DIR}/windeployqt/"
DESTINATION /
COMPONENT tools
)
ENDIF()
ENDMACRO()
# This macro will create a target to generate the documentation using the
# specified Doxyfile.in file.
MACRO(GENERATE_DOCS_EX doxyfile targetname)
# Make sure we have Doxygen.
FIND_PACKAGE(Doxygen)
# Only do something if we have Doxygen.
If(DOXYGEN_FOUND AND GENERATE_DOCUMENTATION)
# Replace CMake variables in the input Doxyfile.
CONFIGURE_FILE("${doxyfile}" "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" @ONLY)
# Create the target that will run Doxygen. The working directory is
# the build directory so all the documentation ends up in the same
# directory structure.
IF(${targetname} MATCHES "libcomp")
ADD_CUSTOM_TARGET(doc-${targetname} ${DOXYGEN_EXECUTABLE}
"${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" WORKING_DIRECTORY
"${CMAKE_BINARY_DIR}" COMMENT
"Generating ${PROJECT_NAME} API documentation" VERBATIM)
ELSE(${targetname} MATCHES "libcomp")
ADD_CUSTOM_TARGET(doc-${targetname} ${DOXYGEN_EXECUTABLE}
"${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" WORKING_DIRECTORY
"${CMAKE_BINARY_DIR}" DEPENDS doc-libcomp COMMENT
"Generating ${targetname} API documentation" VERBATIM)
ENDIF(${targetname} MATCHES "libcomp")
# Add the target to a list of documentation targets.
GET_PROPERTY(targets GLOBAL PROPERTY DOC_TARGETS)
SET_PROPERTY(GLOBAL PROPERTY DOC_TARGETS
doc-${targetname} ${targets})
ENDIF(DOXYGEN_FOUND AND GENERATE_DOCUMENTATION)
ENDMACRO(GENERATE_DOCS_EX doxyfile)
# This macro will create a target to generate the documentation using the
# specified Doxyfile.in file.
MACRO(GENERATE_DOCS doxyfile)
GENERATE_DOCS_EX("${doxyfile}" ${PROJECT_NAME})
ENDMACRO(GENERATE_DOCS doxyfile)
# When building Windows executables, this macro packs the executable. This
# works by simply passing the same name you passed to ADD_EXECUTABLE to this
# macro. The executable will be packed in place. UPX is not used when using
# Microsoft Visual C++ or if DISABLE_UPX is defined.
MACRO(UPX_WRAP exefile)
IF(WIN32 AND NOT MSVC AND NOT DISABLE_UPX)
# Get the path to the executable.
GET_PROPERTY(exefile_path TARGET ${exefile} PROPERTY LOCATION)
# Add a command to run UPX passing a compression of 9 and the path to
# the target executable.
ADD_CUSTOM_COMMAND(TARGET "${exefile}" POST_BUILD
COMMAND upx -9 "${exefile_path}" 1> nul 2>&1 VERBATIM)
ENDIF(WIN32 AND NOT MSVC AND NOT DISABLE_UPX)
ENDMACRO(UPX_WRAP exefile)
# If we are using mingw and the path to windres is not set, add a default path.
IF(MINGW AND NOT CMAKE_WINDRES_PATH)
SET(CMAKE_WINDRES_PATH windres.exe)
ENDIF(MINGW AND NOT CMAKE_WINDRES_PATH)
# This macro is used to compile Windows resource files for either Microsoft
# Visual C++ or MinGW. Simply pass the name of the output variable followed
# by a list of resource file paths. The output variable will be filled and
# should then be passed as source files to the ADD_EXECUTABLE command.
MACRO(RES_WRAP outfiles)
IF(WIN32)
IF(MINGW) # MinGW
FOREACH(it ${ARGN}) # Process each resource file
# Get the name of the file (without the extension) and the path
# to the file. These are needed for the custom command.
GET_FILENAME_COMPONENT(fn ${it} NAME_WE)
GET_FILENAME_COMPONENT(fp ${it} PATH)
# This command calls windres with the resource file and outputs
# an object file with the _res.o suffix. This object file is then
# linked to the executable (by adding the object file to the output
# variable). The object file depends on the resource file.
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${fn}_res.o
COMMAND ${CMAKE_WINDRES_PATH}
-I${CMAKE_CURRENT_SOURCE_DIR}/${fp}
-i${CMAKE_CURRENT_SOURCE_DIR}/${it}
-o ${CMAKE_CURRENT_BINARY_DIR}/${fn}_res.o
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${it})
# Add the object file to the list of output files that will be
# added to the ADD_EXECUTABLE command (and thus linked to the app).
SET(${outfiles} ${${outfiles}}
${CMAKE_CURRENT_BINARY_DIR}/${fn}_res.o)
ENDFOREACH(it ${ARGN})
ELSE(MINGW) # Microsoft Visual C++
FOREACH(it ${ARGN}) # Process each resource file
# Simply add the resource file to the output variable and let cmake
# handle it for us.
SET(${outfiles} ${${outfiles}}
${CMAKE_CURRENT_SOURCE_DIR}/${it})
ENDFOREACH(it ${ARGN})
ENDIF(MINGW)
ENDIF(WIN32)
ENDMACRO(RES_WRAP outfiles)
# This macro handles Qt translations and embeds them as resources into the
# application under the "/trans" virtual directory. The arguments must start
# with the name of the output variable that will be passed to the
# ADD_EXECUTABLE command to ensure the generated files are compiled and linked
# to the application. All remaining variables are source files containing text
# to be translated and source translation files to be built into the app.
MACRO(SETUP_TRANSLATION outvar)
# Generate a list of translation source files.
SET(ts_files "")
FOREACH(it ${ARGN})
GET_FILENAME_COMPONENT(ex ${it} EXT)
IF(ex MATCHES "ts")
SET(ts_files ${ts_files} ${it})
ENDIF(ex MATCHES "ts")
ENDFOREACH(it ${ARGN})
# If the user has instructed us to generate the translation source files,
# do that; otherwise, add them to be compiled into binary files.
IF(${CREATE_TRANSLATION})
QT4_CREATE_TRANSLATION(qm_out ${ARGN})
ELSE(${CREATE_TRANSLATION})
QT4_ADD_TRANSLATION(qm_out ${ts_files})
ENDIF(${CREATE_TRANSLATION})
# Generate the contents of the translation resource file.
SET(qrc_contents "<!DOCTYPE RCC><RCC version=\"1.0\">")
SET(qrc_contents "${qrc_contents}<qresource prefix=\"/trans\">")
FOREACH(it ${ts_files})
GET_FILENAME_COMPONENT(fn ${it} NAME_WE)
SET(qrc_contents "${qrc_contents}<file>${fn}.qm</file>")
ENDFOREACH(it ${ARGN})
SET(qrc_contents "${qrc_contents}</qresource></RCC>")
# Where to write the translation resource file to.
SET(qrc_path ${CMAKE_CURRENT_BINARY_DIR}/trans.qrc)
# Write the translation resource file.
FILE(WRITE ${qrc_path} "${qrc_contents}")
# Add the translation resource file as a target to be generated.
QT4_ADD_RESOURCES(qrc_src ${qrc_path})
# Set the output variable as the generated resource target.
SET(${outvar} ${qrc_src})
ENDMACRO(SETUP_TRANSLATION outvar)
# This macro takes a list of test names (for google-test, not cucumber), builds
# them, and adds them to the CTest framework. Note that the test file should
# be in the "tests" subdirectory of the project with the test name and a ".cpp"
# extension for this macro to work.
MACRO(CREATE_GTESTS)
SET(EXPECT_TARGET False)
SET(TEST_TARGET "test")
SET(TEST_LIBS "")
SET(HAVE_LIBS False)
# Create a test based on each test name.
FOREACH(test ${ARGN})
IF("${test}" MATCHES "LIBS")
SET(HAVE_LIBS False)
ELSEIF("${test}" MATCHES "SRCS")
SET(HAVE_LIBS True)
ELSEIF("${test}" MATCHES "TARGET")
SET(EXPECT_TARGET True)
ELSEIF(EXPECT_TARGET)
SET(TEST_TARGET ${test})
SET(EXPECT_TARGET False)
ELSEIF(HAVE_LIBS)
# Prefix the test name with "Test".
SET(ttest "Test${test}")
# Generate the test executable.
ADD_EXECUTABLE(${ttest} "tests/${test}.cpp")
# Add this to the project folder.
SET_TARGET_PROPERTIES(${ttest} PROPERTIES FOLDER
"Tests/${PROJECT_NAME}")
# Link the libraries to the test executable.
TARGET_LINK_LIBRARIES(${ttest} gtest ${TEST_LIBS}
${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES})
# Add the test to CTest.
IF("${TEST_TARGET}" STREQUAL "test")
ADD_TEST(NAME ${test} COMMAND
${EXECUTABLE_OUTPUT_PATH}/${ttest}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
ELSE()
ADD_CUSTOM_COMMAND(TARGET ${TEST_TARGET} COMMAND
${EXECUTABLE_OUTPUT_PATH}/${ttest}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS ${ttest})
ENDIF()
ELSE() # Must be a library.
# Add the library to the list.
SET(TEST_LIBS ${TEST_LIBS} ${test})
ENDIF("${test}" MATCHES "LIBS")
ENDFOREACH(test ${ARGN})
ENDMACRO(CREATE_GTESTS)
# This must come first so that objgen is found for the macro bellow. As a
# consequence, none of the tools can define their own structures to be
# generated by objgen. This is not a big deal because for the most part
# these should be defined in libcomp.
IF(NOT UPDATER_ONLY AND NOT BUILD_EXOTIC)
ADD_SUBDIRECTORY(deps)
ENDIF(NOT UPDATER_ONLY AND NOT BUILD_EXOTIC)
IF(NOT CHANNEL_ONLY AND NOT BUILD_EXOTIC)
ADD_SUBDIRECTORY(tools)
ENDIF(NOT CHANNEL_ONLY AND NOT BUILD_EXOTIC)
# This macro generates code using objgen. The arguments must start with the
# name of the output variable that will be passed to the ADD_EXECUTABLE command
# to ensure the generated files are compiled and linked to the application or
# library. The 2nd argument must be the main xml schema file that includes all
# other schema files and structures that code will be generated for. The
# remaining arguments will change depending on the extension (or lack of one).
# Files with the xml extension will be used as dependencies to the master xml
# schema. These are xml schema files that have been declared in an <include>
# element. Files that end in cpp or h are source files that will be generated.
# Only the source files defined will be generated despite what structures may
# be included in the xml schema. Finally, all other arguments are assumed to be
# a search path for other xml schema files that have be listed in an <include>
# element.
MACRO(OBJGEN_XML outfiles xml)
# Get the absolute path to the master xml schema.
GET_FILENAME_COMPONENT(xml_abs ${xml} ABSOLUTE)
# Set the master xml schema as a dependency.
SET(deps ${xml_abs})
IF(SINGLE_OBJGEN)
FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/objgen/ObjectCollection.cpp.in"
"// This file is generated by CMake! DO NOT EDIT!\n")
ENDIF(SINGLE_OBJGEN)
# For each argument after the output variable and master xml schema.
FOREACH(it ${ARGN})
# Get the absolute path and extension to the file or directory.
GET_FILENAME_COMPONENT(fp ${it} ABSOLUTE)
GET_FILENAME_COMPONENT(ex ${it} EXT)
IF(ex MATCHES "xml") # XML schema file
# Add the xml schema file as a dependency.
SET(deps ${deps} "${fp}")
ELSEIF(ex MATCHES "cpp" OR ex MATCHES "h" OR ex MATCHES "xsd") # Source or header or schema file
# Add the source or header file as a generated output that must
# then be compiled.
SET(outs ${outs} "${CMAKE_CURRENT_BINARY_DIR}/objgen/${it}")
# Add the source as a file to include for the single source file.
IF(SINGLE_OBJGEN AND ex MATCHES "cpp")
FILE(APPEND
"${CMAKE_CURRENT_BINARY_DIR}/objgen/ObjectCollection.cpp.in"
"#include \"${it}\"\n")
ENDIF(SINGLE_OBJGEN AND ex MATCHES "cpp")
# Mark the schema file to be installed
IF(ex MATCHES "xsd")
INSTALL(
FILES "${CMAKE_CURRENT_BINARY_DIR}/objgen/${it}"
DESTINATION schema
COMPONENT schema
)
ENDIF(ex MATCHES "xsd")
ELSE() # Everything else is assumed to be a directory
# Add the directory as a search path for other xml schema files.
SET(incs ${incs} "-I" "${fp}")
ENDIF(ex MATCHES "xml")
ENDFOREACH(it ${ARGN})
# Add custom commands for all output source or header files so that they
# depend on all xml schema files listed and are generated when those files
# or the objgen application change.
FOREACH(out ${outs})
ADD_CUSTOM_COMMAND(OUTPUT ${out}
COMMAND comp_objgen ${incs} -o "${out}" "${xml_abs}"
COMMAND cmake -E touch "${out}"
DEPENDS comp_objgen ${deps}
VERBATIM)
ENDFOREACH(out ${outs})
# Set the list of output files to be generated, compiled, and linked.
IF(SINGLE_OBJGEN)
ADD_CUSTOM_COMMAND(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/objgen/ObjectCollection.cpp"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/objgen/ObjectCollection.cpp.in"
"${CMAKE_CURRENT_BINARY_DIR}/objgen/ObjectCollection.cpp"
DEPENDS ${outs} VERBATIM)
SET(${outfiles} ${${outfiles}} "${CMAKE_CURRENT_BINARY_DIR}/objgen/ObjectCollection.cpp")
ELSE(SINGLE_OBJGEN)
SET(${outfiles} ${${outfiles}} ${outs})
ENDIF(SINGLE_OBJGEN)
ENDMACRO(OBJGEN_XML outfiles xml)
# If the dream code exists in the "dream" directory and BUILD_DREAM is set,
# build the dream application as well.
IF(EXISTS "${CMAKE_SOURCE_DIR}/dream" AND BUILD_DREAM AND NOT UPDATER_ONLY AND NOT CHANNEL_ONLY)
ADD_SUBDIRECTORY(dream)
ENDIF(EXISTS "${CMAKE_SOURCE_DIR}/dream" AND BUILD_DREAM AND NOT UPDATER_ONLY AND NOT CHANNEL_ONLY)
# Macro to replace the packet source files with a single source file to build.
MACRO(COMBINE_PACKETS listvar)
FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/Packets.cpp" "")
FOREACH(src IN LISTS ${listvar})
STRING(REGEX REPLACE "^src/(.+)$" "#include \"\\1\"\n" src "${src}")
FILE(APPEND "${CMAKE_CURRENT_BINARY_DIR}/Packets.cpp" "${src}")
ENDFOREACH()
SET(${listvar} "${CMAKE_CURRENT_BINARY_DIR}/Packets.cpp")
ENDMACRO(COMBINE_PACKETS listvar)
# Macro to create rspec tests (web testing with ruby).
MACRO(RSPEC_TESTS)
FOREACH(test ${ARGN})
ADD_TEST(NAME ${test} COMMAND rspec ${test}.rb
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/rspec)
SET_PROPERTY(TEST ${test} PROPERTY ENVIRONMENT
"TESTING_DIR=${CMAKE_BINARY_DIR}")
ENDFOREACH(test ${ARGN})
ENDMACRO(RSPEC_TESTS)
IF(NOT UPDATER_ONLY AND NOT USE_PREBUILT_LIBCOMP)
ADD_SUBDIRECTORY(libcomp)
ENDIF(NOT UPDATER_ONLY AND NOT USE_PREBUILT_LIBCOMP)
IF(USE_PREBUILT_LIBCOMP)
# Write the version information into the Constants.h file.
CONFIGURE_FILE(libcomp/libcomp/src/Constants.h.in
"${CMAKE_BINARY_DIR}/libconfig/Constants.h"
ESCAPE_QUOTES @ONLY NEWLINE_STYLE UNIX)
# Add a target to generate API documentation.
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/api/libcomp)
GENERATE_DOCS_EX(libcomp/libcomp/doc/Doxyfile.in libcomp)
ENDIF(USE_PREBUILT_LIBCOMP)
IF(NOT UPDATER_ONLY AND NOT BUILD_EXOTIC)