1 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
2 message(FATAL_ERROR "Prevented in-tree built. Please create a build directory outside of the SDL source code and call cmake from there")
5 cmake_minimum_required(VERSION 2.8)
7 include(CheckFunctionExists)
8 include(CheckLibraryExists)
9 include(CheckIncludeFiles)
10 include(CheckIncludeFile)
11 include(CheckSymbolExists)
12 include(CheckCSourceRuns)
13 include(CheckCCompilerFlag)
14 include(CheckTypeSize)
15 include(CheckStructHasMember)
16 include(CMakeDependentOption)
17 include(FindPkgConfig)
18 set(CMAKE_MODULE_PATH "${SDL2_SOURCE_DIR}/cmake")
19 include(${SDL2_SOURCE_DIR}/cmake/macros.cmake)
20 include(${SDL2_SOURCE_DIR}/cmake/sdlchecks.cmake)
23 # Edit include/SDL_version.h and change the version, then:
24 # SDL_MICRO_VERSION += 1;
25 # SDL_INTERFACE_AGE += 1;
26 # SDL_BINARY_AGE += 1;
27 # if any functions have been added, set SDL_INTERFACE_AGE to 0.
28 # if backwards compatibility has been broken,
29 # set SDL_BINARY_AGE and SDL_INTERFACE_AGE to 0.
30 set(SDL_MAJOR_VERSION 2)
31 set(SDL_MINOR_VERSION 0)
32 set(SDL_MICRO_VERSION 4)
33 set(SDL_INTERFACE_AGE 0)
35 set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}")
37 # Calculate a libtool-like version number
38 math(EXPR LT_CURRENT "${SDL_MICRO_VERSION} - ${SDL_INTERFACE_AGE}")
39 math(EXPR LT_AGE "${SDL_BINARY_AGE} - ${SDL_INTERFACE_AGE}")
40 math(EXPR LT_MAJOR "${LT_CURRENT}- ${LT_AGE}")
41 set(LT_REVISION "${SDL_INTERFACE_AGE}")
42 set(LT_RELEASE "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}")
43 set(LT_VERSION "${LT_MAJOR}.${LT_AGE}.${LT_REVISION}")
45 message(STATUS "${LT_VERSION} :: ${LT_AGE} :: ${LT_REVISION} :: ${LT_CURRENT} :: ${LT_RELEASE}")
47 # General settings & flags
48 set(LIBRARY_OUTPUT_DIRECTORY "build")
49 # Check for 64 or 32 bit
50 set(SIZEOF_VOIDP ${CMAKE_SIZEOF_VOID_P})
51 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
53 set(PROCESSOR_ARCH "x64")
56 set(PROCESSOR_ARCH "x86")
68 elseif(UNIX AND NOT APPLE)
69 if(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
71 elseif(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*")
73 elseif(CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*")
75 elseif(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
77 elseif(CMAKE_SYSTEM_NAME MATCHES ".*GNU.*")
79 elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
81 elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")
83 elseif(CMAKE_SYSTEM_NAME MATCHES "SYSV5.*")
85 elseif(CMAKE_SYSTEM_NAME MATCHES "Solaris.*")
87 elseif(CMAKE_SYSTEM_NAME MATCHES "HP-UX.*")
89 elseif(CMAKE_SYSTEM_NAME MATCHES "AIX.*")
91 elseif(CMAKE_SYSTEM_NAME MATCHES "Minix.*")
95 if(CMAKE_SYSTEM_NAME MATCHES ".*Darwin.*")
97 elseif(CMAKE_SYSTEM_NAME MATCHES ".*MacOS.*")
101 elseif(CMAKE_SYSTEM_NAME MATCHES "BeOS.*")
102 message_error("BeOS support has been removed as of SDL 2.0.2.")
103 elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku.*")
107 # Don't mistake osx for unix
108 if(UNIX AND NOT APPLE)
115 set(UNIX_OR_MAC_SYS ON)
117 set(UNIX_OR_MAC_SYS OFF)
120 if (UNIX_OR_MAC_SYS AND NOT EMSCRIPTEN) # JavaScript does not yet have threading support, so disable pthreads when building for Emscripten.
121 set(SDL_PTHREADS_ENABLED_BY_DEFAULT ON)
123 set(SDL_PTHREADS_ENABLED_BY_DEFAULT OFF)
126 # Default option knobs
128 set(OPT_DEF_SSEMATH ON)
130 if(UNIX OR MINGW OR MSYS)
135 if(CMAKE_COMPILER_IS_GNUCC)
137 set(OPT_DEF_ASM TRUE)
138 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
140 set(OPT_DEF_ASM TRUE)
141 elseif(MSVC_VERSION GREATER 1400) # VisualStudio 8.0+
142 set(OPT_DEF_ASM TRUE)
143 #set(CMAKE_C_FLAGS "/ZI /WX- /
145 set(OPT_DEF_ASM FALSE)
148 # Default flags, if not set otherwise
149 if("$ENV{CFLAGS}" STREQUAL "")
150 if(USE_GCC OR USE_CLANG)
151 set(CMAKE_C_FLAGS "-g -O3")
154 set(CMAKE_C_FLAGS "$ENV{CFLAGS}")
155 list(APPEND EXTRA_CFLAGS "$ENV{CFLAGS}")
157 if(NOT ("$ENV{CFLAGS}" STREQUAL "")) # Hackish, but does the trick on Win32
158 list(APPEND EXTRA_LDFLAGS "$ENV{LDFLAGS}")
162 option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
163 if(FORCE_STATIC_VCRT)
165 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
166 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
167 if(${flag_var} MATCHES "/MD")
168 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
173 # Make sure /RTC1 is disabled, otherwise it will use functions from the CRT
175 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
176 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
177 string(REGEX REPLACE "/RTC(su|[1su])" "" ${flag_var} "${${flag_var}}")
181 # Those are used for pkg-config and friends, so that the SDL2.pc, sdl2-config,
182 # etc. are created correctly.
183 set(SDL_LIBS "-lSDL2")
186 # Emscripten toolchain has a nonempty default value for this, and the checks
187 # in this file need to change that, so remember the original value, and
188 # restore back to that afterwards. For check_function_exists() to work in
189 # Emscripten, this value must be at its default value.
190 set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
193 # We build SDL on cygwin without the UNIX emulation layer
194 include_directories("-I/usr/include/mingw")
195 set(CMAKE_REQUIRED_FLAGS "-mno-cygwin")
196 check_c_source_compiles("int main(int argc, char **argv) {}"
198 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
199 if(HAVE_GCC_NO_CYGWIN)
200 list(APPEND EXTRA_LDFLAGS "-mno-cygwin")
201 list(APPEND SDL_LIBS "-mno-cygwin")
203 set(SDL_CFLAGS "${SDL_CFLAGS} -I/usr/include/mingw")
206 add_definitions(-DUSING_GENERATED_CONFIG_H)
208 include_directories(${SDL2_BINARY_DIR}/include ${SDL2_SOURCE_DIR}/include)
210 # All these ENABLED_BY_DEFAULT vars will default to ON if not specified, so
211 # you only need to have a platform override them if they are disabling.
212 set(OPT_DEF_ASM TRUE)
214 # Set up default values for the currently supported set of subsystems:
215 # Emscripten/Javascript does not have assembly support, a dynamic library
216 # loading architecture, low-level CPU inspection or multithreading.
217 set(OPT_DEF_ASM FALSE)
218 set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
219 set(SDL_ATOMIC_ENABLED_BY_DEFAULT OFF)
220 set(SDL_THREADS_ENABLED_BY_DEFAULT OFF)
221 set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF)
222 set(SDL_CPUINFO_ENABLED_BY_DEFAULT OFF)
223 set(SDL_DLOPEN_ENABLED_BY_DEFAULT OFF)
226 if (NOT DEFINED SDL_SHARED_ENABLED_BY_DEFAULT)
227 set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
231 Atomic Audio Video Render Events Joystick Haptic Power Threads Timers
232 File Loadso CPUinfo Filesystem Dlopen)
233 foreach(_SUB ${SDL_SUBSYSTEMS})
234 string(TOUPPER ${_SUB} _OPT)
235 if (NOT DEFINED SDL_${_OPT}_ENABLED_BY_DEFAULT)
236 set(SDL_${_OPT}_ENABLED_BY_DEFAULT ON)
238 option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ${SDL_${_OPT}_ENABLED_BY_DEFAULT})
241 option_string(ASSERTIONS "Enable internal sanity checks (auto/disabled/release/enabled/paranoid)" "auto")
242 #set_option(DEPENDENCY_TRACKING "Use gcc -MMD -MT dependency tracking" ON)
243 set_option(LIBC "Use the system C library" ${OPT_DEF_LIBC})
244 set_option(GCC_ATOMICS "Use gcc builtin atomics" ${USE_GCC})
245 set_option(ASSEMBLY "Enable assembly routines" ${OPT_DEF_ASM})
246 set_option(SSEMATH "Allow GCC to use SSE floating point math" ${OPT_DEF_SSEMATH})
247 set_option(MMX "Use MMX assembly routines" ${OPT_DEF_ASM})
248 set_option(3DNOW "Use 3Dnow! MMX assembly routines" ${OPT_DEF_ASM})
249 set_option(SSE "Use SSE assembly routines" ${OPT_DEF_ASM})
250 set_option(SSE2 "Use SSE2 assembly routines" ${OPT_DEF_SSEMATH})
251 set_option(ALTIVEC "Use Altivec assembly routines" ${OPT_DEF_ASM})
252 set_option(DISKAUDIO "Support the disk writer audio driver" ON)
253 set_option(DUMMYAUDIO "Support the dummy audio driver" ON)
254 set_option(VIDEO_DIRECTFB "Use DirectFB video driver" OFF)
255 dep_option(DIRECTFB_SHARED "Dynamically load directfb support" ON "VIDEO_DIRECTFB" OFF)
256 set_option(FUSIONSOUND "Use FusionSound audio driver" OFF)
257 dep_option(FUSIONSOUND_SHARED "Dynamically load fusionsound audio support" ON "FUSIONSOUND" OFF)
258 set_option(VIDEO_DUMMY "Use dummy video driver" ON)
259 set_option(VIDEO_OPENGL "Include OpenGL support" ON)
260 set_option(VIDEO_OPENGLES "Include OpenGL ES support" ON)
261 set_option(VIDEO_VULKAN "Include vulkan support" ON)
262 set_option(PTHREADS "Use POSIX threads for multi-threading" ${SDL_PTHREADS_ENABLED_BY_DEFAULT})
263 dep_option(PTHREADS_SEM "Use pthread semaphores" ON "PTHREADS" OFF)
264 set_option(SDL_DLOPEN "Use dlopen for shared object loading" ${SDL_DLOPEN_ENABLED_BY_DEFAULT})
265 set_option(OSS "Support the OSS audio API" ${UNIX_SYS})
266 set_option(ALSA "Support the ALSA audio API" ${UNIX_SYS})
267 dep_option(ALSA_SHARED "Dynamically load ALSA audio support" ON "ALSA" OFF)
268 set_option(ESD "Support the Enlightened Sound Daemon" ${UNIX_SYS})
269 dep_option(ESD_SHARED "Dynamically load ESD audio support" ON "ESD" OFF)
270 set_option(PULSEAUDIO "Use PulseAudio" ${UNIX_SYS})
271 dep_option(PULSEAUDIO_SHARED "Dynamically load PulseAudio support" ON "PULSEAUDIO" OFF)
272 set_option(ARTS "Support the Analog Real Time Synthesizer" ${UNIX_SYS})
273 dep_option(ARTS_SHARED "Dynamically load aRts audio support" ON "ARTS" OFF)
274 set_option(NAS "Support the NAS audio API" ${UNIX_SYS})
275 set_option(NAS_SHARED "Dynamically load NAS audio API" ${UNIX_SYS})
276 set_option(SNDIO "Support the sndio audio API" ${UNIX_SYS})
277 set_option(RPATH "Use an rpath when linking SDL" ${UNIX_SYS})
278 set_option(CLOCK_GETTIME "Use clock_gettime() instead of gettimeofday()" OFF)
279 set_option(INPUT_TSLIB "Use the Touchscreen library for input" ${UNIX_SYS})
280 set_option(VIDEO_X11 "Use X11 video driver" ${UNIX_SYS})
281 set_option(VIDEO_WAYLAND "Use Wayland video driver" ${UNIX_SYS})
282 dep_option(WAYLAND_SHARED "Dynamically load Wayland support" ON "VIDEO_WAYLAND" OFF)
283 dep_option(VIDEO_WAYLAND_QT_TOUCH "QtWayland server support for Wayland video driver" ON "VIDEO_WAYLAND" OFF)
284 set_option(VIDEO_MIR "Use Mir video driver" ${UNIX_SYS})
285 dep_option(MIR_SHARED "Dynamically load Mir support" ON "VIDEO_MIR" OFF)
286 set_option(VIDEO_RPI "Use Raspberry Pi video driver" ${UNIX_SYS})
287 dep_option(X11_SHARED "Dynamically load X11 support" ON "VIDEO_X11" OFF)
288 set_option(VIDEO_TIZEN "Use Tizen video driver" ${UNIX_SYS})
289 dep_option(TIZEN_SHARED "Dynamically load Tizen support" ON "VIDEO_TIZEN" OFF)
290 set(SDL_X11_OPTIONS Xcursor Xinerama XInput Xrandr Xscrnsaver XShape Xvm)
291 foreach(_SUB ${SDL_X11_OPTIONS})
292 string(TOUPPER "VIDEO_X11_${_SUB}" _OPT)
293 dep_option(${_OPT} "Enable ${_SUB} support" ON "VIDEO_X11" OFF)
295 set_option(VIDEO_COCOA "Use Cocoa video driver" ${APPLE})
296 set_option(DIRECTX "Use DirectX for Windows audio/video" ${WINDOWS})
297 set_option(RENDER_D3D "Enable the Direct3D render driver" ${WINDOWS})
298 set_option(VIDEO_VIVANTE "Use Vivante EGL video driver" ${UNIX_SYS})
300 # TODO: We should (should we?) respect cmake's ${BUILD_SHARED_LIBS} flag here
301 # The options below are for compatibility to configure's default behaviour.
302 set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared version of the library")
303 set(SDL_STATIC ON CACHE BOOL "Build a static version of the library")
305 # General source files
306 file(GLOB SOURCE_FILES
307 ${SDL2_SOURCE_DIR}/src/*.c
308 ${SDL2_SOURCE_DIR}/src/atomic/*.c
309 ${SDL2_SOURCE_DIR}/src/audio/*.c
310 ${SDL2_SOURCE_DIR}/src/cpuinfo/*.c
311 ${SDL2_SOURCE_DIR}/src/dynapi/*.c
312 ${SDL2_SOURCE_DIR}/src/events/*.c
313 ${SDL2_SOURCE_DIR}/src/file/*.c
314 ${SDL2_SOURCE_DIR}/src/libm/*.c
315 ${SDL2_SOURCE_DIR}/src/render/*.c
316 ${SDL2_SOURCE_DIR}/src/render/*/*.c
317 ${SDL2_SOURCE_DIR}/src/stdlib/*.c
318 ${SDL2_SOURCE_DIR}/src/thread/*.c
319 ${SDL2_SOURCE_DIR}/src/timer/*.c
320 ${SDL2_SOURCE_DIR}/src/video/*.c)
323 if(ASSERTIONS STREQUAL "auto")
324 # Do nada - use optimization settings to determine the assertion level
325 elseif(ASSERTIONS STREQUAL "disabled")
326 set(SDL_DEFAULT_ASSERT_LEVEL 0)
327 elseif(ASSERTIONS STREQUAL "release")
328 set(SDL_DEFAULT_ASSERT_LEVEL 1)
329 elseif(ASSERTIONS STREQUAL "enabled")
330 set(SDL_DEFAULT_ASSERT_LEVEL 2)
331 elseif(ASSERTIONS STREQUAL "paranoid")
332 set(SDL_DEFAULT_ASSERT_LEVEL 3)
334 message_error("unknown assertion level")
336 set(HAVE_ASSERTIONS ${ASSERTIONS})
338 # Compiler option evaluation
339 if(USE_GCC OR USE_CLANG)
340 if(DEPENDENCY_TRACKING)
341 check_c_source_compiles("
342 #if !defined(__GNUC__) || __GNUC__ < 3
343 #error Dependency tracking requires GCC 3.0 or newer
345 int main(int argc, char **argv) { }" HAVE_DEPENDENCY_TRACKING)
349 check_c_source_compiles("int main(int argc, char **argv) {
352 __sync_lock_test_and_set(&a, 4);
353 __sync_lock_test_and_set(&x, y);
354 __sync_fetch_and_add(&a, 1);
355 __sync_bool_compare_and_swap(&a, 5, 10);
356 __sync_bool_compare_and_swap(&x, y, z); }" HAVE_GCC_ATOMICS)
357 if(NOT HAVE_GCC_ATOMICS)
358 check_c_source_compiles("int main(int argc, char **argv) {
360 __sync_lock_test_and_set(&a, 1);
361 __sync_lock_release(&a); }" HAVE_GCC_SYNC_LOCK_TEST_AND_SET)
365 set(CMAKE_REQUIRED_FLAGS "-mpreferred-stack-boundary=2")
366 check_c_source_compiles("int x = 0; int main(int argc, char **argv) {}"
367 HAVE_GCC_PREFERRED_STACK_BOUNDARY)
368 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
370 set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden -Werror")
371 check_c_source_compiles("
372 #if !defined(__GNUC__) || __GNUC__ < 4
373 #error SDL only uses visibility attributes in GCC 4 or newer
375 int main(int argc, char **argv) {}" HAVE_GCC_FVISIBILITY)
376 if(HAVE_GCC_FVISIBILITY)
377 list(APPEND EXTRA_CFLAGS "-fvisibility=hidden")
379 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
381 check_c_compiler_flag(-Wall HAVE_GCC_WALL)
383 list(APPEND EXTRA_CFLAGS "-Wall")
385 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")
388 check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW)
390 list(APPEND EXTRA_CFLAGS "-Wshadow")
393 set(CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined")
394 check_c_compiler_flag("" HAVE_NO_UNDEFINED)
395 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
396 if(HAVE_NO_UNDEFINED)
397 list(APPEND EXTRA_LDFLAGS "-Wl,--no-undefined")
402 if(USE_GCC OR USE_CLANG)
403 set(SDL_ASSEMBLY_ROUTINES 1)
404 # TODO: Those all seem to be quite GCC specific - needs to be
405 # reworked for better compiler support
406 set(HAVE_ASSEMBLY TRUE)
408 set(CMAKE_REQUIRED_FLAGS "-mmmx")
409 check_c_source_compiles("
412 #ifdef __MINGW64_VERSION_MAJOR
415 #include <mmintrin.h>
418 #include <mmintrin.h>
421 #error Assembler CPP flag not enabled
423 int main(int argc, char **argv) { }" HAVE_MMX)
425 list(APPEND EXTRA_CFLAGS "-mmmx")
427 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
431 set(CMAKE_REQUIRED_FLAGS "-m3dnow")
432 check_c_source_compiles("
435 #error Assembler CPP flag not enabled
437 int main(int argc, char **argv) {
442 list(APPEND EXTRA_CFLAGS "-m3dnow")
444 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
448 set(CMAKE_REQUIRED_FLAGS "-msse")
449 check_c_source_compiles("
452 #ifdef __MINGW64_VERSION_MAJOR
455 #include <xmmintrin.h>
458 #include <xmmintrin.h>
461 #error Assembler CPP flag not enabled
463 int main(int argc, char **argv) { }" HAVE_SSE)
465 list(APPEND EXTRA_CFLAGS "-msse")
467 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
471 set(CMAKE_REQUIRED_FLAGS "-msse2")
472 check_c_source_compiles("
475 #ifdef __MINGW64_VERSION_MAJOR
478 #include <emmintrin.h>
481 #include <emmintrin.h>
484 #error Assembler CPP flag not enabled
486 int main(int argc, char **argv) { }" HAVE_SSE2)
488 list(APPEND EXTRA_CFLAGS "-msse2")
490 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
496 list(APPEND EXTRA_CFLAGS "-mfpmath=387")
498 set(HAVE_SSEMATH TRUE)
503 set(CMAKE_REQUIRED_FLAGS "-maltivec")
504 check_c_source_compiles("
506 vector unsigned int vzero() {
507 return vec_splat_u32(0);
509 int main(int argc, char **argv) { }" HAVE_ALTIVEC_H_HDR)
510 check_c_source_compiles("
511 vector unsigned int vzero() {
512 return vec_splat_u32(0);
514 int main(int argc, char **argv) { }" HAVE_ALTIVEC)
515 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
516 if(HAVE_ALTIVEC OR HAVE_ALTIVEC_H_HDR)
517 set(HAVE_ALTIVEC TRUE) # if only HAVE_ALTIVEC_H_HDR is set
518 list(APPEND EXTRA_CFLAGS "-maltivec")
519 set(SDL_ALTIVEC_BLITTERS 1)
520 if(HAVE_ALTIVEC_H_HDR)
521 set(HAVE_ALTIVEC_H 1)
525 elseif(MSVC_VERSION GREATER 1500)
526 # TODO: SDL_cpuinfo.h needs to support the user's configuration wish
527 # for MSVC - right now it is always activated
534 set(SDL_ASSEMBLY_ROUTINES 1)
538 # if(USE_GCC OR USE_CLANG)
539 # list(APPEND EXTRA_CFLAGS "-mno-sse" "-mno-sse2" "-mno-mmx")
543 # TODO: Can't deactivate on FreeBSD? w/o LIBC, SDL_stdinc.h can't define
546 if(WINDOWS AND NOT MINGW)
548 foreach(_HEADER stdio.h string.h ctype.h math.h)
549 string(TOUPPER "HAVE_${_HEADER}" _UPPER)
550 string(REPLACE "." "_" _HAVE_H ${_UPPER})
555 malloc calloc realloc free qsort abs memset memcpy memmove memcmp
556 strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
557 _ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp
558 _stricmp _strnicmp sscanf atan atan2 acos asin ceil copysign cos
559 cosf fabs floor log pow scalbn sin sinf sqrt sqrtf tan tanf)
560 string(TOUPPER ${_FN} _UPPER)
561 set(HAVE_${_UPPER} 1)
563 if(NOT CYGWIN AND NOT MINGW)
567 add_definitions(-D_USE_MATH_DEFINES) # needed for M_PI
571 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
573 stdio.h stdlib.h stddef.h stdarg.h malloc.h memory.h string.h
574 strings.h inttypes.h stdint.h ctype.h math.h iconv.h signal.h)
575 string(TOUPPER "HAVE_${_HEADER}" _UPPER)
576 string(REPLACE "." "_" _HAVE_H ${_UPPER})
577 check_include_file("${_HEADER}" ${_HAVE_H})
580 check_include_files("dlfcn.h;stdint.h;stddef.h;inttypes.h;stdlib.h;strings.h;string.h;float.h" STDC_HEADERS)
581 check_type_size("size_t" SIZEOF_SIZE_T)
582 check_symbol_exists(M_PI math.h HAVE_M_PI)
583 # TODO: refine the mprotect check
584 check_c_source_compiles("#include <sys/types.h>
585 #include <sys/mman.h>
586 int main() { }" HAVE_MPROTECT)
588 strtod malloc calloc realloc free getenv setenv putenv unsetenv
589 qsort abs bcopy memset memcpy memmove memcmp strlen strlcpy strlcat
590 strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
591 _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull
592 atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp
593 vsscanf vsnprintf fseeko fseeko64 sigaction setjmp
594 nanosleep sysconf sysctlbyname
596 string(TOUPPER ${_FN} _UPPER)
597 set(_HAVEVAR "HAVE_${_UPPER}")
598 check_function_exists("${_FN}" ${_HAVEVAR})
601 check_library_exists(m pow "" HAVE_LIBM)
603 set(CMAKE_REQUIRED_LIBRARIES m)
605 atan atan2 ceil copysign cos cosf fabs floor log pow scalbn sin
606 sinf sqrt sqrtf tan tanf acos asin)
607 string(TOUPPER ${_FN} _UPPER)
608 set(_HAVEVAR "HAVE_${_UPPER}")
609 check_function_exists("${_FN}" ${_HAVEVAR})
611 set(CMAKE_REQUIRED_LIBRARIES)
612 list(APPEND EXTRA_LIBS m)
615 check_library_exists(iconv iconv_open "" HAVE_LIBICONV)
617 list(APPEND EXTRA_LIBS iconv)
622 check_include_file(alloca.h HAVE_ALLOCA_H)
623 check_function_exists(alloca HAVE_ALLOCA)
629 check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION)
639 # Enable/disable various subsystems of the SDL library
640 foreach(_SUB ${SDL_SUBSYSTEMS})
641 string(TOUPPER ${_SUB} _OPT)
643 set(SDL_${_OPT}_DISABLED 1)
647 file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/*.c)
648 set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
652 # Haptic requires some private functions from the joystick subsystem.
653 message_error("SDL_HAPTIC requires SDL_JOYSTICK, which is not enabled")
655 file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/*.c)
656 set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
659 file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/*.c)
660 set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
662 # TODO: in configure.in, the test for LOADSO and SDL_DLOPEN is a bit weird:
663 # if LOADSO is not wanted, SDL_LOADSO_DISABLED is set
664 # If however on Unix or APPLE dlopen() is detected via CheckDLOPEN(),
665 # SDL_LOADSO_DISABLED will not be set, regardless of the LOADSO settings
667 # General SDL subsystem options, valid for all platforms
669 # CheckDummyAudio/CheckDiskAudio - valid for all platforms
671 set(SDL_AUDIO_DRIVER_DUMMY 1)
672 file(GLOB DUMMYAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dummy/*.c)
673 set(SOURCE_FILES ${SOURCE_FILES} ${DUMMYAUDIO_SOURCES})
674 set(HAVE_DUMMYAUDIO TRUE)
677 set(SDL_AUDIO_DRIVER_DISK 1)
678 file(GLOB DISKAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/disk/*.c)
679 set(SOURCE_FILES ${SOURCE_FILES} ${DISKAUDIO_SOURCES})
680 set(HAVE_DISKAUDIO TRUE)
685 # Relevant for Unix/Darwin only
693 set(SDL_VIDEO_DRIVER_DUMMY 1)
694 file(GLOB VIDEO_DUMMY_SOURCES ${SDL2_SOURCE_DIR}/src/video/dummy/*.c)
695 set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_DUMMY_SOURCES})
696 set(HAVE_VIDEO_DUMMY TRUE)
697 set(HAVE_SDL_VIDEO TRUE)
702 file(GLOB ANDROID_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/android/*.c)
703 set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_CORE_SOURCES})
704 file(GLOB ANDROID_MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/android/*.c)
705 set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_MAIN_SOURCES})
707 set(SDL_AUDIO_DRIVER_ANDROID 1)
708 file(GLOB ANDROID_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/android/*.c)
709 set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_AUDIO_SOURCES})
710 set(HAVE_SDL_AUDIO TRUE)
713 set(SDL_FILESYSTEM_ANDROID 1)
714 file(GLOB ANDROID_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/android/*.c)
715 set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_FILESYSTEM_SOURCES})
716 set(HAVE_SDL_FILESYSTEM TRUE)
719 set(SDL_JOYSTICK_ANDROID 1)
720 file(GLOB ANDROID_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/android/*.c)
721 set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_JOYSTICK_SOURCES})
722 set(HAVE_SDL_JOYSTICK TRUE)
725 set(SDL_POWER_ANDROID 1)
726 file(GLOB ANDROID_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/android/*.c)
727 set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_POWER_SOURCES})
728 set(HAVE_SDL_POWER TRUE)
731 set(SDL_VIDEO_DRIVER_ANDROID 1)
732 file(GLOB ANDROID_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/android/*.c)
733 set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_VIDEO_SOURCES})
734 set(HAVE_SDL_VIDEO TRUE)
738 set(SDL_VIDEO_OPENGL_EGL 1)
739 set(HAVE_VIDEO_OPENGLES TRUE)
740 set(SDL_VIDEO_OPENGL_ES2 1)
741 set(SDL_VIDEO_RENDER_OGL_ES2 1)
744 list(APPEND EXTRA_LDFLAGS "-Wl,--undefined=Java_org_libsdl_app_SDLActivity_nativeInit")
747 # Platform-specific options and settings
749 # Hide noisy warnings that intend to aid mostly during initial stages of porting a new
750 # project. Uncomment at will for verbose cross-compiling -I/../ path info.
751 add_definitions(-Wno-warn-absolute-paths)
753 set(SDL_AUDIO_DRIVER_EMSCRIPTEN 1)
754 file(GLOB EM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/emscripten/*.c)
755 set(SOURCE_FILES ${SOURCE_FILES} ${EM_AUDIO_SOURCES})
756 set(HAVE_SDL_AUDIO TRUE)
759 set(SDL_FILESYSTEM_EMSCRIPTEN 1)
760 file(GLOB EM_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/emscripten/*.c)
761 set(SOURCE_FILES ${SOURCE_FILES} ${EM_FILESYSTEM_SOURCES})
762 set(HAVE_SDL_FILESYSTEM TRUE)
765 set(SDL_JOYSTICK_EMSCRIPTEN 1)
766 file(GLOB EM_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/emscripten/*.c)
767 set(SOURCE_FILES ${SOURCE_FILES} ${EM_JOYSTICK_SOURCES})
768 set(HAVE_SDL_JOYSTICK TRUE)
771 set(SDL_POWER_EMSCRIPTEN 1)
772 file(GLOB EM_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/emscripten/*.c)
773 set(SOURCE_FILES ${SOURCE_FILES} ${EM_POWER_SOURCES})
774 set(HAVE_SDL_POWER TRUE)
777 set(SDL_VIDEO_DRIVER_EMSCRIPTEN 1)
778 file(GLOB EM_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/emscripten/*.c)
779 set(SOURCE_FILES ${SOURCE_FILES} ${EM_VIDEO_SOURCES})
780 set(HAVE_SDL_VIDEO TRUE)
784 set(SDL_VIDEO_OPENGL_EGL 1)
785 set(HAVE_VIDEO_OPENGLES TRUE)
786 set(SDL_VIDEO_OPENGL_ES2 1)
787 set(SDL_VIDEO_RENDER_OGL_ES2 1)
790 elseif(UNIX AND NOT APPLE)
792 if(SYSV5 OR SOLARIS OR HPUX)
793 set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
794 file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
795 set(SOURCE_FILES ${SOURCE_FILES} ${SUN_AUDIO_SOURCES})
796 set(HAVE_SDL_AUDIO TRUE)
797 elseif(NETBSD OR OPENBSD)
798 set(SDL_AUDIO_DRIVER_BSD 1)
799 file(GLOB BSD_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/bsd/*.c)
800 set(SOURCE_FILES ${SOURCE_FILES} ${BSD_AUDIO_SOURCES})
801 set(HAVE_SDL_AUDIO TRUE)
803 set(SDL_AUDIO_DRIVER_PAUDIO 1)
804 file(GLOB AIX_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/paudio/*.c)
805 set(SOURCE_FILES ${SOURCE_FILES} ${AIX_AUDIO_SOURCES})
806 set(HAVE_SDL_AUDIO TRUE)
819 # Need to check for Raspberry PI first and add platform specific compiler flags, otherwise the test for GLES fails!
831 check_c_source_compiles("
832 #include <linux/input.h>
834 #error EVIOCGNAME() ioctl not available
836 int main(int argc, char** argv) {}" HAVE_INPUT_EVENTS)
838 check_c_source_compiles("
839 #include <linux/kd.h>
840 #include <linux/keyboard.h>
842 int main(int argc, char **argv)
845 kbe.kb_table = KG_CTRL;
846 ioctl(0, KDGKBENT, &kbe);
849 file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/linux/*.c)
850 set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
852 if(HAVE_INPUT_EVENTS)
853 set(SDL_INPUT_LINUXEV 1)
856 if(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
857 set(SDL_HAPTIC_LINUX 1)
858 file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/linux/*.c)
859 set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
860 set(HAVE_SDL_HAPTIC TRUE)
864 set(SDL_INPUT_LINUXKD 1)
867 check_include_file("libudev.h" HAVE_LIBUDEV_H)
869 # !!! FIXME: this needs pkg-config to find the include path, I think.
870 check_include_file("dbus/dbus.h" HAVE_DBUS_DBUS_H)
874 check_c_source_compiles("
876 int main(int argc, char** argv) { }" HAVE_INPUT_TSLIB)
878 set(SDL_INPUT_TSLIB 1)
879 list(APPEND EXTRA_LIBS ts)
884 CheckUSBHID() # seems to be BSD specific - limit the test to BSD only?
885 if(LINUX AND NOT ANDROID)
886 set(SDL_JOYSTICK_LINUX 1)
887 file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c)
888 set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
889 set(HAVE_SDL_JOYSTICK TRUE)
896 check_library_exists(rt clock_gettime "" FOUND_CLOCK_GETTIME)
897 if(FOUND_CLOCK_GETTIME)
898 list(APPEND EXTRA_LIBS rt)
899 set(HAVE_CLOCK_GETTIME 1)
901 check_library_exists(c clock_gettime "" FOUND_CLOCK_GETTIME)
902 if(FOUND_CLOCK_GETTIME)
903 set(HAVE_CLOCK_GETTIME 1)
908 check_include_file(linux/version.h HAVE_LINUX_VERSION_H)
909 if(HAVE_LINUX_VERSION_H)
910 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_LINUX_VERSION_H")
915 set(SDL_POWER_LINUX 1)
916 file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/linux/*.c)
917 set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
918 set(HAVE_SDL_POWER TRUE)
923 set(SDL_FILESYSTEM_UNIX 1)
924 file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/unix/*.c)
925 set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
926 set(HAVE_SDL_FILESYSTEM TRUE)
930 set(SDL_TIMER_UNIX 1)
931 file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
932 set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
933 set(HAVE_SDL_TIMERS TRUE)
937 set(SDL_RLD_FLAGS "")
938 if(BSDI OR FREEBSD OR LINUX OR NETBSD)
939 set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir}")
941 set(SDL_RLD_FLAGS "-R\${libdir}")
943 set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
948 find_program(WINDRES windres)
950 check_c_source_compiles("
952 int main(int argc, char **argv) { }" HAVE_WIN32_CC)
954 file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
955 set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
958 # Prevent codegen that would use the VC runtime libraries.
959 add_definitions(/GS-)
961 add_definitions(/arch:SSE)
967 if(DEFINED MSVC_VERSION AND NOT ${MSVC_VERSION} LESS 1700)
968 set(USE_WINSDK_DIRECTX TRUE)
970 if(NOT CMAKE_COMPILER_IS_MINGW AND NOT USE_WINSDK_DIRECTX)
971 if("$ENV{DXSDK_DIR}" STREQUAL "")
972 message_error("DIRECTX requires the \$DXSDK_DIR environment variable to be set")
974 set(CMAKE_REQUIRED_FLAGS "/I\"$ENV{DXSDK_DIR}\\Include\"")
978 # xinput.h may need windows.h, but doesn't include it itself.
979 check_c_source_compiles("
982 int main(int argc, char **argv) { }" HAVE_XINPUT_H)
984 check_include_file(xinput.h HAVE_XINPUT_H)
987 check_include_file(d3d9.h HAVE_D3D_H)
988 check_include_file(d3d11_1.h HAVE_D3D11_H)
989 check_include_file(ddraw.h HAVE_DDRAW_H)
990 check_include_file(dsound.h HAVE_DSOUND_H)
991 check_include_file(dinput.h HAVE_DINPUT_H)
992 check_include_file(xaudio2.h HAVE_XAUDIO2_H)
993 check_include_file(dxgi.h HAVE_DXGI_H)
994 if(HAVE_D3D_H OR HAVE_D3D11_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H OR HAVE_XAUDIO2_H)
995 set(HAVE_DIRECTX TRUE)
996 if(NOT CMAKE_COMPILER_IS_MINGW AND NOT USE_WINSDK_DIRECTX)
997 # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks
998 link_directories($ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH})
999 include_directories($ENV{DXSDK_DIR}\\Include)
1002 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
1006 set(SDL_AUDIO_DRIVER_WINMM 1)
1007 file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c)
1008 set(SOURCE_FILES ${SOURCE_FILES} ${WINMM_AUDIO_SOURCES})
1009 set(HAVE_SDL_AUDIO TRUE)
1012 set(SDL_AUDIO_DRIVER_DSOUND 1)
1013 file(GLOB DSOUND_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/directsound/*.c)
1014 set(SOURCE_FILES ${SOURCE_FILES} ${DSOUND_AUDIO_SOURCES})
1018 set(SDL_AUDIO_DRIVER_XAUDIO2 1)
1019 file(GLOB XAUDIO2_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/xaudio2/*.c)
1020 set(SOURCE_FILES ${SOURCE_FILES} ${XAUDIO2_AUDIO_SOURCES})
1025 # requires SDL_LOADSO on Windows (IME, DX, etc.)
1027 message_error("SDL_VIDEO requires SDL_LOADSO, which is not enabled")
1029 set(SDL_VIDEO_DRIVER_WINDOWS 1)
1030 file(GLOB WIN_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/windows/*.c)
1031 set(SOURCE_FILES ${SOURCE_FILES} ${WIN_VIDEO_SOURCES})
1033 if(RENDER_D3D AND HAVE_D3D_H)
1034 set(SDL_VIDEO_RENDER_D3D 1)
1035 set(HAVE_RENDER_D3D TRUE)
1037 if(RENDER_D3D AND HAVE_D3D11_H)
1038 set(SDL_VIDEO_RENDER_D3D11 1)
1039 set(HAVE_RENDER_D3D TRUE)
1041 set(HAVE_SDL_VIDEO TRUE)
1045 set(SDL_THREAD_WINDOWS 1)
1046 set(SOURCE_FILES ${SOURCE_FILES}
1047 ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_sysmutex.c
1048 ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_syssem.c
1049 ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systhread.c
1050 ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systls.c
1051 ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c)
1052 set(HAVE_SDL_THREADS TRUE)
1056 set(SDL_POWER_WINDOWS 1)
1057 set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/power/windows/SDL_syspower.c)
1058 set(HAVE_SDL_POWER TRUE)
1062 set(SDL_FILESYSTEM_WINDOWS 1)
1063 file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/windows/*.c)
1064 set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
1065 set(HAVE_SDL_FILESYSTEM TRUE)
1068 # Libraries for Win32 native and MinGW
1069 list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid)
1071 # TODO: in configure.in the check for timers is set on
1072 # cygwin | mingw32* - does this include mingw32CE?
1074 set(SDL_TIMER_WINDOWS 1)
1075 file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/windows/*.c)
1076 set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
1077 set(HAVE_SDL_TIMERS TRUE)
1081 set(SDL_LOADSO_WINDOWS 1)
1082 file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/windows/*.c)
1083 set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
1084 set(HAVE_SDL_LOADSO TRUE)
1087 file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
1088 set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
1092 set(SDL_VIDEO_OPENGL 1)
1093 set(SDL_VIDEO_OPENGL_WGL 1)
1094 set(SDL_VIDEO_RENDER_OGL 1)
1095 set(HAVE_VIDEO_OPENGL TRUE)
1099 set(SDL_VIDEO_OPENGL_EGL 1)
1100 set(SDL_VIDEO_OPENGL_ES2 1)
1101 set(SDL_VIDEO_RENDER_OGL_ES2 1)
1102 set(HAVE_VIDEO_OPENGLES TRUE)
1107 file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/windows/*.c)
1108 set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
1110 set(SDL_JOYSTICK_DINPUT 1)
1111 list(APPEND EXTRA_LIBS dinput8 dxguid)
1112 if(CMAKE_COMPILER_IS_MINGW)
1113 list(APPEND EXTRA_LIBS dxerr8)
1114 elseif (NOT USE_WINSDK_DIRECTX)
1115 list(APPEND EXTRA_LIBS dxerr)
1119 set(SDL_JOYSTICK_XINPUT 1)
1121 if(NOT HAVE_DINPUT_H AND NOT HAVE_XINPUT_H)
1122 set(SDL_JOYSTICK_WINMM 1)
1124 set(HAVE_SDL_JOYSTICK TRUE)
1127 if(HAVE_DINPUT_H OR HAVE_XINPUT_H)
1128 file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/windows/*.c)
1130 set(SDL_HAPTIC_DINPUT 1)
1133 set(SDL_HAPTIC_XINPUT 1)
1136 file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
1137 set(SDL_HAPTIC_DUMMY 1)
1139 set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
1140 set(HAVE_SDL_HAPTIC TRUE)
1144 file(GLOB VERSION_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.rc)
1145 file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.c)
1147 list(APPEND EXTRA_LIBS mingw32)
1148 list(APPEND EXTRA_LDFLAGS "-mwindows")
1149 set(SDL_CFLAGS "${SDL_CFLAGS} -Dmain=SDL_main")
1150 list(APPEND SDL_LIBS "-lmingw32" "-lSDL2main" "-mwindows")
1153 # TODO: rework this for proper MacOS X, iOS and Darwin support
1155 # Requires the darwin file implementation
1157 file(GLOB EXTRA_SOURCES ${SDL2_SOURCE_DIR}/src/file/cocoa/*.m)
1158 set(SOURCE_FILES ${EXTRA_SOURCES} ${SOURCE_FILES})
1159 set_source_files_properties(${EXTRA_SOURCES} PROPERTIES LANGUAGE C)
1160 set(HAVE_SDL_FILE TRUE)
1161 set(SDL_FRAMEWORK_COCOA 1)
1162 set(SDL_FRAMEWORK_COREVIDEO 1)
1164 message_error("SDL_FILE must be enabled to build on MacOS X")
1168 set(SDL_AUDIO_DRIVER_COREAUDIO 1)
1169 file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.c)
1170 set(SOURCE_FILES ${SOURCE_FILES} ${AUDIO_SOURCES})
1171 set(HAVE_SDL_AUDIO TRUE)
1172 set(SDL_FRAMEWORK_COREAUDIO 1)
1173 set(SDL_FRAMEWORK_AUDIOUNIT 1)
1177 set(SDL_JOYSTICK_IOKIT 1)
1178 file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
1179 set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
1180 set(HAVE_SDL_JOYSTICK TRUE)
1181 set(SDL_FRAMEWORK_IOKIT 1)
1182 set(SDL_FRAMEWORK_FF 1)
1186 set(SDL_HAPTIC_IOKIT 1)
1187 file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/darwin/*.c)
1188 set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
1189 set(HAVE_SDL_HAPTIC TRUE)
1190 set(SDL_FRAMEWORK_IOKIT 1)
1191 set(SDL_FRAMEWORK_FF 1)
1192 if(NOT SDL_JOYSTICK)
1193 message(FATAL_ERROR "SDL_HAPTIC requires SDL_JOYSTICK to be enabled")
1198 set(SDL_POWER_MACOSX 1)
1199 file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/macosx/*.c)
1200 set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
1201 set(HAVE_SDL_POWER TRUE)
1202 set(SDL_FRAMEWORK_CARBON 1)
1203 set(SDL_FRAMEWORK_IOKIT 1)
1207 set(SDL_TIMER_UNIX 1)
1208 file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
1209 set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
1210 set(HAVE_SDL_TIMERS TRUE)
1214 set(SDL_FILESYSTEM_COCOA 1)
1215 file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
1216 set_source_files_properties(${FILESYSTEM_SOURCES} PROPERTIES LANGUAGE C)
1217 set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
1218 set(HAVE_SDL_FILESYSTEM TRUE)
1221 # Actually load the frameworks at the end so we don't duplicate include.
1222 if(SDL_FRAMEWORK_COREVIDEO)
1223 find_library(COREVIDEO CoreVideo)
1224 list(APPEND EXTRA_LIBS ${COREVIDEO})
1226 if(SDL_FRAMEWORK_COCOA)
1227 find_library(COCOA_LIBRARY Cocoa)
1228 list(APPEND EXTRA_LIBS ${COCOA_LIBRARY})
1230 if(SDL_FRAMEWORK_IOKIT)
1231 find_library(IOKIT IOKit)
1232 list(APPEND EXTRA_LIBS ${IOKIT})
1234 if(SDL_FRAMEWORK_FF)
1235 find_library(FORCEFEEDBACK ForceFeedback)
1236 list(APPEND EXTRA_LIBS ${FORCEFEEDBACK})
1238 if(SDL_FRAMEWORK_CARBON)
1239 find_library(CARBON_LIBRARY Carbon)
1240 list(APPEND EXTRA_LIBS ${CARBON_LIBRARY})
1242 if(SDL_FRAMEWORK_COREAUDIO)
1243 find_library(COREAUDIO CoreAudio)
1244 list(APPEND EXTRA_LIBS ${COREAUDIO})
1246 if(SDL_FRAMEWORK_AUDIOUNIT)
1247 find_library(AUDIOUNIT AudioUnit)
1248 list(APPEND EXTRA_LIBS ${AUDIOUNIT})
1251 # iOS hack needed - http://code.google.com/p/ios-cmake/ ?
1255 set(SDL_VIDEO_OPENGL 1)
1256 set(SDL_VIDEO_OPENGL_CGL 1)
1257 set(SDL_VIDEO_RENDER_OGL 1)
1258 set(HAVE_VIDEO_OPENGL TRUE)
1265 set(SDL_VIDEO_DRIVER_HAIKU 1)
1266 file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.c)
1267 set(SOURCE_FILES ${SOURCE_FILES} ${HAIKUVIDEO_SOURCES})
1268 set(HAVE_SDL_VIDEO TRUE)
1270 set(SDL_FILESYSTEM_HAIKU 1)
1271 file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/haiku/*.cc)
1272 set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
1273 set(HAVE_SDL_FILESYSTEM TRUE)
1276 set(SDL_TIMER_HAIKU 1)
1277 file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/haiku/*.c)
1278 set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
1279 set(HAVE_SDL_TIMERS TRUE)
1283 # TODO: Use FIND_PACKAGE(OpenGL) instead
1284 set(SDL_VIDEO_OPENGL 1)
1285 set(SDL_VIDEO_OPENGL_BGL 1)
1286 set(SDL_VIDEO_RENDER_OGL 1)
1287 list(APPEND EXTRA_LIBS GL)
1288 set(HAVE_VIDEO_OPENGL TRUE)
1296 set(SDL_VIDEO_VULKAN 1)
1297 set(HAVE_VIDEO_VULKAN TRUE)
1298 set(SDL_CFLAGS "${SDL_CFLAGS} -I/usr/include")
1304 # configure.in does it differently:
1306 # if enable_X { SDL_X_DISABLED = 1 }
1307 # [add dummy sources]
1308 # so it always adds a dummy, without checking, if it was actually requested.
1309 # This leads to missing internal references on building, since the
1310 # src/X/*.c does not get included.
1311 if(NOT HAVE_SDL_JOYSTICK)
1312 set(SDL_JOYSTICK_DISABLED 1)
1313 if(SDL_JOYSTICK AND NOT APPLE) # results in unresolved symbols on OSX
1315 file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dummy/*.c)
1316 set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
1319 if(NOT HAVE_SDL_HAPTIC)
1320 set(SDL_HAPTIC_DISABLED 1)
1321 file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
1322 set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
1324 if(NOT HAVE_SDL_LOADSO)
1325 set(SDL_LOADSO_DISABLED 1)
1326 file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
1327 set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
1329 if(NOT HAVE_SDL_FILESYSTEM)
1330 set(SDL_FILESYSTEM_DISABLED 1)
1331 file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c)
1332 set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
1335 # We always need to have threads and timers around
1336 if(NOT HAVE_SDL_THREADS)
1337 set(SDL_THREADS_DISABLED 1)
1338 file(GLOB THREADS_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/*.c)
1339 set(SOURCE_FILES ${SOURCE_FILES} ${THREADS_SOURCES})
1341 if(NOT HAVE_SDL_TIMERS)
1342 set(SDL_TIMERS_DISABLED 1)
1343 file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/dummy/*.c)
1344 set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
1347 if(NOT SDLMAIN_SOURCES)
1348 file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/dummy/*.c)
1351 # Append the -MMD -MT flags
1352 # if(DEPENDENCY_TRACKING)
1353 # if(COMPILER_IS_GNUCC)
1354 # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MMD -MT \$@")
1358 configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
1359 "${SDL2_BINARY_DIR}/include/SDL_config.h")
1361 # Prepare the flags and remove duplicates
1363 list(REMOVE_DUPLICATES EXTRA_LDFLAGS)
1366 list(REMOVE_DUPLICATES EXTRA_LIBS)
1369 list(REMOVE_DUPLICATES EXTRA_CFLAGS)
1371 listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
1372 set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
1374 # Compat helpers for the configuration files
1375 if(NOT WINDOWS OR CYGWIN)
1376 # TODO: we need a Windows script, too
1377 execute_process(COMMAND sh ${SDL2_SOURCE_DIR}/build-scripts/updaterev.sh)
1379 set(prefix ${CMAKE_INSTALL_PREFIX})
1380 set(exec_prefix "\${prefix}")
1381 set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
1382 set(bindir "\${exec_prefix}/bin")
1383 set(includedir "\${prefix}/include")
1385 set(ENABLE_STATIC_TRUE "")
1386 set(ENABLE_STATIC_FALSE "#")
1388 set(ENABLE_STATIC_TRUE "#")
1389 set(ENABLE_STATIC_FALSE "")
1392 set(ENABLE_SHARED_TRUE "")
1393 set(ENABLE_SHARED_FALSE "#")
1395 set(ENABLE_SHARED_TRUE "#")
1396 set(ENABLE_SHARED_FALSE "")
1399 # Clean up the different lists
1400 listtostr(EXTRA_LIBS _EXTRA_LIBS "-l")
1401 set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
1402 list(REMOVE_DUPLICATES SDL_STATIC_LIBS)
1403 listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS)
1404 set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS})
1405 listtostr(SDL_LIBS _SDL_LIBS)
1406 set(SDL_LIBS ${_SDL_LIBS})
1408 # MESSAGE(STATUS "SDL_LIBS: ${SDL_LIBS}")
1409 # MESSAGE(STATUS "SDL_STATIC_LIBS: ${SDL_STATIC_LIBS}")
1411 configure_file("${SDL2_SOURCE_DIR}/sdl2.pc.in"
1412 "${SDL2_BINARY_DIR}/sdl2.pc" @ONLY)
1413 configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
1414 "${SDL2_BINARY_DIR}/sdl2-config")
1415 configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
1416 "${SDL2_BINARY_DIR}/sdl2-config" @ONLY)
1417 configure_file("${SDL2_SOURCE_DIR}/SDL2.spec.in"
1418 "${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
1421 ##### Info output #####
1423 message(STATUS "SDL2 was configured with the following options:")
1425 message(STATUS "Platform: ${CMAKE_SYSTEM}")
1426 message(STATUS "64-bit: ${ARCH_64}")
1427 message(STATUS "Compiler: ${CMAKE_C_COMPILER}")
1429 message(STATUS "Subsystems:")
1430 foreach(_SUB ${SDL_SUBSYSTEMS})
1431 string(TOUPPER ${_SUB} _OPT)
1432 message_bool_option(${_SUB} SDL_${_OPT})
1435 message(STATUS "Options:")
1436 list(SORT ALLOPTIONS)
1437 foreach(_OPT ${ALLOPTIONS})
1438 # Longest option is VIDEO_X11_XSCREENSAVER = 22 characters
1440 string(LENGTH ${_OPT} _OPTLEN)
1441 math(EXPR _PADLEN "23 - ${_OPTLEN}")
1442 string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
1443 message_tested_option(${_OPT} ${_PADDING})
1446 message(STATUS " CFLAGS: ${CMAKE_C_FLAGS}")
1447 message(STATUS " EXTRA_CFLAGS: ${EXTRA_CFLAGS}")
1448 message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS}")
1449 message(STATUS " EXTRA_LIBS: ${EXTRA_LIBS}")
1451 message(STATUS " Build Shared Library: ${SDL_SHARED}")
1452 message(STATUS " Build Static Library: ${SDL_STATIC}")
1455 message(STATUS "If something was not detected, although the libraries")
1456 message(STATUS "were installed, then make sure you have set the")
1457 message(STATUS "CFLAGS and LDFLAGS environment variables correctly.")
1461 # Ensure that the extra cflags are used at compile time
1462 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
1464 # Always build SDLmain
1465 add_library(SDL2main STATIC ${SDLMAIN_SOURCES})
1466 set(_INSTALL_LIBS "SDL2main")
1469 add_library(SDL2 SHARED ${SOURCE_FILES})
1471 set_target_properties(SDL2 PROPERTIES
1472 VERSION ${LT_VERSION}
1473 SOVERSION ${LT_REVISION}
1474 OUTPUT_NAME "SDL2-${LT_RELEASE}")
1476 set_target_properties(SDL2 PROPERTIES
1477 VERSION ${SDL_VERSION}
1478 SOVERSION ${LT_REVISION}
1482 # Don't try to link with the default set of libraries.
1483 set_target_properties(SDL2 PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
1484 set_target_properties(SDL2 PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
1485 set_target_properties(SDL2 PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
1487 set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
1488 target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
1492 set (BUILD_SHARED_LIBS FALSE)
1493 add_library(SDL2-static STATIC ${SOURCE_FILES})
1494 set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
1496 set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
1497 set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
1498 set_target_properties(SDL2-static PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
1500 # TODO: Win32 platforms keep the same suffix .lib for import and static
1501 # libraries - do we need to consider this?
1502 set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS})
1503 target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
1506 ##### Installation targets #####
1507 install(TARGETS ${_INSTALL_LIBS}
1508 LIBRARY DESTINATION "lib${LIB_SUFFIX}"
1509 ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
1510 RUNTIME DESTINATION bin)
1512 file(GLOB INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/*.h)
1513 file(GLOB BIN_INCLUDE_FILES ${SDL2_BINARY_DIR}/include/*.h)
1514 foreach(_FNAME ${BIN_INCLUDE_FILES})
1515 get_filename_component(_INCNAME ${_FNAME} NAME)
1516 list(REMOVE_ITEM INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/${_INCNAME})
1518 list(APPEND INCLUDE_FILES ${BIN_INCLUDE_FILES})
1519 install(FILES ${INCLUDE_FILES} DESTINATION include/SDL2)
1521 if(NOT WINDOWS OR CYGWIN)
1524 execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
1525 \"libSDL2-2.0.so\" \"libSDL2.so\")")
1526 install(FILES ${SDL2_BINARY_DIR}/libSDL2.so DESTINATION "lib${LIB_SUFFIX}")
1529 # FreeBSD uses ${PREFIX}/libdata/pkgconfig
1530 install(FILES ${SDL2_BINARY_DIR}/sdl2.pc DESTINATION "libdata/pkgconfig")
1532 install(FILES ${SDL2_BINARY_DIR}/sdl2.pc
1533 DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
1535 install(PROGRAMS ${SDL2_BINARY_DIR}/sdl2-config DESTINATION bin)
1536 # TODO: what about the .spec file? Is it only needed for RPM creation?
1537 install(FILES "${SDL2_SOURCE_DIR}/sdl2.m4" DESTINATION "share/aclocal")
1540 ##### Uninstall target #####
1543 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
1544 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
1547 add_custom_target(uninstall
1548 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)