forked from Wargus/stratagus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1331 lines (1162 loc) · 38.1 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
# _________ __ __
# / _____// |_____________ _/ |______ ____ __ __ ______
# \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
# / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
# /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
# \/ \/ \//_____/ \/
# ______________________ ______________________
# T H E W A R B E G I N S
# Stratagus - A free fantasy real time strategy game engine
#
# CMakeLists.txt
# Copyright (C) 2011-2014 Pali Rohár <pali.rohar@gmail.com>, cybermind <cybermindid@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
cmake_minimum_required(VERSION 3.5)
cmake_policy(VERSION 3.10..3.20.2)
#########################
# Version configuration #
#########################
# Stratagus major version
set(STRATAGUS_MAJOR_VERSION 3)
# Stratagus minor version (maximum 99)
set(STRATAGUS_MINOR_VERSION 3)
# Stratagus patch level (maximum 99)
set(STRATAGUS_PATCH_LEVEL 3)
# Stratagus patch level 2
set(STRATAGUS_PATCH_LEVEL2 0)
#########################
###############################
# Build vendored dependencies #
###############################
# Build lua 5.1
option(BUILD_VENDORED_LUA OFF)
option(BUILD_VENDORED_SDL OFF)
option(BUILD_VENDORED_MEDIA_LIBS OFF)
option(DOWNLOAD_FREEPATS OFF)
###############################
project(stratagus)
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/third-party/CMakeLists.txt")
add_subdirectory(third-party)
else()
message(WARNING "Third-party directory not populated, cannot vendor any dependencies.")
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# useful for clangd LSP server
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(EXISTS ${WIN32_CMAKE_PREFIX_PATH})
list(APPEND CMAKE_PREFIX_PATH "${WIN32_CMAKE_PREFIX_PATH}")
message("Using prefix path ${CMAKE_PREFIX_PATH}")
endif()
# C++ standard
set(CMAKE_CXX_STANDARD 17)
set(STRATAGUS_VERSION "${STRATAGUS_MAJOR_VERSION}.${STRATAGUS_MINOR_VERSION}.${STRATAGUS_PATCH_LEVEL}")
set(STRATAGUS_VERSION_FULL "${STRATAGUS_VERSION}.${STRATAGUS_PATCH_LEVEL2}")
if(${STRATAGUS_PATCH_LEVEL2} GREATER 0)
set(STRATAGUS_VERSION "${STRATAGUS_VERSION_FULL}")
endif()
# Stratagus sources
include_directories(
src/include
src/third_party/
${CMAKE_CURRENT_BINARY_DIR}
)
set(action_SRCS
src/action/action_attack.cpp
src/action/action_board.cpp
src/action/action_build.cpp
src/action/action_built.cpp
src/action/action_defend.cpp
src/action/action_die.cpp
src/action/action_explore.cpp
src/action/action_follow.cpp
src/action/action_move.cpp
src/action/action_patrol.cpp
src/action/action_repair.cpp
src/action/action_research.cpp
src/action/action_resource.cpp
src/action/action_spellcast.cpp
src/action/action_still.cpp
src/action/action_train.cpp
src/action/action_unload.cpp
src/action/action_upgradeto.cpp
src/action/actions.cpp
src/action/command.cpp
)
source_group(action FILES ${action_SRCS})
set(animation_SRCS
src/animation/animation.cpp
src/animation/animation_attack.cpp
src/animation/animation_die.cpp
src/animation/animation_exactframe.cpp
src/animation/animation_frame.cpp
src/animation/animation_goto.cpp
src/animation/animation_ifvar.cpp
src/animation/animation_label.cpp
src/animation/animation_luacallback.cpp
src/animation/animation_move.cpp
src/animation/animation_randomgoto.cpp
src/animation/animation_randomrotate.cpp
src/animation/animation_randomsound.cpp
src/animation/animation_randomwait.cpp
src/animation/animation_rotate.cpp
src/animation/animation_setplayervar.cpp
src/animation/animation_setvar.cpp
src/animation/animation_sound.cpp
src/animation/animation_spawnmissile.cpp
src/animation/animation_spawnunit.cpp
src/animation/animation_unbreakable.cpp
src/animation/animation_wait.cpp
src/animation/animation_wiggle.cpp
)
source_group(animation FILES ${animation_SRCS})
set(ai_SRCS
src/ai/ai_building.cpp
src/ai/ai.cpp
src/ai/ai_force.cpp
src/ai/ai_magic.cpp
src/ai/ai_plan.cpp
src/ai/ai_resource.cpp
src/ai/script_ai.cpp
)
source_group(ai FILES ${ai_SRCS})
set(beos_SRCS
src/beos/beos.cpp
)
source_group(beos FILES ${beos_SRCS})
set(editor_SRCS
src/editor/editloop.cpp
src/editor/editor.cpp
src/editor/edmap.cpp
src/editor/script_editor.cpp
)
source_group(editor FILES ${editor_SRCS})
set(game_SRCS
src/game/game.cpp
src/game/loadgame.cpp
src/game/replay.cpp
src/game/savegame.cpp
src/game/trigger.cpp
)
source_group(game FILES ${game_SRCS})
set(map_SRCS
src/map/fov.cpp
src/map/fow.cpp
src/map/fow_utils.cpp
src/map/map.cpp
src/map/map_draw.cpp
src/map/map_fog.cpp
src/map/map_radar.cpp
src/map/map_wall.cpp
src/map/mapfield.cpp
src/map/minimap.cpp
src/map/script_map.cpp
src/map/script_tileset.cpp
src/map/tileset.cpp
)
source_group(map FILES ${map_SRCS})
set(missile_SRCS
src/missile/missile.cpp
src/missile/missile_cliptotarget.cpp
src/missile/missile_continuous.cpp
src/missile/missile_cycleonce.cpp
src/missile/missile_deathcoil.cpp
src/missile/missile_fire.cpp
src/missile/missile_flameshield.cpp
src/missile/missile_hit.cpp
src/missile/missile_landmine.cpp
src/missile/missile_none.cpp
src/missile/missile_parabolic.cpp
src/missile/missile_pointotpointwithhit.cpp
src/missile/missile_pointtopoint.cpp
src/missile/missile_pointtopointbounce.cpp
src/missile/missile_pointtopointcycleonce.cpp
src/missile/missile_stay.cpp
src/missile/missile_straightfly.cpp
src/missile/missile_tracer.cpp
src/missile/missile_whirlwind.cpp
src/missile/missileconfig.cpp
src/missile/script_missile.cpp
)
source_group(missile FILES ${missile_SRCS})
set(network_SRCS
src/network/commands.cpp
src/network/net_lowlevel.cpp
src/network/net_message.cpp
src/network/netconnect.cpp
src/network/network.cpp
src/network/netsockets.cpp
src/network/online_service.cpp
src/network/mdns_wrapper.cpp
)
source_group(network FILES ${network_SRCS})
set(particle_SRCS
src/particle/graphicanimation.cpp
src/particle/chunkparticle.cpp
src/particle/particlemanager.cpp
src/particle/radialparticle.cpp
src/particle/smokeparticle.cpp
src/particle/staticparticle.cpp
)
source_group(particle FILES ${particle_SRCS})
set(pathfinder_SRCS
src/pathfinder/astar.cpp
src/pathfinder/pathfinder.cpp
src/pathfinder/script_pathfinder.cpp
)
source_group(pathfinder FILES ${pathfinder_SRCS})
set(sound_SRCS
src/sound/music.cpp
src/sound/script_sound.cpp
src/sound/sound.cpp
src/sound/sound_id.cpp
src/sound/sound_server.cpp
src/sound/unitsound.cpp
)
source_group(sound FILES ${sound_SRCS})
set(spell_SRCS
src/spell/script_spell.cpp
src/spell/spell_adjustvariable.cpp
src/spell/spell_adjustvital.cpp
src/spell/spell_areaadjustvital.cpp
src/spell/spell_areabombardment.cpp
src/spell/spell_capture.cpp
src/spell/spell_demolish.cpp
src/spell/spell_luacallback.cpp
src/spell/spell_polymorph.cpp
src/spell/spell_spawnmissile.cpp
src/spell/spell_spawnportal.cpp
src/spell/spell_summon.cpp
src/spell/spell_teleport.cpp
src/spell/spells.cpp
)
source_group(spell FILES ${spell_SRCS})
set(stratagusmain_SRCS
src/stratagus/construct.cpp
src/stratagus/groups.cpp
src/stratagus/iolib.cpp
src/stratagus/luacallback.cpp
src/stratagus/mainloop.cpp
src/stratagus/parameters.cpp
src/stratagus/player.cpp
src/stratagus/script.cpp
src/stratagus/script_player.cpp
src/stratagus/selection.cpp
src/stratagus/stratagus.cpp
src/stratagus/title.cpp
src/stratagus/translate.cpp
src/stratagus/util.cpp
)
source_group(stratagusmain FILES ${stratagus_SRCS})
set(ui_SRCS
src/ui/botpanel.cpp
src/ui/button_checks.cpp
src/ui/contenttype.cpp
src/ui/icons.cpp
src/ui/interface.cpp
src/ui/mainscr.cpp
src/ui/uibuttons_proc.cpp
src/ui/mouse.cpp
src/ui/popup.cpp
src/ui/script_ui.cpp
src/ui/statusline.cpp
src/ui/ui.cpp
src/ui/uitimer.cpp
src/ui/widgets.cpp
)
source_group(ui FILES ${ui_SRCS})
set(unit_SRCS
src/unit/build.cpp
src/unit/depend.cpp
src/unit/script_unit.cpp
src/unit/script_unittype.cpp
src/unit/unit.cpp
src/unit/unit_draw.cpp
src/unit/unit_find.cpp
src/unit/unit_manager.cpp
src/unit/unit_save.cpp
src/unit/unitptr.cpp
src/unit/unittype.cpp
src/unit/upgrade.cpp
)
source_group(unit FILES ${unit_SRCS})
set(video_SRCS
src/video/color.cpp
src/video/cursor.cpp
src/video/font.cpp
src/video/graphic.cpp
src/video/linedraw.cpp
src/video/mng.cpp
src/video/movie.cpp
src/video/png.cpp
src/video/sdl.cpp
src/video/video.cpp
src/video/shaders.cpp
)
source_group(video FILES ${video_SRCS})
set(win32_SRCS
src/win32/SetupConsole_win32.cpp
src/win32/stratagus.rc
)
source_group(win32 FILES ${win32_SRCS})
set(tolua_FILES
src/tolua/ai.pkg
src/tolua/editor.pkg
src/tolua/font.pkg
src/tolua/game.pkg
src/tolua/map.pkg
src/tolua/minimap.pkg
src/tolua/network.pkg
src/tolua/particle.pkg
src/tolua/pathfinder.pkg
src/tolua/player.pkg
src/tolua/sound.pkg
src/tolua/stratagus.pkg
src/tolua/translate.pkg
src/tolua/trigger.pkg
src/tolua/ui.pkg
src/tolua/unit.pkg
src/tolua/unittype.pkg
src/tolua/upgrade.pkg
src/tolua/video.pkg
src/tolua/stratagus.lua
)
source_group(tolua FILES ${tolua_FILES})
set(stratagus_SRCS
${action_SRCS}
${animation_SRCS}
${ai_SRCS}
${editor_SRCS}
${game_SRCS}
${map_SRCS}
${missile_SRCS}
${network_SRCS}
${particle_SRCS}
${pathfinder_SRCS}
${sound_SRCS}
${spell_SRCS}
${stratagusmain_SRCS}
${ui_SRCS}
${unit_SRCS}
${video_SRCS}
${hqx_SRCS}
${xbrz_SRCS}
${CMAKE_CURRENT_BINARY_DIR}/tolua.cpp
)
set(stratagus_action_HDRS
src/include/action/action_attack.h
src/include/action/action_board.h
src/include/action/action_build.h
src/include/action/action_built.h
src/include/action/action_defend.h
src/include/action/action_die.h
src/include/action/action_follow.h
src/include/action/action_move.h
src/include/action/action_patrol.h
src/include/action/action_repair.h
src/include/action/action_research.h
src/include/action/action_resource.h
src/include/action/action_spellcast.h
src/include/action/action_still.h
src/include/action/action_train.h
src/include/action/action_unload.h
src/include/action/action_upgradeto.h
)
set(stratagus_animation_HDRS
src/include/animation/animation_attack.h
src/include/animation/animation_die.h
src/include/animation/animation_exactframe.h
src/include/animation/animation_frame.h
src/include/animation/animation_goto.h
src/include/animation/animation_ifvar.h
src/include/animation/animation_label.h
src/include/animation/animation_luacallback.h
src/include/animation/animation_move.h
src/include/animation/animation_randomgoto.h
src/include/animation/animation_randomrotate.h
src/include/animation/animation_randomsound.h
src/include/animation/animation_randomwait.h
src/include/animation/animation_rotate.h
src/include/animation/animation_setplayervar.h
src/include/animation/animation_setvar.h
src/include/animation/animation_sound.h
src/include/animation/animation_spawnmissile.h
src/include/animation/animation_spawnunit.h
src/include/animation/animation_unbreakable.h
src/include/animation/animation_wait.h
src/include/animation/animation_wiggle.h
)
set(stratagus_spell_HDRS
src/include/spell/spell_adjustvariable.h
src/include/spell/spell_adjustvital.h
src/include/spell/spell_areaadjustvital.h
src/include/spell/spell_areabombardment.h
src/include/spell/spell_capture.h
src/include/spell/spell_demolish.h
src/include/spell/spell_luacallback.h
src/include/spell/spell_polymorph.h
src/include/spell/spell_spawnmissile.h
src/include/spell/spell_spawnportal.h
src/include/spell/spell_summon.h
src/include/spell/spell_teleport.h
)
set(stratagus_generic_HDRS
src/ai/ai_local.h
src/video/intern_video.h
src/video/renderer.h
src/include/actions.h
src/include/ai.h
src/include/animation.h
src/include/color.h
src/include/commands.h
src/include/construct.h
src/include/cursor.h
src/include/depend.h
src/include/editor.h
src/include/online_service.h
src/include/filesystem.h
src/include/font.h
src/include/fov.h
src/include/fow.h
src/include/fow_utils.h
src/include/game.h
src/include/icons.h
src/include/interface.h
src/include/iolib.h
src/include/luacallback.h
src/include/map.h
src/include/mdns_wrapper.h
src/include/menus.h
src/include/minimap.h
src/include/missile.h
src/include/missileconfig.h
src/include/movie.h
src/include/net_lowlevel.h
src/include/net_serialization.h
src/include/net_message.h
src/include/netconnect.h
src/include/network.h
src/include/network/netsockets.h
src/include/parameters.h
src/include/particle.h
src/include/pathfinder.h
src/include/player.h
src/include/replay.h
src/include/results.h
src/include/script.h
src/include/script_sound.h
src/include/sdl2_helper.h
src/include/settings.h
src/include/sound.h
src/include/sound_server.h
src/include/spells.h
src/include/stratagus.h
src/include/tile.h
src/include/tileset.h
src/include/title.h
src/include/translate.h
src/include/trigger.h
src/include/ui/contenttype.h
src/include/ui/popup.h
src/include/ui/statusline.h
src/include/ui/uitimer.h
src/include/ui.h
src/include/unit.h
src/include/unit_find.h
src/include/unit_manager.h
src/include/unitptr.h
src/include/unitsound.h
src/include/unittype.h
src/include/upgrade.h
src/include/upgrade_structs.h
src/include/util.h
src/include/vec2i.h
src/include/version.h
src/include/video.h
src/include/shaders.h
src/include/viewport.h
src/include/wav.h
src/include/widgets.h
src/include/SetupConsole_win32.h
)
set(stratagus_tests_SRCS
tests/main.cpp
tests/stratagus/test_action_built.cpp
tests/stratagus/test_depend.cpp
tests/stratagus/test_luacallback.cpp
tests/stratagus/test_missile_fire.cpp
tests/stratagus/test_trigger.cpp
tests/stratagus/test_util.cpp
tests/network/test_net_lowlevel.cpp
tests/network/test_netconnect.cpp
tests/network/test_network.cpp
tests/network/test_udpsocket.cpp
)
source_group(include FILES ${stratagus_generic_HDRS})
source_group(include\\action FILES ${stratagus_action_HDRS})
source_group(include\\animation FILES ${stratagus_animation_HDRS})
source_group(include\\spell FILES ${stratagus_spell_HDRS})
set(stratagus_HDRS
${stratagus_generic_HDRS}
${stratagus_action_HDRS}
${stratagus_animation_HDRS}
${stratagus_spell_HDRS}
${CMAKE_CURRENT_BINARY_DIR}/version-generated.h
version-generated.h # This line is needed for CMake when generating Doxygen documentation
)
# Configuration types
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Profile" CACHE STRING "" FORCE)
# Additional platform checks
if(UNIX AND CMAKE_SYSTEM_NAME MATCHES BSD)
set(BSD true)
endif()
if(UNIX AND CMAKE_SYSTEM_NAME MATCHES Linux)
set(LINUX true)
endif()
if(WIN32 AND MSVC AND NOT CMAKE_PREFIX_PATH)
# use a default
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../dependencies)
endif()
# Find all libraries
option(ENABLE_STATIC "Compile Stratagus as static executable" OFF)
if(ENABLE_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.a")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
if(APPLE)
list(APPEND CMAKE_PREFIX_PATH /opt/homebrew/)
endif()
include(CheckCXXSourceCompiles)
set(FS_SRC "
#include <filesystem>
namespace fs = std::filesystem;
int main() {
fs::path p = fs::path(\".\");
if (fs::absolute(p).is_absolute()) {
return 0;
} else {
return 1;
}
}
")
check_cxx_source_compiles("${FS_SRC}" HAS_17_FS)
if(NOT HAS_17_FS) # Tr
set(EXPERIMENTAL_FS_SRC "
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
int main() {
fs::path p = fs::path(\".\");
if (fs::absolute(p).is_absolute()) {
return 0;
} else {
return 1;
}
}
")
check_cxx_source_compiles("${EXPERIMENTAL_FS_SRC}" HAS_17_EXPERIMENTAL_FS)
if(NOT HAS_17_EXPERIMENTAL_FS)
set(CMAKE_REQUIRED_LIBRARIES stdc++fs)
check_cxx_source_compiles("${EXPERIMENTAL_FS_SRC}" HAS_EXP_17_FS_WITH_STDC)
if(HAS_EXP_17_FS_WITH_STDC)
set(stratagus_LIBS ${stratagus_LIBS} stdc++fs)
else()
set(CMAKE_REQUIRED_LIBRARIES c++fs)
check_cxx_source_compiles("${EXPERIMENTAL_FS_SRC}" HAS_EXP_17_FS_WITH_CLIB)
if(HAS_EXP_17_FS_WITH_CLIB)
set(stratagus_LIBS ${stratagus_LIBS} c++fs)
else()
message(FATAL_ERROR "I don't know how to compile with C++17 filesystem support on your system")
endif()
endif()
endif()
endif()
if(BUILD_VENDORED_LUA)
vendored_lua()
else()
find_package(Lua51 REQUIRED)
find_package(Tolua++ REQUIRED)
endif()
if(BUILD_VENDORED_MEDIA_LIBS)
vendored_zlib()
vendored_png()
vendored_bzip2()
vendored_mng()
vendored_oggvorbis()
vendored_theora()
else()
find_package(PNG REQUIRED)
find_package(ZLIB REQUIRED)
find_package(BZip2)
find_package(MNG)
find_package(OggVorbis)
find_package(Theora)
endif()
if (BUILD_VENDORED_SDL)
vendored_sdl()
vendored_sdl_mixer()
vendored_sdl_image()
if(DOWNLOAD_FREEPATS)
vendored_freepats()
vendored_unsf()
add_dependencies(SDL2_mixer freepats unsf)
endif()
else()
find_package(SDL2 REQUIRED)
find_package(SDL2_mixer REQUIRED)
find_package(SDL2_image REQUIRED)
endif()
find_package(OpenMP)
if(WIN32)
find_package(MakeNSIS)
endif()
if(ENABLE_DOC)
find_package(Doxygen
REQUIRED dot
OPTIONAL_COMPONENTS mscgen dia)
endif()
find_package(StackTrace)
find_package(Doxygen)
find_package(SelfPackers)
include(CheckTypeSize)
include(CheckFunctionExists)
include(CheckSymbolExists)
vendored_guichan()
# Windows RC compiler definitions
if(WIN32)
enable_language(RC)
include(CMakeDetermineRCCompiler)
if(MINGW)
set(CMAKE_RC_COMPILER_INIT windres)
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
endif()
endif()
# Options for compiling
if(WIN32)
option(ENABLE_STDIO_REDIRECT "Redirect Stratagus console output to files on Windows" ON)
option(ENABLE_NSIS "Create Stratagus Window NSIS Installer" OFF)
endif()
option(ENABLE_TOUCHSCREEN "Use touchscreen input" OFF)
option(EAGER_LOAD "Load all game data at startup, may avoid stutter during gameplay at the cost of memory" OFF)
option(WITH_BZIP2 "Compile Stratagus with BZip2 compression support" ON)
option(WITH_MNG "Compile Stratagus with MNG image library" ON)
option(WITH_OGGVORBIS "Compile Stratagus with OGG/Vorbis sound library" ON)
option(WITH_THEORA "Compile Stratagus with Theroa video library" ON)
option(WITH_STACKTRACE "Compile Stratagus with StackTrace library" ON)
option(WITH_OPENMP "Compile Stratagus with OpenMP for parallel processing" ON)
option(ENABLE_DOC "Generate Stratagus source code documentation with Doxygen" OFF)
option(ENABLE_DEV "Install Stratagus game development headers files" OFF)
option(ENABLE_UPX "Compress Stratagus executable binary with UPX packer" OFF)
option(ENABLE_STRIP "Strip all symbols from executables" OFF)
option(ENABLE_USEGAMEDIR "Place all files created by Stratagus(logs, savegames) in game directory(old behavior), otherwise place everything in user directory(new behavior)" OFF)
option(ENABLE_MULTIBUILD "Compile Stratagus on all CPU cores simltaneously in MSVC" ON)
# Install paths
set(BINDIR "bin" CACHE PATH "Where to install user binaries")
set(SBINDIR "sbin" CACHE PATH "Where to install system binaries")
set(GAMEDIR "games" CACHE PATH "Where to install games binaries")
set(DOCDIR "share/doc/stratagus" CACHE PATH "Sets the doc directory to a non-default location.")
set(MANDIR "share/man/man6" CACHE PATH "Sets the man directory to a non-default location.")
set(PIXMAPSDIR "share/pixmaps" CACHE PATH "Sets the pixmaps directory to a non-default location.")
set(STRATAGUS_HEADERS "include" CACHE PATH "Where to install stratagus headers.")
if(NOT IS_ABSOLUTE "${PIXMAPSDIR}")
set(PIXMAPSDIRABS "${CMAKE_INSTALL_PREFIX}/${PIXMAPSDIR}")
else()
set(PIXMAPSDIRABS "${PIXMAPSDIR}")
endif()
if (WIN32)
set(SDL2_LIBRARY ${SDL2_LIBRARY} ${SDL2main_LIBRARY})
message(${SDL2_LIBRARY})
endif()
# Stratagus definitions
add_definitions(-DUSE_ZLIB -DPIXMAPS=\"${PIXMAPSDIRABS}\")
include_directories(SYSTEM ${LUA_INCLUDE_DIR} ${SDL2_INCLUDE_DIR} ${SDL2_MIXER_INCLUDE_DIRS} ${SDL2_IMAGE_INCLUDE_DIRS} ${TOLUA++_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ${PNG_INCLUDE_DIR})
set(stratagus_LIBS ${stratagus_LIBS} ${LUA_LIBRARIES} ${SDL2_LIBRARY} ${SDL2_MIXER_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${TOLUA++_LIBRARY} ${ZLIB_LIBRARIES} ${PNG_LIBRARY})
if(WIN32 AND NOT ENABLE_STDIO_REDIRECT)
add_definitions(-DNO_STDIO_REDIRECT)
endif()
if(WITH_BZIP2 AND BZIP2_FOUND)
add_definitions(-DUSE_BZ2LIB ${BZIP2_DEFINITIONS})
include_directories(SYSTEM ${BZIP2_INCLUDE_DIR})
set(stratagus_LIBS ${stratagus_LIBS} ${BZIP2_LIBRARIES})
endif()
if(WITH_MNG AND MNG_FOUND)
add_definitions(-DUSE_MNG)
include_directories(SYSTEM ${MNG_INCLUDE_DIR})
add_definitions(${MNG_DEFINITIONS})
set(stratagus_LIBS ${stratagus_LIBS} ${MNG_LIBRARY})
endif()
if(WITH_OGGVORBIS AND OGGVORBIS_FOUND)
add_definitions(-DUSE_VORBIS)
include_directories(SYSTEM ${OGGVORBIS_INCLUDE_DIR})
set(stratagus_LIBS ${stratagus_LIBS} ${OGG_LIBRARY} ${VORBIS_LIBRARY})
endif()
if(WITH_THEORA AND THEORA_FOUND)
add_definitions(-DUSE_THEORA)
include_directories(SYSTEM ${THEORA_INCLUDE_DIR})
set(stratagus_LIBS ${stratagus_LIBS} ${THEORA_LIBRARY})
endif()
if(WITH_STACKTRACE AND STACKTRACE_FOUND)
add_definitions(-DUSE_STACKTRACE ${STACKTRACE_DEFINITIONS})
include_directories(${STACKTRACE_PROJECT_DIR})
set(stratagus_LIBS ${stratagus_LIBS} ${STACKTRACE_LIBRARY})
endif()
# Platform definitions
if(WIN32)
# define winXP SP2 as minimum for everything
add_definitions(-DUSE_WIN32 -DNTDDI_VERSION=0x05010200 -D_WIN32_WINNT=0x0501 -DWINVER=0x0501)
set(stratagus_SRCS ${stratagus_SRCS} ${win32_SRCS})
set(stratagus_LIBS ${stratagus_LIBS} dsound winmm ws2_32 dbghelp)
endif()
if (WIN32 AND MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE=1 -DNOMINMAX)
endif()
if (WIN32 AND MINGW)
set(stratagus_LIBS ${stratagus_LIBS} dxguid)
endif()
if(APPLE)
add_definitions(-DUSE_MAC)
set(SDL2_LIBRARY ${SDL2_LIBRARY} SDL2main)
endif()
if(BSD)
add_definitions(-DUSE_BSD)
endif()
if(LINUX)
add_definitions(-DUSE_LINUX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -ggdb")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -ggdb")
endif()
if(BEOS)
add_definitions(-DUSE_BEOS)
set(stratagus_SRCS ${stratagus_SRCS} ${beos_SRCS})
endif()
if(HAIKU)
set(stratagus_LIBS ${stratagus_LIBS} -lnetwork)
endif()
# Stratagus needs to have char by default signed
# No idea how to tell this to other compilers
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char")
endif()
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsigned-char")
endif()
if(WIN32 AND MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Profile")
find_package(coz-profiler)
if(COZ-PROFILER_FOUND)
add_definitions(-DHAVE_COZ_PROFILER)
include_directories(${COZ_INCLUDE_DIRS})
set(stratagus_LIBS ${stratagus_LIBS} ${COZ_LIBRARIES} -ldl)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg -g -ggdb")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg -g -ggdb")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
endif()
# TODO: Add support for other compilers
check_type_size(errno_t ERRNOT)
check_function_exists("strcpy_s" HAVE_STRCPYS)
check_function_exists("strncpy_s" HAVE_STRNCPYS)
check_function_exists("strnlen" HAVE_STRNLEN)
check_function_exists("getopt" HAVE_GETOPT)
# mingw-w64 does not have strcat_s in any include file, but function symbol in library exists
# so rather check if we have strcat_s in string.h file
check_symbol_exists("strcat_s" "string.h" HAVE_STRCATS)
if(HAVE_ERRNOT)
add_definitions(-DHAVE_ERRNOT)
endif()
if(HAVE_STRCPYS)
add_definitions(-DHAVE_STRCPYS)
endif()
if(HAVE_STRNCPYS)
add_definitions(-DHAVE_STRNCPYS)
endif()
if(HAVE_STRCATS)
add_definitions(-DHAVE_STRCATS)
endif()
if(HAVE_STRNLEN)
add_definitions(-DHAVE_STRNLEN)
endif()
if(HAVE_GETOPT)
add_definitions(-DHAVE_GETOPT)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDEBUG)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
elseif (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -glldb")
endif()
endif()
endif()
if(ENABLE_STRIP)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s")
endif()
# TODO: Add support for other compilers
endif()
if(ENABLE_USEGAMEDIR)
add_definitions(-DUSE_GAME_DIR)
endif()
if(ENABLE_TOUCHSCREEN)
add_definitions(-DUSE_TOUCHSCREEN)
endif()
if(EAGER_LOAD)
# nothing
else()
add_definitions(-DDYNAMIC_LOAD)
endif()
if(ENABLE_MULTIBUILD)
if(WIN32 AND MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
message(STATUS "Added parallel build arguments to CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
endif()
endif()
# Print compile info
message("==================================")
macro(log_package PACKAGE_NAME PACKAGE)
if(NOT WITH_${PACKAGE})
message("${PACKAGE_NAME}: Disabled (Enable by param -DWITH_${PACKAGE}=ON)")
elseif(WITH_${PACKAGE} AND ${PACKAGE}_FOUND)
message("${PACKAGE_NAME}: Found and enabled (Disable by param -DWITH_${PACKAGE}=OFF)")
else()
message("${PACKAGE_NAME}: Not Found")
endif()
endmacro()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message("Debug mode: Yes (Disable by param -DCMAKE_BUILD_TYPE=Release)")
else()
message("Debug mode: No (Enable by param -DCMAKE_BUILD_TYPE=Debug)")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Profile")
message("Profiling mode: Yes (Disable by param -DCMAKE_BUILD_TYPE=Release)")
if(COZ-PROFILER_FOUND)
message("Coz profiler enabled build: Yes")
else()
message("Coz profiler enabled build: No")
endif()
else()
message("Profiling mode: No (Enable by param -DCMAKE_BUILD_TYPE=Profile)")
endif()
if(ENABLE_STRIP)
message("Strip executables: Yes (Disable by param -DENABLE_STRIP=OFF)")
else()
message("Strip executables: No (Enable by param -DENABLE_STRIP=ON)")
endif()
if(ENABLE_STATIC)
message("Static linking: Yes (Disable by param -DENABLE_STATIC=OFF)")
else()
message("Static linking: No (Enable by param -DENABLE_STATIC=ON)")
endif()
if(ENABLE_USEGAMEDIR)
message("Place game files in: game directory (Place in user directory with -DENABLE_USEGAMEDIR=OFF)")
else()
message("Place game files in: user directory (Place in game directory with -DENABLE_USEGAMEDIR=ON)")
endif()
if(ENABLE_MULTIBUILD)
message("Parallel building in MSVC: Yes (Disable by param -DENABLE_MULTIBUILD=OFF)")
else()
message("Parallel building in MSVC: No (Enable by param -DENABLE_MULTIBUILD=ON)")
endif()
if(WIN32 AND MSVC)
message("Platform: Windows (MSVC)")
elseif(WIN32 AND MINGW)
message("Platform: Windows (MinGW)")
elseif(WIN32)
message("Platform: Windows (Other)")
elseif(APPLE)