forked from liballeg/allegro5
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
290 lines (234 loc) · 8.05 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
#-----------------------------------------------------------------------------#
#
# CMake setup
#
# Refer to https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/Life-Cycle-Considerations
cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR)
#-----------------------------------------------------------------------------#
#
# Build options
#
# Set the project name.
project(ALLEGRO C CXX)
if(WIN32)
enable_language(RC OPTIONAL)
endif(WIN32)
set(ALLEGRO_VERSION 4.4.3)
# Search in the `cmake' directory for additional CMake modules.
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# Put libraries into `lib'.
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
# Lists of all the source files.
include(FileList)
#-----------------------------------------------------------------------------#
#
# Unix platform checks
#
include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckCSourceCompiles)
include(CheckCSourceRuns)
include(FindPkgConfig)
include(TestBigEndian)
test_big_endian(ALLEGRO_BIG_ENDIAN)
if(NOT ALLEGRO_BIG_ENDIAN)
set(ALLEGRO_LITTLE_ENDIAN 1)
endif(NOT ALLEGRO_BIG_ENDIAN)
if(UNIX)
check_include_files(dirent.h ALLEGRO_HAVE_DIRENT_H)
check_include_files(inttypes.h ALLEGRO_HAVE_INTTYPES_H)
check_include_files(linux/awe_voice.h ALLEGRO_HAVE_LINUX_AWE_VOICE_H)
check_include_files(linux/input.h ALLEGRO_HAVE_LINUX_INPUT_H)
# On some systems including linux/joystick.h without sys/types.h results
# in conflicting definitions of fd_set.
check_include_files("sys/types.h;linux/joystick.h" ALLEGRO_HAVE_LINUX_JOYSTICK_H)
check_include_files(linux/soundcard.h ALLEGRO_HAVE_LINUX_SOUNDCARD_H)
check_include_files(machine/soundcard.h ALLEGRO_HAVE_MACHINE_SOUNDCARD_H)
check_include_files(soundcard.h ALLEGRO_HAVE_SOUNDCARD_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(sys/soundcard.h ALLEGRO_HAVE_SYS_SOUNDCARD_H)
check_include_files(sys/utsname.h ALLEGRO_HAVE_SYS_UTSNAME_H)
check_function_exists(getexecname ALLEGRO_HAVE_GETEXECNAME)
check_function_exists(memcmp ALLEGRO_HAVE_MEMCMP)
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(stricmp ALLEGRO_HAVE_STRICMP)
check_function_exists(strlwr ALLEGRO_HAVE_STRLWR)
check_function_exists(strupr ALLEGRO_HAVE_STRUPR)
check_function_exists(sysconf ALLEGRO_HAVE_SYSCONF)
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 <sys/procfs.h>
int main(void) {
struct prpsinfo psinfo;
psinfo.pr_argc = 0;
return 0;
}"
ALLEGRO_HAVE_PROCFS_ARGCV
)
check_c_source_compiles("
#include <unistd.h>
#include <sys/mman.h>
int main(void) {
void *x = MAP_FAILED;
}"
MAP_FAILED_DEFINED)
if(NOT MAP_FAILED_DEFINED)
set(MAP_FAILED "((void *) -1)")
endif()
check_c_source_runs("
static int notsupported = 1;
void test_ctor (void) __attribute__((constructor));
void test_ctor (void) { notsupported = 0; }
int main(void) { return (notsupported); }
"
ALLEGRO_USE_CONSTRUCTOR)
find_library(RT_LIBRARY rt)
check_c_source_compiles("
#include <time.h>
int main(void) {
struct timespec new_time_ns;
clock_gettime(CLOCK_MONOTONIC, &new_time_ns);
return 0;
}"
ALLEGRO_HAVE_POSIX_MONOTONIC_CLOCK
)
set(ALLEGRO_WITH_MAGIC_MAIN 0)
# XXX const
# XXX inline
# XXX size_t
endif(UNIX)
#-----------------------------------------------------------------------------#
#
# Compiler and platform setup
#
option(STRICT_WARN "Halt at warnings" off)
if(CMAKE_COMPILER_IS_GNUCC)
set(COMPILER_GCC 1)
set(ALLEGRO_GCC 1)
set(WFLAGS "-W -Wall -Wno-unused-parameter")
set(WFLAGS_C_ONLY "-Wdeclaration-after-statement")
if(STRICT_WARN)
set(WFLAGS "${WFLAGS} -Werror -Wpointer-arith")
set(WFLAGS_C_ONLY "${WFLAGS_C_ONLY} -Wmissing-declarations")
set(WFLAGS_C_ONLY "${WFLAGS_C_ONLY} -Wstrict-prototypes")
endif(STRICT_WARN)
endif(CMAKE_COMPILER_IS_GNUCC)
set(ALLEGRO_SDL2 1)
if(MSVC)
set(COMPILER_MSVC 1)
set(ALLEGRO_MSVC_SDL2 1)
set(WFLAGS "/W3 -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE")
endif(MSVC)
if(APPLE OR UNIX)
set(ALLEGRO_UNIX_SDL2 1)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WFLAGS} ${WFLAGS_C_ONLY}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WFLAGS} ${WFLAGS_CXX_ONLY}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DALLEGRO_STATICLINK")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DALLEGRO_STATICLINK")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUGMODE=1")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUGMODE=1")
list(APPEND CMAKE_BUILD_TYPES Profile)
mark_as_advanced(
CMAKE_C_FLAGS_PROFILE
CMAKE_CXX_FLAGS_PROFILE
CMAKE_EXE_LINKER_FLAGS_PROFILE
)
if(COMPILER_GCC)
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")
endif(COMPILER_GCC)
if(COMPILER_MSVC)
set(CMAKE_C_FLAGS_PROFILE "-Gd -Ox"
CACHE STRING "profiling flags")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE}"
CACHE STRING "profiling flags")
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "-profile"
CACHE STRING "profiling flags")
endif(COMPILER_MSVC)
#-----------------------------------------------------------------------------#
# Not sure if we want to support disabling these any more.
set(ALLEGRO_COLOR8 1)
set(ALLEGRO_COLOR16 1)
set(ALLEGRO_COLOR24 1)
set(ALLEGRO_COLOR32 1)
set(ALLEGRO_NO_ASM 1)
#-----------------------------------------------------------------------------#
#
# Platform drivers
#
find_package(SDL2 REQUIRED)
set(PLATFORM_SOURCES)
if(ALLEGRO_MSVC_SDL2)
list(APPEND PLATFORM_SOURCES ${ALLEGRO_SRC_WIN_SDL2_FILES})
else()
list(APPEND PLATFORM_SOURCES ${ALLEGRO_SRC_UNIX_SDL2_FILES})
endif()
#-----------------------------------------------------------------------------#
#
# Generate and install headers
#
configure_file(
include/allegro/platform/alplatf.h.cmake
include/allegro/platform/alplatf.h
@ONLY
)
if(UNIX)
configure_file(
include/allegro/platform/alunixac.h.cmake
include/allegro/platform/alunixac.h
)
endif(UNIX)
#-----------------------------------------------------------------------------#
#
# Main library
#
add_library(allegro
${ALLEGRO_SRC_FILES}
${ALLEGRO_SRC_C_FILES}
${PLATFORM_SOURCES}
${ALLEGRO_PUBLIC_HEADERS}
)
set_target_properties(allegro
PROPERTIES
DEBUG_POSTFIX -debug
PROFILE_POSTFIX -profile
)
set(allegro_OUTPUT_NAME alleg)
set_target_properties(allegro
PROPERTIES
COMPILE_FLAGS "-DALLEGRO_SRC"
LINK_FLAGS "${ALLEGRO_LINK_FLAGS}"
OUTPUT_NAME ${allegro_OUTPUT_NAME}
VERSION ${ALLEGRO_VERSION}
)
target_link_libraries(allegro ${SDL2_LIBRARY})
# Search for C header files in these directories.
message("${ALLEGRO_PUBLIC_HEADERS}")
target_include_directories(allegro
PRIVATE ${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include ${SDL2_INCLUDE_DIR}
PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include ${PROJECT_SOURCE_DIR}/include
)
#-----------------------------------------------------------------------------#
# vim: set sts=4 sw=4 et: