-
Notifications
You must be signed in to change notification settings - Fork 289
/
CMakeLists.txt
1051 lines (888 loc) · 33 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
#
#
# TODO:
#
# - some documentation targets still missing
# - installing documentation
#
#-----------------------------------------------------------------------------#
#
# Build system setup
#
#-----------------------------------------------------------------------------#
cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Profile."
FORCE)
endif()
# Restrict configuration types to the selected build type.
# Note: This needs to be done before the project command
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_BUILD_TYPE}" CACHE INTERNAL "internal")
option(WANT_ANDROID "Build for Android" OFF)
option(WANT_ANDROID_LEGACY "Build for Android 4 (1.6)" OFF)
option(WANT_GLES2 "Compile with GLES2 support" ON)
if(WANT_ANDROID)
include(${CMAKE_SOURCE_DIR}/cmake/Toolchain-android.cmake)
set(ANDROID_TARGET "android-12" CACHE STRING "What Android target to compile for.")
endif(WANT_ANDROID)
option(ALLEGRO_SDL "Build using the SDL backend (experimental)" OFF)
option(WANT_STATIC_RUNTIME "Whether or not to link the C and C++ runtimes statically (currently only implemented for MSVC)" OFF)
# Set the project name.
# We use C++ in a few cases.
project(ALLEGRO C CXX)
set(ALLEGRO_VERSION 5.1.12)
string(REGEX MATCH "^[0-9]+[.][0-9]+" ALLEGRO_SOVERSION ${ALLEGRO_VERSION})
string(REPLACE "." "" ALLEGRO_DLL_SHORTVER ${ALLEGRO_SOVERSION})
# Search in the `cmake' directory for additional CMake modules.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
# Search in `deps' directories for dependency files.
file(GLOB deps_subdirs
"${CMAKE_SOURCE_DIR}/deps"
"${CMAKE_SOURCE_DIR}/deps/*"
"${CMAKE_BINARY_DIR}/deps"
"${CMAKE_BINARY_DIR}/deps/*"
)
foreach(subdir ${deps_subdirs})
if(EXISTS "${subdir}/include" OR EXISTS "${subdir}/lib")
if(CMAKE_FIND_ROOT_PATH)
message(STATUS "Adding ${subdir} to CMAKE_FIND_ROOT_PATH")
list(APPEND CMAKE_FIND_ROOT_PATH "${subdir}")
else()
message(STATUS "Adding ${subdir} to CMAKE_PREFIX_PATH")
list(APPEND CMAKE_PREFIX_PATH "${subdir}")
endif()
endif()
endforeach(subdir)
# Search for C header files in these directories.
include_directories(
${CMAKE_SOURCE_DIR}/include
${CMAKE_BINARY_DIR}/include
)
# Put libraries into `lib'.
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
# Lists of all the source files.
include(FileList)
# Our own CMake macros and functions.
include(Common)
#-----------------------------------------------------------------------------#
#
# Build options
#
#-----------------------------------------------------------------------------#
if(NOT IPHONE)
option(SHARED "Build shared libraries" on)
set(BUILD_SHARED_LIBS ${SHARED}) # actual CMake variable
endif(NOT IPHONE)
# On some 64-bit platforms, libraries should be installed into `lib64'
# instead of `lib'. Set this to 64 to do that.
set(LIB_SUFFIX "" CACHE STRING "Suffix for 'lib' directories, e.g. '64'")
option(WANT_FRAMEWORKS "Want frameworks on Mac OS X" off)
option(WANT_EMBED
"Make frameworks embeddable in application bundles (Mac OS X)" on)
set(FRAMEWORK_INSTALL_PREFIX "/Library/Frameworks" CACHE STRING
"Directory in which to install Mac OS X frameworks")
#
# Platforms and drivers.
#
option(WANT_X11 "X11 support" on)
option(WANT_X11_XF86VIDMODE "X11 XF86VidMode Extension support" on)
option(WANT_X11_XINERAMA "X11 Xinerama Extension support" on)
option(WANT_X11_XRANDR "X11 XRandR Extension support" on)
option(WANT_D3D "Enable Direct3D graphics driver (Windows)" on)
option(WANT_D3D9EX "Enable Direct3D 9Ex extensions (Vista)" off)
option(WANT_OPENGL "Enable OpenGL graphics driver (Windows, X11, OS X))" on)
option(WANT_SHADERS_GL "Build GLSL shader support (OpenGL)" on)
option(WANT_SHADERS_D3D "Build HLSL shader support (Direct3D)" on)
option(WANT_OPENGL_S3TC_LOCKING "Whether to support blocked locking of DXT1, DXT2, and DXT3 formats in OpenGL." off)
#
# Addons.
#
option(WANT_FONT "Enable bitmap font add-on" on)
option(WANT_AUDIO "Enable allegro_audio engine" on)
option(WANT_IMAGE "Enable image load/save addon" on)
if (NOT IPHONE)
option(WANT_IMAGE_JPG "Enable JPEG support in image addon" on)
option(WANT_IMAGE_PNG "Enable PNG support in image addon" on)
endif (NOT IPHONE)
option(WANT_TTF "Enable TTF addon" on)
option(WANT_COLOR "Enable color addon" on)
option(WANT_MEMFILE "Enable memfile addon" on)
option(WANT_PHYSFS "Enable PhysicsFS addon" on)
option(WANT_PRIMITIVES "Enable primitives addon" on)
option(WANT_NATIVE_DIALOG "Enable native dialog addon" on)
option(WANT_VIDEO "Enable video player addon" on)
option(WANT_MONOLITH "Include all addons in the main library" off)
#
# Wrappers.
#
option(WANT_PYTHON_WRAPPER "Enable generation of the Python wrapper" off)
#
# Documentation.
#
option(WANT_DOCS "Generate documentation" on)
option(WANT_DOCS_HTML "Generate HTML documentation" on)
option(WANT_DOCS_MAN "Generate man pages" on)
option(WANT_DOCS_INFO "Generate Info document" off)
option(WANT_DOCS_PDF "Generate PDF document (requires pdflatex)" off)
option(WANT_DOCS_PDF_PAPER "Whether PDF output is destined for paper" off)
#
# For developers.
#
option(STRICT_WARN "Halt at warnings" off)
option(WANT_MUDFLAP "Enable gcc mudflap (requires gcc 4.0+)" off)
option(WANT_RELEASE_LOGGING "Enable logging even in release mode" on)
if(WANT_RELEASE_LOGGING)
set(ALLEGRO_CFG_RELEASE_LOGGING 1)
endif()
#
# Minor options.
#
if(NOT IPHONE)
option(WANT_ALLOW_SSE "Allow compiler to use SSE instructions (x86)" on)
endif(NOT IPHONE)
option(NO_FPU "No floating point unit" off)
option(WANT_DLL_TLS "Force use of DllMain for TLS (Windows)" off)
option(WANT_DEMO "Build demo programs" on)
option(WANT_EXAMPLES "Build example programs" on)
option(WANT_POPUP_EXAMPLES "Use popups instead of printf for fatal errors" on)
option(WANT_TESTS "Build test programs" on)
#-----------------------------------------------------------------------------#
#
# Set up compilers
#
#-----------------------------------------------------------------------------#
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
if(CMAKE_COMPILER_IS_GNUCC)
set(COMPILER_GCC 1)
set(COMPILER_GCC_OR_CLANG 1)
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(COMPILER_GCC_OR_CLANG 1)
endif()
if(WIN32)
if(WANT_DLL_TLS AND SHARED)
set(ALLEGRO_CFG_DLL_TLS 1)
endif(WANT_DLL_TLS AND SHARED)
endif(WIN32)
if(MSVC)
set(COMPILER_MSVC 1)
set(ALLEGRO_MSVC 1)
# Guess VCINSTALLDIR from the value of CMAKE_C_COMPILER if it's not set.
# XXX CMAKE_C_COMPILER will often be simply "cl" so this won't work.
if("$ENV{VCINSTALLDIR}" STREQUAL "")
string(REGEX REPLACE "/bin/[^/]*$" "" VCINSTALLDIR "${CMAKE_C_COMPILER}")
message(STATUS "Guessed MSVC directory: ${VCINSTALLDIR}")
else("$ENV{VCINSTALLDIR}" STREQUAL "")
file(TO_CMAKE_PATH "$ENV{VCINSTALLDIR}" VCINSTALLDIR)
message(STATUS "Using VCINSTALLDIR: ${VCINSTALLDIR}")
endif("$ENV{VCINSTALLDIR}" STREQUAL "")
# Install in VCINSTALLDIR by default
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${VCINSTALLDIR}
CACHE PATH "Install path prefix, prepended onto install directories."
FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(EXECUTABLE_TYPE "WIN32")
endif(MSVC)
if(MINGW)
# For alplatf.h
set(ALLEGRO_MINGW32 1)
# Guess MINGDIR from the value of CMAKE_C_COMPILER if it's not set.
if("$ENV{MINGDIR}" STREQUAL "")
string(REGEX REPLACE "/bin/[^/]*$" "" MINGDIR "${CMAKE_C_COMPILER}")
message(STATUS "Guessed MinGW directory: ${MINGDIR}")
else("$ENV{MINGDIR}" STREQUAL "")
file(TO_CMAKE_PATH "$ENV{MINGDIR}" MINGDIR)
message(STATUS "Using MINGDIR: ${MINGDIR}")
endif("$ENV{MINGDIR}" STREQUAL "")
# Search in MINGDIR for headers and libraries.
if(CMAKE_FIND_ROOT_PATH)
list(APPEND CMAKE_FIND_ROOT_PATH "${MINGDIR}")
else()
list(APPEND CMAKE_PREFIX_PATH "${MINGDIR}")
endif()
# Install to MINGDIR
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${MINGDIR}
CACHE PATH "Install path prefix, prepended onto install directories."
FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# Check for a common problem (at the time of writing).
check_c_source_compiles("
#include <windows.h>
int main(void)
{
int x = DM_POSITION;
return 0;
}"
HAVE_DM_POSITION)
if(NOT HAVE_DM_POSITION)
message(FATAL_ERROR
"Missing DM_POSITION. Please update your MinGW "
"w32api package, delete CMakeCache.txt and try again.")
endif(NOT HAVE_DM_POSITION)
endif(MINGW)
if(UNIX AND NOT APPLE AND NOT ANDROID)
set(ALLEGRO_UNIX 1)
endif(UNIX AND NOT APPLE AND NOT ANDROID)
if(APPLE AND NOT IPHONE)
set(MACOSX 1)
endif(APPLE AND NOT IPHONE)
if(MACOSX)
set(ALLEGRO_MACOSX 1)
set(ALLEGRO_CFG_PTHREADS_TLS 1)
set(ALLEGRO_UNIX 0)
set(WANT_X11 off)
# This flag is required on some versions of Mac OS X to avoid linker
# problems with global variables which are not explicitly initialised.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-common")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common")
endif(MACOSX)
if(IPHONE)
set(ALLEGRO_CFG_PTHREADS_TLS 1)
set(ALLEGRO_IPHONE 1)
set(ALLEGRO_UNIX 0)
set(WANT_X11 off)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
set(CMAKE_EXE_LINKER_FLAGS "-framework CoreGraphics -framework QuartzCore -framework UIKit -framework Foundation -framework CoreFoundation")
endif(IPHONE)
if(BORLAND)
set(ALLEGRO_BCC32 1)
endif(BORLAND)
if(ANDROID)
set(ALLEGRO_ANDROID 1)
set(ALLEGRO_CFG_PTHREADS_TLS 1)
set(WANT_X11 off)
endif(ANDROID)
if(ALLEGRO_RASPBERRYPI)
set(ALLEGRO_CFG_PTHREADS_TLS 1)
endif(ALLEGRO_RASPBERRYPI)
if(ALLEGRO_SDL)
set(ALLEGRO_UNIX 0)
set(WANT_X11 off)
include(FindSDL2)
endif(ALLEGRO_SDL)
# Tell the compiler it can use SSE instructions on x86 architectures.
# If compatibility with Pentium 2's and below is required then the user
# should switch WANT_ALLOW_SSE off.
# Workaround for a possible bug in CMake. Even if we set this variable in
# the toolchain file when cross-compiling, as we should, it is empty.
if(NOT CMAKE_SYSTEM_PROCESSOR AND CMAKE_SYSTEM_NAME STREQUAL Windows)
set(CMAKE_SYSTEM_PROCESSOR i686)
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "i.86")
set(ARCH_X86 1)
endif()
# CMake reports "x86" on my Windows Vista machine
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86")
set(ARCH_X86 1)
endif()
if(ARCH_X86 AND WANT_ALLOW_SSE)
if(COMPILER_GCC_OR_CLANG)
message(STATUS "Allowing GCC/Clang to use SSE instructions")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse")
endif(COMPILER_GCC_OR_CLANG)
# Flags for other compilers should be added here.
if(COMPILER_MSVC)
message(STATUS "Allowing MSVC to use SSE instructions")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:SSE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE")
endif(COMPILER_MSVC)
endif()
#-----------------------------------------------------------------------------#
#
# Build types
#
#-----------------------------------------------------------------------------#
# Warnings.
if(COMPILER_GCC_OR_CLANG)
set(WFLAGS "-W -Wall -Wpointer-arith")
set(WFLAGS_C_ONLY "-Wmissing-declarations -Wstrict-prototypes")
if(ALLEGRO_UNIX)
# Unfortunately we can't use this flag when magic main is used,
# the mangled_main won't have a forward declaration.
set(WFLAGS_C_ONLY "${WFLAGS_C_ONLY} -Wmissing-prototypes")
endif(ALLEGRO_UNIX)
if(WIN32)
# Helps to ensure the Windows port remains compatible with MSVC.
set(WFLAGS_C_ONLY "${WFLAGS_C_ONLY} -Wdeclaration-after-statement")
endif(WIN32)
if(STRICT_WARN)
set(WFLAGS "${WFLAGS} -Werror")
endif()
endif()
if(COMPILER_MSVC)
set(WFLAGS "/W4 -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE")
endif(COMPILER_MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WFLAGS} ${WFLAGS_C_ONLY}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WFLAGS}")
if(WANT_MUDFLAP AND COMPILER_GCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fmudflapth")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmudflapth")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fmudflapth -lmudflapth")
endif(WANT_MUDFLAP AND COMPILER_GCC)
# Debugging.
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUGMODE=1 -DD3D_DEBUG_INFO")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUGMODE=1 -DD3D_DEBUG_INFO")
# Profiling.
list(APPEND CMAKE_BUILD_CONFIGURATIONS Profile)
if(COMPILER_GCC_OR_CLANG)
set(CMAKE_C_FLAGS_PROFILE "-pg"
CACHE STRING "profiling flags")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE}"
CACHE STRING "profiling flags")
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "-pg"
CACHE STRING "profiling flags")
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "-pg"
CACHE STRING "profiling flags")
mark_as_advanced(
CMAKE_C_FLAGS_PROFILE
CMAKE_CXX_FLAGS_PROFILE
CMAKE_EXE_LINKER_FLAGS_PROFILE
CMAKE_SHARED_LINKER_FLAGS_PROFILE
)
endif(COMPILER_GCC_OR_CLANG)
#-----------------------------------------------------------------------------#
#
# Begin tests
#
#-----------------------------------------------------------------------------#
include(CheckFunctionExists)
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckTypeSize)
include(FindPkgConfig)
include(TestBigEndian)
if(NOT IPHONE)
test_big_endian(ALLEGRO_BIG_ENDIAN)
endif(NOT IPHONE)
if(NOT ALLEGRO_BIG_ENDIAN)
set(ALLEGRO_LITTLE_ENDIAN 1)
endif(NOT ALLEGRO_BIG_ENDIAN)
check_include_files(dirent.h ALLEGRO_HAVE_DIRENT_H)
check_include_files(inttypes.h ALLEGRO_HAVE_INTTYPES_H)
check_include_files(linux/input.h ALLEGRO_HAVE_LINUX_INPUT_H)
check_include_files(stdbool.h ALLEGRO_HAVE_STDBOOL_H)
check_include_files(stdint.h ALLEGRO_HAVE_STDINT_H)
check_include_files(sys/io.h ALLEGRO_HAVE_SYS_IO_H)
check_include_files(sys/stat.h ALLEGRO_HAVE_SYS_STAT_H)
check_include_files(sys/time.h ALLEGRO_HAVE_SYS_TIME_H)
check_include_files(time.h ALLEGRO_HAVE_TIME_H)
check_include_files(sys/utsname.h ALLEGRO_HAVE_SYS_UTSNAME_H)
check_include_files(sys/types.h ALLEGRO_HAVE_SYS_TYPES_H)
check_include_files(soundcard.h ALLEGRO_HAVE_SOUNDCARD_H)
check_include_files(sys/soundcard.h ALLEGRO_HAVE_SYS_SOUNDCARD_H)
check_include_files(machine/soundcard.h ALLEGRO_HAVE_MACHINE_SOUNDCARD_H)
check_include_files(linux/soundcard.h ALLEGRO_HAVE_LINUX_SOUNDCARD_H)
check_include_files(libkern/OSAtomic.h ALLEGRO_HAVE_OSATOMIC_H)
check_include_files(sys/inotify.h ALLEGRO_HAVE_SYS_INOTIFY_H)
check_include_files(sal.h ALLEGRO_HAVE_SAL_H)
check_function_exists(getexecname ALLEGRO_HAVE_GETEXECNAME)
check_function_exists(mkstemp ALLEGRO_HAVE_MKSTEMP)
check_function_exists(mmap ALLEGRO_HAVE_MMAP)
check_function_exists(mprotect ALLEGRO_HAVE_MPROTECT)
check_function_exists(sched_yield ALLEGRO_HAVE_SCHED_YIELD)
check_function_exists(sysconf ALLEGRO_HAVE_SYSCONF)
check_function_exists(fseeko ALLEGRO_HAVE_FSEEKO)
check_function_exists(ftello ALLEGRO_HAVE_FTELLO)
check_function_exists(strerror_r ALLEGRO_HAVE_STRERROR_R)
check_function_exists(strerror_s ALLEGRO_HAVE_STRERROR_S)
check_type_size("_Bool" ALLEGRO_HAVE__BOOL)
check_c_source_compiles("
#include <sys/procfs.h>
int main(void) {
struct prpsinfo psinfo;
psinfo.pr_argc = 0;
return 0;
}"
ALLEGRO_HAVE_PROCFS_ARGCV
)
check_c_source_compiles("
#include <sys/procfs.h>
#include <sys/ioctl.h>
int main(void) {
struct prpsinfo psinfo;
ioctl(0, PIOCPSINFO, &psinfo);
return 0;
}"
ALLEGRO_HAVE_SV_PROCFS_H
)
check_c_source_compiles("
#include <stdarg.h>
int main(void) {
va_list a, b;
va_copy(a, b);
return 0;
}"
ALLEGRO_HAVE_VA_COPY
)
#-----------------------------------------------------------------------------#
#
# Driver configuration
#
#-----------------------------------------------------------------------------#
#
# These are the conventions for this CMakeFile.
#
# The WANT_* variables indicate whether the user wants to have an optional
# feature enabled, i.e. whether they have selected something in the CMake UI.
#
# The CAN_* variables indicate whether a feature *can* be enabled on this
# system/platform. As these variable values are cached, CAN_ variables could
# be set even though the user has turned a corresponding WANT_* variable
# off---it might have been tested and set in a previous run.
#
# The SUPPORT_* variables are the conjunction of WANT_FEATURE and CAN_FEATURE,
# i.e. the user wants it and the system can support it.
#
# Those variables are internal to the CMake build. Allegro header files use
# preprocessor constants with names like ALLEGRO_WITH_* and ALLEGRO_HAVE_*.
# Sometimes we make use of those variables in this CMakeFile as well, but
# generally that's just due to sloppiness.
#
if(WANT_OPENGL)
find_package(OpenGL)
if(ANDROID)
find_package(OpenGLES)
find_package(OpenGLES2)
endif(ANDROID)
# on cmake 2.8.1 OpenGL ES is not found in the iphone case
# XXX incorporate IPHONE case into FindOpenGLES/2
if(IPHONE)
set(OPENGLES_FOUND 1)
set(OPENGLES_LIBRARIES "-framework OpenGLES")
set(OPENGLES2_FOUND 1)
set(OPENGLES2_LIBRARIES "-framework OpenGLES")
endif(IPHONE)
if(OPENGLES_FOUND)
set(SUPPORT_OPENGL 1)
set(ALLEGRO_CFG_OPENGL 1)
set(ALLEGRO_CFG_OPENGLES 1)
set(OPENGL_LIBRARIES ${OPENGLES_LIBRARIES})
if(OPENGLES2_FOUND)
set(ALLEGRO_CFG_OPENGLES2 1)
set(ALLEGRO_CFG_OPENGL_PROGRAMMABLE_PIPELINE 1)
list(APPEND OPENGL_LIBRARIES ${OPENGLES2_LIBRARIES})
endif()
elseif(OPENGL_FOUND)
set(SUPPORT_OPENGL 1)
set(ALLEGRO_CFG_OPENGL 1)
# We assume that the OpenGL library is not very old.
set(ALLEGRO_CFG_OPENGL_PROGRAMMABLE_PIPELINE 1)
endif()
endif(WANT_OPENGL)
if(WANT_OPENGL_S3TC_LOCKING)
set(ALLEGRO_CFG_OPENGL_S3TC_LOCKING 1)
else()
message("S3TC locking disabled. You will not be able to load/save "
"pre-compressed textures with OpenGL.")
endif()
#
# Unix-specific
#
if(UNIX) # includes MACOSX
if(NOT IPHONE AND NOT ANDROID)
find_package(Threads)
if(NOT CMAKE_USE_PTHREADS_INIT)
message(FATAL_ERROR
"Unix port requires pthreads support, not detected.")
endif(NOT CMAKE_USE_PTHREADS_INIT)
endif()
endif(UNIX)
#
# X Window System
#
if(WANT_X11)
find_package(X11)
if(X11_FOUND)
set(SUPPORT_X11 1)
set(ALLEGRO_WITH_XWINDOWS 1)
endif(X11_FOUND)
endif(WANT_X11)
if(ALLEGRO_UNIX AND NOT SUPPORT_X11 AND WANT_X11) # not MACOSX
message(FATAL_ERROR
"X11 not found. You may need to install X11 development libraries.")
endif(ALLEGRO_UNIX AND NOT SUPPORT_X11 AND WANT_X11)
if((NOT ALLEGRO_RASPBERRYPI) AND (SUPPORT_X11 AND NOT SUPPORT_OPENGL))
message(FATAL_ERROR "X11 support currently requires OpenGL support.")
endif((NOT ALLEGRO_RASPBERRYPI) AND (SUPPORT_X11 AND NOT SUPPORT_OPENGL))
if(SUPPORT_X11)
set(CMAKE_REQUIRED_LIBRARIES ${X11_LIBRARIES})
check_library_exists(Xcursor XcursorImageCreate "" CAN_XCURSOR)
if(CAN_XCURSOR)
set(ALLEGRO_XWINDOWS_WITH_XCURSOR 1)
find_library(XCURSOR_LIB "Xcursor")
list(APPEND X11_LIBRARIES "${XCURSOR_LIB}")
else(CAN_XCURSOR)
message(FATAL_ERROR "X11 support requires Xcursor library.")
endif(CAN_XCURSOR)
check_include_file("X11/extensions/XInput2.h" CAN_XINPUT2)
check_c_source_compiles("
#include <X11/extensions/XInput2.h>
int main(void) { (void)XI_TouchBegin; return 0; }"
XINPUT2_COMPILES
)
if(CAN_XINPUT2 AND XINPUT2_COMPILES)
list(APPEND X11_LIBRARIES "Xi")
set(ALLEGRO_XWINDOWS_WITH_XINPUT2 1)
else()
message("XInput2 library version 2.2 or higher not found, disabling touch support.")
endif()
if(WANT_X11_XF86VIDMODE)
check_include_file("X11/extensions/xf86vmode.h" HAVE_XF86VIDMODE_H)
check_library_exists(Xxf86vm XF86VidModeQueryExtension "" CAN_XF86VIDMODE)
if(CAN_XF86VIDMODE AND HAVE_XF86VIDMODE_H)
set(ALLEGRO_XWINDOWS_WITH_XF86VIDMODE 1)
list(APPEND X11_LIBRARIES "Xxf86vm")
endif()
endif(WANT_X11_XF86VIDMODE)
if(WANT_X11_XINERAMA)
check_include_file("X11/extensions/Xinerama.h" HAVE_XINERAMA_H)
check_library_exists(Xinerama XineramaQueryExtension "" CAN_XINERAMA)
if(CAN_XINERAMA AND HAVE_XINERAMA_H)
set(ALLEGRO_XWINDOWS_WITH_XINERAMA 1)
find_library(XINERAMA_LIB "Xinerama")
list(APPEND X11_LIBRARIES "${XINERAMA_LIB}")
endif()
endif(WANT_X11_XINERAMA)
if(WANT_X11_XRANDR)
check_include_file("X11/extensions/Xrandr.h" HAVE_XRANDR_H)
check_library_exists(Xrandr XRRQueryExtension "" CAN_XRANDR)
if(CAN_XRANDR AND HAVE_XRANDR_H)
set(ALLEGRO_XWINDOWS_WITH_XRANDR 1)
find_library(XRANDR_LIB "Xrandr")
list(APPEND X11_LIBRARIES "${XRANDR_LIB}")
endif()
endif(WANT_X11_XRANDR)
if(NOT ALLEGRO_RASPBERRYPI)
check_library_exists(X11 XOpenIM "" CAN_XIM)
if(CAN_XIM)
set(ALLEGRO_XWINDOWS_WITH_XIM 1)
endif(CAN_XIM)
endif(NOT ALLEGRO_RASPBERRYPI)
set(CMAKE_REQUIRED_LIBRARIES)
endif(SUPPORT_X11)
#
# Windows
#
if(WIN32)
find_package(DirectX)
if(DINPUT_FOUND)
# At least some copies of dinput.h redefine some types multiple times.
# We must add the directory as a system directory so that the compiler
# will suppress such errors.
include_directories(SYSTEM ${DINPUT_INCLUDE_DIR})
else(DINPUT_FOUND)
message(FATAL_ERROR
"Windows port requires DirectInput (not found).")
endif(DINPUT_FOUND)
# Xinput support for xbox compatible controllers.
if(XINPUT_FOUND)
set(SUPPORT_XINPUT 1)
set(ALLEGRO_CFG_XINPUT 1)
endif(XINPUT_FOUND)
if(WANT_D3D)
if(D3D9_FOUND)
set(SUPPORT_D3D 1)
set(ALLEGRO_CFG_D3D 1)
endif(D3D9_FOUND)
endif(WANT_D3D)
if(SUPPORT_D3D)
if(D3DX9_FOUND)
include_directories(BEFORE SYSTEM ${D3DX9_INCLUDE_DIR})
set(ALLEGRO_CFG_D3DX9 1)
else()
message("D3DX9 not found. You will not be able to compress or "
"decompress textures on the GPU.")
endif()
endif(SUPPORT_D3D)
if(WANT_D3D9EX AND SUPPORT_D3D)
set(ALLEGRO_CFG_D3D9EX 1)
endif(WANT_D3D9EX AND SUPPORT_D3D)
endif(WIN32)
#-----------------------------------------------------------------------------#
#
# Main library
#
#-----------------------------------------------------------------------------#
if(WIN32 AND SHARED)
if(NOT SUPPORT_D3D OR NOT SUPPORT_OPENGL)
message("WARNING: "
"Both D3D and OpenGL should be present for the SHARED build "
" to ensure maximum DLL compatibility.")
endif(NOT SUPPORT_D3D OR NOT SUPPORT_OPENGL)
endif(WIN32 AND SHARED)
# List of source files need to compile Allegro in this configuration on
# this platform.
set(LIBRARY_SOURCES
${ALLEGRO_SRC_FILES}
)
# Libraries that we always need to link against on this platform.
set(PLATFORM_LIBS)
if(ALLEGRO_UNIX) # not MACOSX
list(APPEND LIBRARY_SOURCES ${ALLEGRO_SRC_UNIX_FILES})
list(APPEND PLATFORM_LIBS m ${CMAKE_THREAD_LIBS_INIT})
endif(ALLEGRO_UNIX)
if(SUPPORT_X11 AND NOT ALLEGRO_RASPBERRYPI)
list(APPEND LIBRARY_SOURCES ${ALLEGRO_SRC_X_FILES})
list(APPEND PLATFORM_LIBS ${X11_LIBRARIES})
endif(SUPPORT_X11 AND NOT ALLEGRO_RASPBERRYPI)
if(WIN32)
list(APPEND LIBRARY_SOURCES ${ALLEGRO_SRC_WIN_FILES})
list(APPEND PLATFORM_LIBS
kernel32 user32 gdi32 comdlg32 ole32 winmm psapi shlwapi
)
if(SUPPORT_D3D)
list(APPEND LIBRARY_SOURCES ${ALLEGRO_SRC_D3D_FILES})
list(APPEND PLATFORM_LIBS ${D3D9_LIBRARIES})
endif(SUPPORT_D3D)
if(SUPPORT_XINPUT)
list(APPEND PLATFORM_LIBS ${XINPUT_LIBRARIES})
endif(SUPPORT_XINPUT)
list(APPEND PLATFORM_LIBS ${DINPUT_LIBRARIES})
if(MINGW AND NOT SHARED)
list(APPEND PLATFORM_LIBS stdc++)
endif(MINGW AND NOT SHARED)
endif(WIN32)
if(MACOSX)
list(APPEND LIBRARY_SOURCES ${ALLEGRO_SRC_MACOSX_FILES})
find_library(APPKIT_LIBRARY AppKit)
find_library(IOKIT_LIBRARY IOKit)
list(APPEND PLATFORM_LIBS ${APPKIT_LIBRARY})
list(APPEND PLATFORM_LIBS ${IOKIT_LIBRARY})
endif(MACOSX)
if(IPHONE)
list(APPEND LIBRARY_SOURCES ${ALLEGRO_SRC_IPHONE_FILES})
endif(IPHONE)
if(ANDROID)
list(APPEND LIBRARY_SOURCES ${ALLEGRO_SRC_ANDROID_FILES})
list(APPEND PLATFORM_LIBS m log)
endif(ANDROID)
if(ALLEGRO_RASPBERRYPI)
list(APPEND LIBRARY_SOURCES ${ALLEGRO_SRC_RASPBERRYPI_FILES})
list(APPEND PLATFORM_LIBS ${X11_LIBRARIES})
endif(ALLEGRO_RASPBERRYPI)
if(SUPPORT_OPENGL)
list(APPEND LIBRARY_SOURCES ${ALLEGRO_SRC_OPENGL_FILES})
if(WIN32)
list(APPEND LIBRARY_SOURCES ${ALLEGRO_SRC_WGL_FILES})
endif(WIN32)
list(APPEND PLATFORM_LIBS ${OPENGL_LIBRARIES})
endif(SUPPORT_OPENGL)
if(SUPPORT_OPENGL AND WANT_SHADERS_GL)
set(ALLEGRO_CFG_SHADER_GLSL 1)
endif()
if(SUPPORT_D3D AND WANT_SHADERS_D3D AND D3DX9_FOUND)
set(ALLEGRO_CFG_SHADER_HLSL 1)
list(APPEND PLATFORM_LIBS "${D3DX9_LIBRARY}")
endif()
# Header files that we need to install.
set(ALLEGRO_PUBLIC_HEADERS
${ALLEGRO_INCLUDE_ALLEGRO_FILES}
${ALLEGRO_INCLUDE_ALLEGRO_INLINE_FILES}
${ALLEGRO_INCLUDE_ALLEGRO_INTERNAL_FILES}
${ALLEGRO_INCLUDE_ALLEGRO_PLATFORM_FILES}
)
if(WIN32)
list(APPEND ALLEGRO_PUBLIC_HEADERS
${ALLEGRO_INCLUDE_ALLEGRO_WINDOWS_FILES}
)
endif(WIN32)
if(MACOSX)
list(APPEND ALLEGRO_PUBLIC_HEADERS
${ALLEGRO_INCLUDE_ALLEGRO_MACOSX_FILES}
)
endif(MACOSX)
if(IPHONE)
list(APPEND ALLEGRO_PUBLIC_HEADERS
${ALLEGRO_INCLUDE_ALLEGRO_IPHONE_FILES}
)
endif(IPHONE)
if(SUPPORT_X11 AND NOT ALLEGRO_RASPBERRYPI)
list(APPEND ALLEGRO_PUBLIC_HEADERS
${ALLEGRO_INCLUDE_ALLEGRO_X_FILES}
)
endif(SUPPORT_X11 AND NOT ALLEGRO_RASPBERRYPI)
if(ANDROID)
list(APPEND ALLEGRO_PUBLIC_HEADERS ${ALLEGRO_INCLUDE_ALLEGRO_ANDROID_FILES})
endif(ANDROID)
if(SUPPORT_OPENGL)
list(APPEND ALLEGRO_PUBLIC_HEADERS
${ALLEGRO_INCLUDE_ALLEGRO_OPENGL_FILES}
${ALLEGRO_INCLUDE_ALLEGRO_OPENGL_GLEXT_FILES}
)
endif(SUPPORT_OPENGL)
foreach(genfile ${ALLEGRO_INCLUDE_ALLEGRO_PLATFORM_FILES_GENERATED})
list(APPEND ALLEGRO_PUBLIC_HEADERS
${CMAKE_CURRENT_BINARY_DIR}/${genfile}
)
endforeach(genfile)
if(ALLEGRO_SDL)
list(APPEND LIBRARY_SOURCES ${ALLEGRO_SRC_SDL_FILES})
list(APPEND PLATFORM_LIBS ${SDL2_LIBRARIES} pthread dl m)
include_directories(${SDL2_INCLUDE_DIR})
endif(ALLEGRO_SDL)
set_our_header_properties(${ALLEGRO_PUBLIC_HEADERS})
if(NOT WANT_MONOLITH)
# ALLEGRO_LIB_BUILD is defined for all Allegro sources (core and addon)
# ALLEGRO_SRC is defined only while compiling the core sources (its use is
# to get the DLL #defines right under Windows for creating DLL export
# functions when it is defined or import DLL functions when it is not).
add_our_library(allegro
Allegro-${ALLEGRO_SOVERSION}
"${LIBRARY_SOURCES};${ALLEGRO_PUBLIC_HEADERS}"
"${LIBRARY_CFLAGS} -DALLEGRO_SRC"
"${PLATFORM_LIBS}"
)
endif(NOT WANT_MONOLITH)
# Addons and examples should link with this target.
set(ALLEGRO_LINK_WITH allegro)
install_our_headers(${ALLEGRO_PUBLIC_HEADERS})
#-----------------------------------------------------------------------------#
#
# Add-ons
#
#-----------------------------------------------------------------------------#
set(MONOLITH_SOURCES ${LIBRARY_SOURCES})
add_subdirectory(addons)
if(WANT_MONOLITH)
include_directories(SYSTEM ${MONOLITH_INCLUDE_DIRECTORIES})
# For OSX, we need to set the header location inside the framework for each
# file (relative to the current directory, so for example when the
# AllegroImage framework is built we need to set the path for
# allegro5/allegro_image.h but when the AllegroMonolith framework is built
# we need to set the path for addons/image/allegro5/allegro_image.h -
# otherwise the header is silently missing).
set_our_header_properties(${MONOLITH_HEADERS})
link_directories(${MONOLITH_LINK_DIRECTORIES})
add_our_library(allegro_monolith
AllegroMonolith-${ALLEGRO_SOVERSION}
"${MONOLITH_SOURCES};${ALLEGRO_PUBLIC_HEADERS}"
"${LIBRARY_CFLAGS} -DALLEGRO_SRC ${MONOLITH_DEFINES}"
"${PLATFORM_LIBS};${MONOLITH_LIBRARIES}"
)
set(ALLEGRO_MONOLITH_LINK_WITH allegro_monolith)
endif(WANT_MONOLITH)
#-----------------------------------------------------------------------------#
#
# Produce configuration file
#
#-----------------------------------------------------------------------------#
if(NO_FPU)
set(ALLEGRO_CFG_NO_FPU 1)
endif(NO_FPU)
# All relevant variables must be set before here.
configure_file(
include/allegro5/platform/alplatf.h.cmake
${CMAKE_BINARY_DIR}/include/allegro5/platform/alplatf.h
)
#-----------------------------------------------------------------------------#
#
# Android
#
#-----------------------------------------------------------------------------#
if(WANT_ANDROID)
include(AndroidApp)
add_subdirectory(android)
endif(WANT_ANDROID)
#-----------------------------------------------------------------------------#
#
# Demo
#
#-----------------------------------------------------------------------------#
if(NOT MSVC80 AND WANT_DEMO) # XXX disabled because it breaks MSVC's intellisense for some reason
add_subdirectory(demos/cosmic_protector)
add_subdirectory(demos/speed)
add_subdirectory(demos/skater)
endif(NOT MSVC80 AND WANT_DEMO)
#-----------------------------------------------------------------------------#
#
# Examples
#
#-----------------------------------------------------------------------------#
if(WANT_EXAMPLES)
add_subdirectory(examples)
endif(WANT_EXAMPLES)
#-----------------------------------------------------------------------------#
#
# Tests
#
#-----------------------------------------------------------------------------#
if(WANT_TESTS)
add_subdirectory(tests)
endif(WANT_TESTS)
#-----------------------------------------------------------------------------#
#
# pkg-config files
#
#-----------------------------------------------------------------------------#
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(INCLUDE_PREFIX "\${prefix}")
# XXX these should be configurable separately
set(bindir "\${exec_prefix}/bin")
set(includedir "\${prefix}/include")
set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
if(WANT_MONOLITH)
set(PKG_CONFIG_FILES allegro_monolith)
else()
set(PKG_CONFIG_FILES allegro ${ADDON_PKG_CONFIG_FILES})
endif(WANT_MONOLITH)
# Install pkg-config files on Unix, and when cross-compiling on Unix.
if(UNIX AND NOT WANT_FRAMEWORKS AND NOT IPHONE)
set(INSTALL_PKG_CONFIG_FILES true)
endif()
if(CMAKE_CROSSCOMPILING AND CMAKE_HOST_UNIX)
set(INSTALL_PKG_CONFIG_FILES true)
endif()