forked from arx/ArxLibertatis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
executable file
·1265 lines (1079 loc) · 35.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
project(ArxLibertatis)
if(MSVC)
# CMake 2.8.5 or newer is needed for CMAKE_LIBRARY_ARCHITECTURE support.
cmake_minimum_required(VERSION 2.8.5)
# Change CMAKE_LIBRARY_ARCHITECTURE to ensure the right libs are used
if(CMAKE_CL_64)
set(CMAKE_LIBRARY_ARCHITECTURE "x64")
else()
set(CMAKE_LIBRARY_ARCHITECTURE "x86")
endif()
else()
cmake_minimum_required(VERSION 2.8)
endif()
# Define configuration options
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX 1)
else()
set(MACOSX 0)
endif()
# Components
option(BUILD_TESTS "Build tests" OFF)
option(BUILD_TOOLS "Build tools" ON)
set(def_BUILD_CRASHREPORTER ON)
if(MACOSX)
set(def_BUILD_CRASHREPORTER OFF)
elseif(WIN32 AND NOT MSVC)
set(def_BUILD_CRASHREPORTER OFF)
endif()
option(BUILD_CRASHREPORTER "Build the crash reporter" ${def_BUILD_CRASHREPORTER})
option(BUILD_EDITOR "Build editor" OFF)
option(BUILD_EDIT_LOADSAVE "Build save/load functions only used by the editor" ON)
option(INSTALL_SCRIPTS "Install the data install script" ON)
# Optional dependencies
option(USE_OPENAL "Build the OpenAL audio backend" ON)
option(USE_OPENGL "Build the OpenGL renderer backend" ON)
option(USE_SDL "Build the SDL windowing backend" ON)
option(USE_NATIVE_FS "Use the native filesystem backend directly instead of boost" ON)
option(USE_QT5 "Use Qt 5 if available" ON)
option(USE_QT4 "Use Qt 4 if available" ON)
# OpenPandora
option(PANDORA "Set to ON if targeting an OpenPandora device" ${PANDORA})
option(GLES "Set to ON to build GLES renderer instead of OpenGL" ${GLES})
# Build types
option(UNITY_BUILD "Unity build" OFF)
option(DEBUG_EXTRA "Expensive debug options" OFF)
option(SET_WARNING_FLAGS "Adjust compiler warning flags" ON)
option(SET_OPTIMIZATION_FLAGS "Adjust compiler optimization flags" ON)
option(USE_CXX11 "Try to use C++11 if available" ON)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(IS_DEBUG_BUILD ON)
else()
set(IS_DEBUG_BUILD OFF)
endif()
option(DEBUG "Enable debug output and runtime checks" ${IS_DEBUG_BUILD})
if(DEBUG)
add_definitions(-DARX_DEBUG=1)
endif()
# Static libs
set(default_USE_STATIC_LIBS OFF)
if(WIN32)
set(default_USE_STATIC_LIBS ON)
endif()
option(USE_STATIC_LIBS "Statically link libraries" ${default_USE_STATIC_LIBS})
option(GLEW_USE_STATIC_LIBS "Statically link GLEW" ${USE_STATIC_LIBS})
option(Boost_USE_STATIC_LIBS "Statically link Boost" ${USE_STATIC_LIBS})
# Make optional dependencies required
option(STRICT_USE "Abort if there are missing optional dependencies" OFF)
if(STRICT_USE)
set(OPTIONAL_DEPENDENCY REQUIRED)
else()
set(OPTIONAL_DEPENDENCY)
endif()
# Install destinations
if(CMAKE_VERSION VERSION_LESS 2.8.5)
set(CMAKE_INSTALL_DATAROOTDIR "share" CACHE
STRING "read-only architecture-independent data root (share) (relative to prefix).")
set(CMAKE_INSTALL_BINDIR "bin" CACHE
STRING "user executables (bin) (relative to prefix).")
set(CMAKE_INSTALL_LIBEXECDIR "libexec" CACHE
STRING "program executables (libexec) (relative to prefix).")
set(CMAKE_INSTALL_MANDIR "${CMAKE_INSTALL_DATAROOTDIR}/man" CACHE
STRING "man documentation (DATAROOTDIR/man) (relative to prefix).")
foreach(dir BINDIR LIBEXECDIR DATAROOTDIR MANDIR)
if(NOT IS_ABSOLUTE ${CMAKE_INSTALL_${dir}})
set(CMAKE_INSTALL_FULL_${dir} "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_${dir}}")
else()
set(CMAKE_INSTALL_FULL_${dir} "${CMAKE_INSTALL_${dir}}")
endif()
endforeach()
mark_as_advanced(
CMAKE_INSTALL_DATAROOTDIR
CMAKE_INSTALL_BINDIR
CMAKE_INSTALL_LIBEXECDIR
CMAKE_INSTALL_MANDIR
)
else()
include(GNUInstallDirs)
endif()
set(ICONDIR "${CMAKE_INSTALL_DATAROOTDIR}/pixmaps" CACHE
STRING "Install location for icons (relative to prefix).")
set(APPDIR "${CMAKE_INSTALL_DATAROOTDIR}/applications" CACHE
STRING "Install location for .desktop files (relative to prefix).")
set(GAMESBINDIR "${CMAKE_INSTALL_BINDIR}" CACHE
STRING "Install location for game executables (relative to prefix).")
set(SCRIPTDIR "${CMAKE_INSTALL_BINDIR}" CACHE
STRING "Where to install the data install script (relative to prefix).")
mark_as_advanced(
ICONDIR
APPDIR
GAMESBINDIR
SCRIPTDIR
)
# Default runtime user and data directories
if(WIN32)
set(USER_DIR "Arx Libertatis" CACHE STRING "User dir names")
set(USER_DIR_PREFIXES "%FOLDERID_SavedGames%" CACHE STRING "User dir paths")
elseif(MACOSX)
set(DATA_DIR "ArxLibertatis" CACHE STRING "Data dir names")
set(DATA_DIR_PREFIXES "/Applications" CACHE STRING "Data dir paths")
set(USER_DIR "ArxLibertatis" CACHE STRING "User dir names")
set(USER_DIR_PREFIXES "~/Library/Application Support" CACHE STRING "User dir paths")
else()
set(DATA_DIR
"games/arx:arx"
CACHE STRING "Data dir names"
)
set(DATA_DIR_PREFIXES
"\${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}:/opt"
CACHE STRING "Data dir paths"
)
set(USER_DIR
"arx"
CACHE STRING "User dir names"
)
set(USER_DIR_PREFIXES
"\${XDG_DATA_HOME:-$HOME/.local/share}"
CACHE STRING "User dir paths"
)
set(CONFIG_DIR
"arx"
CACHE STRING "Config dir names"
)
set(CONFIG_DIR_PREFIXES
"\${XDG_CONFIG_HOME:-$HOME/.config}"
CACHE STRING "Config dir paths"
)
set(IGNORE_EXE_DIR
"/usr/bin:/usr/games:/usr/games/bin:/usr/local/bin:/usr/local/games:/usr/local/games/bin"
CACHE STRING "Executable locations that should not be used as a data dir"
)
endif()
mark_as_advanced(
DATA_DIR
DATA_DIR_PREFIXES
USER_DIR
USER_DIR_PREFIXES
CONFIG_DIR
CONFIG_DIR_PREFIXES
IGNORE_EXE_DIR
)
# Helper scrips
include(CheckCXXSourceCompiles)
include(CheckSymbolExists)
include(CheckTypeSize)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") # For custom cmake modules
include(BuildSystem)
include(BuildType)
include(CompileCheck)
include(CreateSourceGroups)
include(PrintConfiguration)
include(StyleCheck)
include(VersionString)
# Find required libraries
set(ARX_LIBRARIES)
set(BASE_LIBRARIES)
# Force re-checking libraries if the compiler or compiler flags change
if((NOT LAST_CMAKE_CXX_FLAGS STREQUAL CMAKE_CXX_FLAGS)
OR (NOT LAST_CMAKE_CXX_COMPILER STREQUAL CMAKE_CXX_COMPILER))
force_recheck_library(ZLIB)
force_recheck_library(Freetype)
force_recheck_library(Threads)
force_recheck_library(OpenAL)
force_recheck_library(OpenGL)
force_recheck_library(GLEW)
force_recheck_library(Boost)
force_recheck_library(QtCore QT_QTCORE)
force_recheck_library(QtGui QT_QTGUI)
force_recheck_library(QtNetwork QT_QTNETWORK)
unset(Boost_INCLUDE_DIR CACHE)
set(LAST_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE INTERNAL
"The last C++ compiler flags")
set(LAST_CMAKE_CXX_COMPILER "${CMAKE_CXX_COMPILER}" CACHE INTERNAL
"The last C++ compiler")
endif()
# Win32 API
if(WIN32)
# Ensure we aren't using functionalities not found under Window XP SP1
add_definitions(-D_WIN32_WINNT=0x0502)
if(NOT MSVC)
# We need to define WINVER for MinGW when requiring anything newer than Win95/WinNT
add_definitions(-DWINVER=0x0500) # Require at least Windows 2000
add_definitions(-D_WIN32_IE=0x0500) # Required for "SHGFP_TYPE_CURRENT"
endif()
add_definitions(-DNOMINMAX)
add_definitions(-DWIN32_LEAN_AND_MEAN)
list(APPEND ARX_LIBRARIES gdi32 shell32 comdlg32 ole32 comctl32)
set(ARX_HAVE_WINAPI 1)
else()
set(ARX_HAVE_WINAPI 0)
endif()
# pthread / Win32 threads
set(CMAKE_THREAD_PREFER_PTHREAD 1)
find_package(Threads REQUIRED)
if(NOT MSVC AND CMAKE_THREAD_LIBS_INIT)
check_link_library(Threads CMAKE_THREAD_LIBS_INIT)
endif()
list(APPEND ARX_LIBARIES ${CMAKE_THREAD_LIBS_INIT})
# FreeType
find_package(Freetype REQUIRED)
if(NOT MSVC)
check_link_library(Freetype FREETYPE_LIBRARIES)
endif()
include_directories(SYSTEM ${FREETYPE_INCLUDE_DIRS})
list(APPEND ARX_LIBRARIES ${FREETYPE_LIBRARIES})
# zlib
find_package(ZLIB REQUIRED)
if(MSVC)
add_definitions(-DZLIB_WINAPI)
else()
check_link_library(ZLIB ZLIB_LIBRARIES)
endif()
include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
list(APPEND ARX_LIBRARIES ${ZLIB_LIBRARIES})
# OpenGL
if(USE_OPENGL)
if(GLES)
else()
find_package(OpenGL ${OPTIONAL_DEPENDENCY})
find_package(GLEW ${OPTIONAL_DEPENDENCY})
if(NOT MSVC AND OPENGL_FOUND AND GLEW_FOUND)
check_link_library(OpenGL OPENGL_gl_LIBRARY)
check_link_library(GLEW GLEW_LIBRARIES)
endif()
endif()
endif()
# OpenAL
if(USE_OPENAL)
find_package(OpenAL 1.1 ${OPTIONAL_DEPENDENCY})
find_package(OpenALEFX)
if(NOT MSVC AND OPENAL_FOUND)
check_link_library(OpenAL OPENAL_LIBRARY)
endif()
endif()
# SDL
if(USE_SDL)
if(NOT MACOSX)
# Required to avoid linking with SDLmain except for OS X where it is necessary
# due to the need to have NSApplication correctly setup by SDLmain.
set(SDL_BUILDING_LIBRARY 1)
endif()
find_package(SDL 1.2 ${OPTIONAL_DEPENDENCY})
if(SDL_FOUND)
if(NOT MSVC)
check_link_library(SDL SDL_LIBRARY)
endif()
endif(SDL_FOUND)
endif()
# Boost
find_package(Boost 1.39 REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
# Qt and DbgHelp
set(ARX_HAVE_CRASHREPORTER 0)
if(BUILD_CRASHREPORTER)
# Try to find Qt 5 modules
if(NOT HAVE_QT AND USE_QT5)
if(USE_QT4)
# Missing Qt5*Config.cmake files are not errors, reuduce log spam
set(Qt_OPTIONAL_DEPENDENCY QUIET)
else()
set(Qt_OPTIONAL_DEPENDENCY ${OPTIONAL_DEPENDENCY})
endif()
find_package(Qt5Core ${Qt_OPTIONAL_DEPENDENCY})
find_package(Qt5Gui ${Qt_OPTIONAL_DEPENDENCY})
find_package(Qt5Widgets ${Qt_OPTIONAL_DEPENDENCY})
find_package(Qt5Network ${Qt_OPTIONAL_DEPENDENCY})
if(Qt5Core_FOUND AND Qt5Gui_FOUND AND Qt5Widgets_FOUND AND Qt5Network_FOUND)
message(STATUS "Using Qt 5")
set(HAVE_QT5 1)
set(HAVE_QT 1)
endif()
endif()
# Otherwise, look for Qt 4
if(NOT HAVE_QT AND USE_QT4)
find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork ${OPTIONAL_DEPENDENCY})
if(QT_FOUND)
if(NOT MSVC)
check_link_library(QtCore QT_QTCORE_LIBRARY_RELEASE QT_QTCORE)
check_link_library(QtGui QT_QTGUI_LIBRARY_RELEASE QT_QTGUI)
check_link_library(QtNetwork QT_QTNETWORK_LIBRARY_RELEASE QT_QTNETWORK)
endif()
message(STATUS "Using Qt 4")
set(HAVE_QT4 1)
set(HAVE_QT 1)
endif()
endif()
# Needed by the crash reporter
if(HAVE_QT)
if(MSVC)
find_package(DbgHelp ${OPTIONAL_DEPENDENCY})
if(DBGHELP_FOUND)
set(ARX_HAVE_CRASHREPORTER 1)
endif()
else()
set(ARX_HAVE_CRASHREPORTER 1)
endif()
endif()
if(ARX_HAVE_CRASHREPORTER)
if(HAVE_QT5)
set(ARX_HAVE_CRASHREPORTER_QT5 1)
elseif(HAVE_QT4)
set(ARX_HAVE_CRASHREPORTER_QT4 1)
endif()
endif()
endif()
find_package(Doxygen)
find_package(PythonInterp)
# Check for optional functionality and system configuration
if(NOT MSVC)
if(USE_STATIC_LIBS)
add_ldflag("-static-libstdc++")
if(WIN32)
add_ldflag("-static-libgcc")
endif()
endif()
if(${Boost_VERSION} LESS 104800)
# Older Boost versions don't work with C++11
elseif(USE_CXX11)
add_cxxflag("-std=c++11")
if(WIN32)
add_definitions(-U__STRICT_ANSI__) # __argc and __argv
endif()
endif()
# Don't expose internal symbols to the outside world by default
add_cxxflag("-fvisibility=hidden")
add_cxxflag("-fvisibility-inlines-hidden")
# Define _POSIX_C_SOURCE and _XOPEN_SOURCE for GNU systems
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "GNU"
OR ${CMAKE_SYSTEM_NAME} MATCHES "kFreeBSD")
set(CMAKE_REQUIRED_DEFINITIONS "-D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=600")
add_definitions(-D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=600)
if(${CMAKE_SYSTEM_NAME} MATCHES "kFreeBSD")
set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_BSD_SOURCE")
add_definitions(-D_BSD_SOURCE)
endif()
endif()
# Not a symbol, so we can't use check_symbol_exists
check_compile(ARX_HAVE_BUILTIN_TRAP
"${CMAKE_MODULE_PATH}/check_compiler_builtin_trap.cpp"
"__builtin_trap" "compiler feature"
)
check_compile(ARX_HAVE_ATTRIBUTE_FORMAT_PRINTF
"${CMAKE_MODULE_PATH}/check_compiler_attribute_format_printf.cpp"
"__attribute__((format(printf, i, j)))" "compiler feature"
)
check_symbol_exists(nanosleep "time.h" ARX_HAVE_NANOSLEEP)
set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
check_symbol_exists(pthread_setname_np "pthread.h" ARX_HAVE_PTHREAD_SETNAME_NP)
if(NOT ARX_HAVE_PTHREAD_SETNAME_NP)
check_symbol_exists(pthread_set_name_np "pthread_np.h" ARX_HAVE_PTHREAD_SET_NAME_NP)
endif()
check_symbol_exists(prctl "sys/prctl.h" ARX_HAVE_PRCTL)
unset(CMAKE_REQUIRED_LIBRARIES)
check_symbol_exists(uname "sys/utsname.h" ARX_HAVE_UNAME)
check_symbol_exists(getrusage "sys/resource.h" ARX_HAVE_GETRUSAGE)
check_symbol_exists(popen "stdio.h" ARX_HAVE_POPEN)
check_symbol_exists(pclose "stdio.h" ARX_HAVE_PCLOSE)
check_symbol_exists(getexecname "stdlib.h" ARX_HAVE_GETEXECNAME)
check_symbol_exists(setenv "stdlib.h" ARX_HAVE_SETENV)
find_library(LIBRT_LIBRARY rt)
if(LIBRT_LIBRARY)
set(CMAKE_REQUIRED_LIBRARIES "${LIBRT_LIBRARY}")
endif()
check_symbol_exists(clock_gettime "time.h" ARX_HAVE_CLOCK_GETTIME)
if(LIBRT_LIBRARY)
unset(CMAKE_REQUIRED_LIBRARIES)
endif()
if(NOT ARX_HAVE_CLOCK_GETTIME AND NOT ARX_HAVE_WINAPI)
check_include_files("mach/clock.h;mach/clock_types.h;mach/mach_host.h"
ARX_HAVE_MACH_CLOCK)
endif()
check_include_file("wordexp.h" ARX_HAVE_WORDEXP_H)
check_symbol_exists(fork "unistd.h" ARX_HAVE_FORK)
check_symbol_exists(readlink "unistd.h" ARX_HAVE_READLINK)
check_symbol_exists(dup2 "unistd.h" ARX_HAVE_DUP2)
check_symbol_exists(execl "unistd.h" ARX_HAVE_EXECL)
check_symbol_exists(execlp "unistd.h" ARX_HAVE_EXECLP)
if(NOT WIN32)
check_symbol_exists(isatty "unistd.h" ARX_HAVE_ISATTY)
endif()
check_symbol_exists(sched_getscheduler "sched.h" ARX_HAVE_SCHED_GETSCHEDULER)
check_symbol_exists(kill "signal.h" ARX_HAVE_KILL)
check_symbol_exists(backtrace "execinfo.h" ARX_HAVE_BACKTRACE)
check_include_file("sys/types.h" ARX_HAVE_SYS_TYPES_H)
check_symbol_exists(getpid "unistd.h" ARX_HAVE_GETPID)
if(CMAKE_USE_PTHREADS_INIT AND ARX_HAVE_SYS_TYPES_H AND ARX_HAVE_GETPID)
set(ARX_HAVE_PTHREADS 1)
endif()
check_symbol_exists(sysconf "unistd.h" ARX_HAVE_SYSCONF)
check_symbol_exists(sigaction "signal.h" ARX_HAVE_SIGACTION)
check_symbol_exists(sysctl "sys/sysctl.h" ARX_HAVE_SYSCTL)
if(USE_NATIVE_FS)
check_include_file("sys/stat.h" ARX_HAVE_SYS_STAT_H)
check_include_file("sys/errno.h" ARX_HAVE_SYS_ERRNO_H)
check_include_file("dirent.h" ARX_HAVE_DIRENT_H)
check_symbol_exists(readdir_r "dirent.h" ARX_HAVE_READDIR_R)
check_symbol_exists(getcwd "unistd.h" ARX_HAVE_GETCWD)
check_symbol_exists(fpathconf "unistd.h" ARX_HAVE_FPATHCONF)
check_symbol_exists(pathconf "unistd.h" ARX_HAVE_PATHCONF)
check_symbol_exists(_PC_NAME_MAX "unistd.h" ARX_HAVE_PC_NAME_MAX)
check_symbol_exists(_PC_CASE_SENSITIVE "unistd.h" ARX_HAVE_PC_CASE_SENSITIVE)
check_symbol_exists(dirfd "dirent.h" ARX_HAVE_DIRFD)
check_symbol_exists(fstatat "sys/stat.h" ARX_HAVE_FSTATAT)
check_symbol_exists(NAME_MAX "dirent.h" ARX_HAVE_NAME_MAX)
if(ARX_HAVE_SYS_STAT_H AND ARX_HAVE_SYS_ERRNO_H AND ARX_HAVE_DIRENT_H
AND ARX_HAVE_READDIR_R AND ARX_HAVE_GETCWD
AND ((((ARX_HAVE_DIRFD AND ARX_HAVE_FPATHCONF) OR ARX_HAVE_PATHCONF)
AND ARX_HAVE_PC_NAME_MAX) OR ARX_HAVE_NAME_MAX))
set(ARX_HAVE_POSIX_FILESYSTEM 1)
elseif(STRICT_USE)
message(FATAL_ERROR "Missing dependencies for native filesystem backend.")
endif()
endif(USE_NATIVE_FS)
endif(NOT MSVC)
# Sources
set(SRC_DIR src)
set(AI_SOURCES
src/ai/PathFinder.cpp
src/ai/PathFinderManager.cpp
src/ai/Paths.cpp
)
set(ANIMATION_SOURCES
src/animation/Animation.cpp
src/animation/AnimationRender.cpp
src/animation/Cinematic.cpp
src/animation/CinematicKeyframer.cpp
src/animation/Intro.cpp
)
set(AUDIO_SOURCES
src/audio/Ambiance.cpp
src/audio/Audio.cpp
src/audio/AudioEnvironment.cpp
src/audio/AudioGlobal.cpp
src/audio/AudioResource.cpp
src/audio/AudioSource.cpp
src/audio/Mixer.cpp
src/audio/Sample.cpp
src/audio/Stream.cpp
src/audio/codec/ADPCM.cpp
src/audio/codec/RAW.cpp
src/audio/codec/WAV.cpp
)
set(AUDIO_OPENAL_SOURCES
src/audio/openal/OpenALBackend.cpp
src/audio/openal/OpenALSource.cpp
src/audio/openal/OpenALUtils.cpp
)
set(CORE_SOURCES
src/core/Application.cpp
src/core/ArxGame.cpp
src/core/Config.cpp
src/core/Core.cpp
src/core/GameTime.cpp
src/core/Localisation.cpp
src/core/SaveGame.cpp
src/core/Startup.cpp
src/util/cmdline/Parser.cpp # TODO: move to UTIL_SOURCES once it's used in the tools
)
set(GAME_SOURCES
src/game/Camera.cpp
src/game/Damage.cpp
src/game/Entity.cpp
src/game/EntityId.cpp
src/game/EntityManager.cpp
src/game/Equipment.cpp
src/game/Inventory.cpp
src/game/Item.cpp
src/game/Levels.cpp
src/game/Map.cpp
src/game/Missile.cpp
src/game/NPC.cpp
src/game/Player.cpp
src/game/Spells.cpp
src/game/spell/FlyingEye.cpp
)
set(GRAPHICS_SOURCES
src/graphics/Draw.cpp
src/graphics/DrawLine.cpp
src/graphics/DrawDebug.cpp
src/graphics/GraphicsModes.cpp
src/graphics/GraphicsUtility.cpp
src/graphics/Math.cpp
src/graphics/Renderer.cpp
src/graphics/data/CinematicTexture.cpp
src/graphics/data/FTL.cpp
src/graphics/data/Mesh.cpp
src/graphics/data/MeshManipulation.cpp
src/graphics/data/BackgroundEdit.cpp
src/graphics/data/Progressive.cpp
src/graphics/data/TextureContainer.cpp
src/graphics/effects/CinematicEffects.cpp
src/graphics/effects/DrawEffects.cpp
src/graphics/effects/Fog.cpp
src/graphics/effects/SpellEffects.cpp
src/graphics/effects/Halo.cpp
src/graphics/effects/Trail.cpp
src/graphics/font/Font.cpp
src/graphics/font/FontCache.cpp
src/graphics/image/Image.cpp
src/graphics/image/stb_image.cpp
src/graphics/image/stb_image_write.cpp
src/graphics/particle/Particle.cpp
src/graphics/particle/ParticleEffects.cpp
src/graphics/particle/ParticleManager.cpp
src/graphics/particle/ParticleSystem.cpp
src/graphics/particle/MagicFlare.cpp
src/graphics/spells/Spells01.cpp
src/graphics/spells/Spells02.cpp
src/graphics/spells/Spells03.cpp
src/graphics/spells/Spells04.cpp
src/graphics/spells/Spells05.cpp
src/graphics/spells/Spells06.cpp
src/graphics/spells/Spells07.cpp
src/graphics/spells/Spells09.cpp
src/graphics/spells/Spells10.cpp
src/graphics/texture/PackedTexture.cpp
src/graphics/texture/Texture.cpp
src/graphics/texture/TextureStage.cpp
)
set(GRAPHICS_OPENGL_SOURCES
src/graphics/opengl/GLTexture2D.cpp
src/graphics/opengl/GLTextureStage.cpp
src/graphics/opengl/GLVertexBuffer.cpp
src/graphics/opengl/OpenGLRenderer.cpp
)
set(GUI_SOURCES
src/gui/Credits.cpp
src/gui/Interface.cpp
src/gui/Menu.cpp
src/gui/MenuPublic.cpp
src/gui/MenuWidgets.cpp
src/gui/MiniMap.cpp
src/gui/Note.cpp
src/gui/Speech.cpp
src/gui/Text.cpp
src/gui/TextManager.cpp
)
set(INPUT_SOURCES src/input/Input.cpp)
set(INPUT_SDL_SOURCES src/input/SDLInputBackend.cpp)
set(IO_SOURCES
src/io/CinematicLoad.cpp
src/io/Implode.cpp
src/io/IniReader.cpp
src/io/IniSection.cpp
src/io/IniWriter.cpp
src/io/IO.cpp
src/io/SaveBlock.cpp
src/io/Screenshot.cpp
)
set(IO_LOGGER_SOURCES
src/io/log/ConsoleLogger.cpp
src/io/log/LogBackend.cpp
src/io/log/Logger.cpp
)
set(IO_LOGGER_EXTRA_SOURCES
src/io/log/FileLogger.cpp
src/io/log/CriticalLogger.cpp
)
set(IO_RESOURCE_SOURCES
src/io/Blast.cpp
src/io/resource/PakEntry.cpp
src/io/resource/PakReader.cpp
src/io/resource/ResourcePath.cpp
)
set(IO_LOGGER_POSIX_SOURCES src/io/log/ColorLogger.cpp)
set(IO_LOGGER_WINDOWS_SOURCES src/io/log/MsvcLogger.cpp)
set(IO_FILESYSTEM_SOURCES
src/io/fs/FilePath.cpp
src/io/fs/FileStream.cpp
src/io/fs/Filesystem.cpp
src/io/fs/SystemPaths.cpp
)
set(IO_FILESYSTEM_BOOST_SOURCES src/io/fs/FilesystemBoost.cpp)
set(IO_FILESYSTEM_POSIX_SOURCES src/io/fs/FilesystemPOSIX.cpp)
set(IO_FILESYSTEM_WINDOWS_SOURCES src/io/fs/FilesystemWindows.cpp)
set(MATH_SOURCES
src/math/Angle.cpp
src/math/Random.cpp
src/math/VectorNeon.cpp
)
set(PHYSICS_SOURCES
src/physics/Anchors.cpp
src/physics/Attractors.cpp
src/physics/Box.cpp
src/physics/Clothes.cpp
src/physics/Collisions.cpp
src/physics/CollisionShapes.cpp
src/physics/Physics.cpp
)
# Basic platform abstraction sources
set(PLATFORM_SOURCES
src/platform/Dialog.cpp
src/platform/Environment.cpp
src/platform/Lock.cpp
src/platform/OS.cpp
src/platform/Platform.cpp
src/platform/ProgramOptions.cpp
src/platform/Time.cpp
)
if(MACOSX)
list(APPEND PLATFORM_SOURCES src/platform/Dialog.mm)
endif()
# Extra platform abstraction - depends on the crash handler
set(PLATFORM_EXTRA_SOURCES
src/platform/Thread.cpp
)
# Crash handler sources
set(PLATFORM_CRASHHANDLER_SOURCES src/platform/CrashHandler.cpp)
set(PLATFORM_CRASHHANDLER_IMPL_SOURCES src/platform/crashhandler/CrashHandlerImpl.cpp)
set(PLATFORM_CRASHHANDLER_POSIX_SOURCES src/platform/crashhandler/CrashHandlerPOSIX.cpp)
set(PLATFORM_CRASHHANDLER_WINDOWS_SOURCES src/platform/crashhandler/CrashHandlerWindows.cpp)
set(SCENE_SOURCES
src/scene/ChangeLevel.cpp
src/scene/CinematicSound.cpp
src/scene/GameSound.cpp
src/scene/Interactive.cpp
src/scene/Light.cpp
src/scene/LinkedObject.cpp
src/scene/LoadLevel.cpp
src/scene/Object.cpp
src/scene/Scene.cpp
)
set(SCRIPT_SOURCES
src/script/Script.cpp
src/script/ScriptedAnimation.cpp
src/script/ScriptedCamera.cpp
src/script/ScriptedControl.cpp
src/script/ScriptedConversation.cpp
src/script/ScriptedInterface.cpp
src/script/ScriptedInventory.cpp
src/script/ScriptedIOControl.cpp
src/script/ScriptedIOProperties.cpp
src/script/ScriptedItem.cpp
src/script/ScriptedLang.cpp
src/script/ScriptedNPC.cpp
src/script/ScriptedPlayer.cpp
src/script/ScriptedVariable.cpp
src/script/ScriptEvent.cpp
src/script/ScriptUtils.cpp
)
set(UTIL_SOURCES
src/util/String.cpp
)
set(WINDOW_SOURCES
src/window/RenderWindow.cpp
src/window/Window.cpp
)
if(GLES)
set(WINDOW_SDL_SOURCES src/window/SDLWindow.cpp src/window/eglport.cpp)
else()
set(WINDOW_SDL_SOURCES src/window/SDLWindow.cpp)
endif()
# TODO manually specify theese like we do for the tools
file(GLOB_RECURSE ALL_INCLUDES RELATIVE ${CMAKE_SOURCE_DIR} ${SRC_DIR}/*.h)
include_directories(${SRC_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/tools)
# Check for optional / alternative subsystem implementations
# Audio
if(USE_OPENAL AND OPENAL_FOUND)
list(APPEND AUDIO_SOURCES ${AUDIO_OPENAL_SOURCES})
list(APPEND ARX_LIBRARIES ${OPENAL_LIBRARY})
include_directories(SYSTEM ${OPENAL_INCLUDE_DIR})
set(ARX_HAVE_OPENAL 1)
if(OPENALEFX_FOUND)
include_directories(SYSTEM ${OPENAL_EFX_INCLUDE_DIR})
set(ARX_HAVE_OPENAL_EFX 1)
endif()
endif()
# Graphics
if(USE_OPENGL AND OPENGL_FOUND AND GLEW_FOUND)
list(APPEND GRAPHICS_SOURCES ${GRAPHICS_OPENGL_SOURCES})
list(APPEND ARX_LIBRARIES ${GLEW_LIBRARIES} ${OPENGL_gl_LIBRARY})
include_directories(SYSTEM ${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIR})
add_definitions(${GLEW_DEFINITIONS})
set(ARX_HAVE_OPENGL 1)
endif()
if(GLES)
list(APPEND GRAPHICS_SOURCES ${GRAPHICS_OPENGL_SOURCES})
list(APPEND ARX_LIBRARIES GLES_CM EGL )
include_directories(SYSTEM /mnt/utmp/codeblocks/usr/include/GLES )
set(ARX_HAVE_OPENGL 1)
add_definitions(-DHAVE_GLES)
else()
if(USE_OPENGL AND OPENGL_FOUND AND GLEW_FOUND)
list(APPEND GRAPHICS_SOURCES ${GRAPHICS_OPENGL_SOURCES})
list(APPEND ARX_LIBRARIES ${GLEW_LIBRARIES} ${OPENGL_gl_LIBRARY})
include_directories(SYSTEM ${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIR})
add_definitions(${GLEW_DEFINITIONS})
set(ARX_HAVE_OPENGL 1)
endif()
endif()
if(PANDORA)
add_definitions(-DPANDORA)
endif()
# Windowing / input
if(USE_SDL AND ARX_HAVE_OPENGL AND SDL_FOUND)
list(APPEND WINDOW_SOURCES ${WINDOW_SDL_SOURCES})
list(APPEND INPUT_SOURCES ${INPUT_SDL_SOURCES})
list(APPEND ARX_LIBRARIES ${SDL_LIBRARY})
include_directories(SYSTEM ${SDL_INCLUDE_DIR})
set(ARX_HAVE_SDL 1)
endif()
# Logging
if(ARX_HAVE_ISATTY)
list(APPEND IO_LOGGER_SOURCES ${IO_LOGGER_POSIX_SOURCES})
endif()
if(ARX_HAVE_WINAPI)
list(APPEND IO_LOGGER_SOURCES ${IO_LOGGER_WINDOWS_SOURCES})
endif()
list(APPEND IO_SOURCES ${IO_LOGGER_SOURCES} ${IO_LOGGER_EXTRA_SOURCES})
list(APPEND IO_SOURCES ${IO_RESOURCE_SOURCES})
# Filesystem
if(ARX_HAVE_POSIX_FILESYSTEM)
list(APPEND IO_FILESYSTEM_SOURCES ${IO_FILESYSTEM_POSIX_SOURCES})
elseif(USE_NATIVE_FS AND ARX_HAVE_WINAPI)
add_definitions(-DARX_HAVE_WINDOWS_FILESYSTEM)
list(APPEND IO_FILESYSTEM_SOURCES ${IO_FILESYSTEM_WINDOWS_SOURCES})
set(ARX_HAVE_WIN32_FILESYSTEM 1)
elseif(NOT ${Boost_VERSION} LESS 104400)
find_package(Boost 1.44 REQUIRED COMPONENTS filesystem system)
set(ARX_HAVE_BOOST_FILESYSTEM_V3 1)
add_definitions(-DBOOST_FILESYSTEM_VERSION=3)
add_definitions(-DBOOST_FILESYSTEM_NO_DEPRECATED)
list(APPEND IO_FILESYSTEM_SOURCES ${IO_FILESYSTEM_BOOST_SOURCES})
list(APPEND BASE_LIBRARIES ${Boost_LIBRARIES})
# BOOST_SCOPED_ENUM is implemented differently if compiled with C++11 support
# This means the Boost.Filesystem ABI depends on what C++ version was used
# to compile the library - check for that!
check_compile(boost_filesystem_abi_matches
"${CMAKE_MODULE_PATH}/check_boostfs_cxx11_scoped_enum.cpp"
"scoped enum" "Boost ABI"
"${Boost_LIBRARIES}"
"mismatch, fixing"
)
if(NOT boost_filesystem_abi_matches)
add_definitions(
# Different names for different Boost versions :/
-DBOOST_NO_SCOPED_ENUMS=1
-DBOOST_NO_CXX11_SCOPED_ENUMS=1
)
endif()
else()
message(FATAL_ERROR "You need either Boost >= 1.44 or Windows API"
"or enough POSIX functionality; Found boost version ${Boost_VERSION}")
endif()
list(APPEND IO_SOURCES ${IO_FILESYSTEM_SOURCES})
# Crash reporter
if(ARX_HAVE_CRASHREPORTER)
if((ARX_HAVE_EXECLP OR ARX_HAVE_EXECL) AND ARX_HAVE_FORK AND ARX_HAVE_KILL)
list(APPEND PLATFORM_CRASHHANDLER_SOURCES ${PLATFORM_CRASHHANDLER_IMPL_SOURCES})
list(APPEND PLATFORM_CRASHHANDLER_SOURCES ${PLATFORM_CRASHHANDLER_POSIX_SOURCES})
set(ARX_HAVE_CRASHHANDLER_POSIX 1)
elseif(MSVC)
list(APPEND PLATFORM_CRASHHANDLER_SOURCES ${PLATFORM_CRASHHANDLER_IMPL_SOURCES})
list(APPEND PLATFORM_CRASHHANDLER_SOURCES ${PLATFORM_CRASHHANDLER_WINDOWS_SOURCES})
set(ARX_HAVE_CRASHHANDLER_WINDOWS 1)
list(APPEND ARX_LIBRARIES ${DBGHELP_LIBRARIES})
include_directories(SYSTEM ${DBGHELP_INCLUDE_DIR})
else()
# Don't bother building arxcrashreporter if it will never be used.
set(ARX_HAVE_CRASHREPORTER 0)
endif()
endif()
if(LIBRT_LIBRARY AND (ARX_HAVE_CLOCK_GETTIME OR ARX_HAVE_CRASHHANDLER_POSIX))
# Needed for clock_gettime and boost::interprocess on some system.
list(APPEND BASE_LIBRARIES ${LIBRT_LIBRARY})
endif()
list(APPEND ARX_LIBRARIES ${BASE_LIBRARIES})
if(NOT MSVC)
check_link_library(Boost Boost_LIBRARIES)
endif()
set(ARX_SOURCES
${AI_SOURCES}
${ANIMATION_SOURCES}
${AUDIO_SOURCES}
${CORE_SOURCES}
${GAME_SOURCES}
${GRAPHICS_SOURCES}
${GUI_SOURCES}
${INPUT_SOURCES}
${IO_SOURCES}
${MATH_SOURCES}
${PHYSICS_SOURCES}
${PLATFORM_SOURCES}
${PLATFORM_EXTRA_SOURCES}
${PLATFORM_CRASHHANDLER_SOURCES}
${SCENE_SOURCES}
${SCRIPT_SOURCES}
${UTIL_SOURCES}
${WINDOW_SOURCES}
)
# Set the icon for the Windows executable by adding this resource file to the sources
if(WIN32)
list(APPEND ARX_SOURCES data/icons/arx-libertatis.rc)
endif()
# Prepare sources
# Create source groups
list(APPEND ALL_FILES_FOR_GROUPS ${ALL_INCLUDES} ${ARX_SOURCES})
create_source_groups(ALL_FILES_FOR_GROUPS)
configure_file("${SRC_DIR}/Configure.h.in" "Configure.h" ESCAPE_QUOTES)
configure_file("${SRC_DIR}/io/fs/PathConstants.h.in" "io/fs/PathConstants.h"
ESCAPE_QUOTES)
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/platform")
set(PLATFORM_CONFIG_H "platform/PlatformConfig.h")
configure_file("${SRC_DIR}/${PLATFORM_CONFIG_H}.in" "${PLATFORM_CONFIG_H}" ESCAPE_QUOTES)
set(VERSION_TEMPLATE "${SRC_DIR}/core/Version.cpp.in")
set(VERSION_FILE "${CMAKE_BINARY_DIR}/core/Version.cpp")
set(VERSION_SOURCES VERSION "VERSION" AUTHORS "AUTHORS")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/core")
version_file("${VERSION_TEMPLATE}" "${VERSION_FILE}" "${VERSION_SOURCES}" ".git")
list(APPEND ARX_SOURCES "${VERSION_FILE}")
# Add executables
add_executable_shared(arx WIN32 "${ARX_SOURCES}" "${ARX_LIBRARIES}"
"${ALL_INCLUDES}" "${GAMESBINDIR}")
if(ARX_HAVE_CRASHREPORTER)
if(HAVE_QT5)
add_definitions(
${Qt5Core_DEFINITIONS}
${Qt5Gui_DEFINITIONS}
${Qt5Widgets_DEFINITIONS}
${Qt5Network_DEFINITIONS}
-DQT_NO_DEBUG
)
include_directories(SYSTEM
${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
${Qt5Network_INCLUDE_DIRS}
)
elseif(HAVE_QT4)
add_definitions(${QT_DEFINITIONS} -DQT_NO_DEBUG)
include_directories(SYSTEM
${QT_INCLUDE_DIR}
${QT_QTCORE_INCLUDE_DIR}
${QT_QTGUI_INCLUDE_DIR}
${QT_QTNETWORK_INCLUDE_DIR}
)
endif()
set(arxcrashreporter_SOURCES
${PLATFORM_SOURCES}
${IO_FILESYSTEM_SOURCES}
${IO_LOGGER_SOURCES}
${UTIL_SOURCES}
tools/crashreporter/CrashReporter.cpp
tools/crashreporter/ErrorReport.h
tools/crashreporter/ErrorReport.cpp