forked from libsdl-org/SDL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
324 lines (268 loc) · 8.01 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
cmake_minimum_required(VERSION 2.8.9...3.19)
project(SDL2 C)
#https://cmake.org/cmake/help/v2.8.9/cmake.html
#
# Options
#
option(OPENGL "Build with the OpenGL window")
if(APPLE)
option(UNIVERSAL "Build an AMD64/ARM64 universal binary")
option(CA "Build with CoreAudio")
option(METAL "Build with the Metal window and renderer")
endif()
#
# Variables
#
if(CA)
set(AUDIO 1)
endif()
# Project generator
if(CMAKE_GENERATOR MATCHES Ninja)
set(NINJA 1)
endif()
# Compiler
if(CMAKE_C_COMPILER_ID MATCHES Clang)
set(CLANG 1)
endif()
if(CMAKE_C_COMPILER_ID MATCHES GNU)
set(GCC 1)
endif()
if(CMAKE_C_COMPILER_ID MATCHES MSVC)
set(MSVC 1)
endif()
# OS
if(CMAKE_SYSTEM_NAME MATCHES Linux)
set(LINUX 1)
endif()
if(CMAKE_SYSTEM_NAME MATCHES FreeBSD)
set(FREEBSD 1)
endif()
if(CMAKE_SYSTEM_NAME MATCHES NetBSD)
set(NETBSD 1)
endif()
# Build type
set(IS_DEBUG
"$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>")
set(IS_RELEASE
"$<OR:$<CONFIG:Release>,$<CONFIG:MinSizeRel>,$<CONFIG:RelWithDebInfo>>")
#
# Sources
#
set(HERE ${CMAKE_CURRENT_LIST_DIR})
#
# Sources in src
#
set(SDL2_SOURCES ${SDL2_SOURCES}
${HERE}/src/SDL.c
${HERE}/src/SDL_assert.c
${HERE}/src/SDL_dataqueue.c
${HERE}/src/SDL_error.c
${HERE}/src/SDL_hints.c
${HERE}/src/SDL_log.c
${HERE}/src/atomic/SDL_atomic.c
${HERE}/src/atomic/SDL_spinlock.c
${HERE}/src/cpuinfo/SDL_cpuinfo.c
${HERE}/src/events/SDL_displayevents.c
${HERE}/src/events/SDL_events.c
${HERE}/src/events/SDL_keyboard.c
${HERE}/src/events/SDL_mouse.c
${HERE}/src/events/SDL_quit.c
${HERE}/src/events/SDL_windowevents.c
${HERE}/src/file/SDL_rwops.c
${HERE}/src/render/SDL_render.c
${HERE}/src/stdlib/SDL_crc32.c
${HERE}/src/stdlib/SDL_malloc.c
${HERE}/src/stdlib/SDL_qsort.c
${HERE}/src/stdlib/SDL_stdlib.c
${HERE}/src/stdlib/SDL_string.c
${HERE}/src/stdlib/SDL_strtokr.c
${HERE}/src/thread/SDL_thread.c
${HERE}/src/timer/SDL_timer.c
${HERE}/src/video/SDL_bmp.c
${HERE}/src/video/SDL_fillrect.c
${HERE}/src/video/SDL_pixels.c
${HERE}/src/video/SDL_rect.c
${HERE}/src/video/SDL_shape.c
${HERE}/src/video/SDL_surface.c
${HERE}/src/video/SDL_video.c
${HERE}/src/video/SDL_yuv.c
)
if(AUDIO)
set(SDL2_SOURCES ${SDL2_SOURCES}
${HERE}/src/audio/SDL_audio.c
${HERE}/src/audio/SDL_audiocvt.c
${HERE}/src/audio/SDL_audiotypecvt.c
${HERE}/src/audio/SDL_mixer.c
${HERE}/src/audio/SDL_wave.c
)
endif()
if(APPLE)
set(SDL2_SOURCES ${SDL2_SOURCES}
${HERE}/src/core/unix/SDL_poll.c
${HERE}/src/core/unix/SDL_poll.c
${HERE}/src/loadso/dlopen/SDL_sysloadso.c
${HERE}/src/thread/pthread/SDL_syscond.c
${HERE}/src/thread/pthread/SDL_sysmutex.c
${HERE}/src/thread/pthread/SDL_syssem.c
${HERE}/src/thread/pthread/SDL_systhread.c
${HERE}/src/thread/pthread/SDL_systls.c
${HERE}/src/timer/unix/SDL_systimer.c
${HERE}/src/timer/unix/SDL_systimer.c
${HERE}/src/video/cocoa/SDL_cocoaevents.m
${HERE}/src/video/cocoa/SDL_cocoakeyboard.m
${HERE}/src/video/cocoa/SDL_cocoamessagebox.m
${HERE}/src/video/cocoa/SDL_cocoamodes.m
${HERE}/src/video/cocoa/SDL_cocoamouse.m
${HERE}/src/video/cocoa/SDL_cocoashape.m
${HERE}/src/video/cocoa/SDL_cocoavideo.m
${HERE}/src/video/cocoa/SDL_cocoawindow.m
)
endif()
if(CA)
set(SDL2_SOURCES ${SDL2_SOURCES}
${HERE}/src/audio/coreaudio/SDL_coreaudio.m
)
endif()
if(APPLE AND OPENGL)
set(SDL2_SOURCES ${SDL2_SOURCES}
#${HERE}/src/render/opengl/SDL_render_gl.c
#${HERE}/src/render/opengl/SDL_shaders_gl.c
${HERE}/src/video/cocoa/SDL_cocoaopengl.m
)
endif()
if(METAL)
set(SDL2_SOURCES ${SDL2_SOURCES}
${HERE}/src/render/metal/SDL_render_metal.m
${HERE}/src/video/cocoa/SDL_cocoametalview.m
)
endif()
#
# Targets
#
add_library(sdl2 ${SDL2_SOURCES})
include_directories(include)
#
# Source groups for IDEs
#
if(NOT ${CMAKE_VERSION} VERSION_LESS 3.8.0)
get_target_property(SDL2_SOURCES sdl2 SOURCES)
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}
FILES ${SDL2_SOURCES}
)
endif()
#
# Preprocessor definitions
#
if(APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing -D_THREAD_SAFE -x objective-c -DHAVE_GCC_ATOMICS=1 -DSDL_ASSEMBLY_ROUTINES=1 -DSDL_DYNAMIC_API=0 -DSDL_LEAN_AND_MEAN=1 -DSDL_LOADSO_DLOPEN=1 -DSDL_TIMER_UNIX=1 -DSDL_VIDEO_DRIVER_COCOA=1")
endif()
if(APPLE AND OPENGL)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTSU_OPENGL")
endif()
if(METAL)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTSU_METAL")
endif()
if(NOT AUDIO)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDL_AUDIO_DISABLED=1")
endif()
if(CA)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDL_AUDIO_DRIVER_COREAUDIO=1")
endif()
#
# Compilation options
#
if(CLANG OR GCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
endif()
# Hide most symbols
if(CLANG OR GCC)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -fvisibility-inlines-hidden")
set(CMAKE_C_FLAGS_RELEASE
"${CMAKE_C_FLAGS_RELEASE} -fvisibility=hidden")
set(CMAKE_C_FLAGS_MINSIZEREL
"${CMAKE_C_FLAGS_MINSIZEREL} -fvisibility=hidden")
endif()
# Don't allow enum values outside enum range
if(CLANG OR GCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstrict-enums")
endif()
# Don't allow thread-safe function-local static variables
if(CLANG OR GCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-threadsafe-statics")
endif()
# Disable warnings
if(CLANG OR GCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
endif()
# Reduce code size
if(CLANG)
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -Oz")
endif()
# Enable floating point optimizations
if(CLANG OR GCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffast-math")
elseif(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fp:fast")
endif()
# Disable stack canary
if(CLANG OR GCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-stack-protector")
elseif(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /GS-")
endif()
# Disable frame pointer
if(CLANG OR GCC)
set(CMAKE_C_FLAGS_RELEASE
"${CMAKE_C_FLAGS_RELEASE} -fomit-frame-pointer")
set(CMAKE_C_FLAGS_MINSIZEREL
"${CMAKE_C_FLAGS_MINSIZEREL} -fomit-frame-pointer")
endif()
# Optimize at link time
if(CLANG OR GCC)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -flto")
set(CMAKE_C_FLAGS_RELWITHDEBINFO
"${CMAKE_C_FLAGS_RELWITHDEBINFO} -flto")
endif()
# Enable NDEBUG anything not a debug build.
if(${CMAKE_VERSION} VERSION_LESS 2.8.10)
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
else()
target_compile_definitions(sdl2 PUBLIC $<$<NOT:${IS_DEBUG}>:NDEBUG>)
endif()
# Enable RELEASE in anything with optimizations.
if(${CMAKE_VERSION} VERSION_LESS 2.8.10)
set(CMAKE_C_FLAGS_MINSIZEREL
"${CMAKE_C_FLAGS_MINSIZEREL} -DRELEASE")
set(CMAKE_C_FLAGS_RELEASE
"${CMAKE_C_FLAGS_RELEASE} -DRELEASE")
set(CMAKE_C_FLAGS_RELWITHDEBINFO
"${CMAKE_C_FLAGS_MINSIZEREL} -DRELEASE")
else()
target_compile_definitions(sdl2 PUBLIC $<${IS_RELEASE}:RELEASE>)
endif()
# Enable color within compiler's output
if(NOT DEFINED ENV{CI})
if(NINJA AND CLANG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcolor-diagnostics")
endif()
if(NINJA AND GCC AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=always")
endif()
endif()
if(UNIVERSAL)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch x86_64 -arch arm64")
endif()
if(APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.11")
endif()
#
# Policies
#
# Do not turn on -rdynamic. Also solved with CMP0065 in CMake 3.4
# FIXME: Apply it only to local targets, or possibly just try to
# remove -rdynamic from these.
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")