🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1960 lines
67 KiB

  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")
  3. endif()
  4. cmake_minimum_required(VERSION 2.8.11)
  5. project(SDL2 C CXX)
  6. # !!! FIXME: this should probably do "MACOSX_RPATH ON" as a target property
  7. # !!! FIXME: for the SDL2 shared library (so you get an
  8. # !!! FIXME: install_name ("soname") of "@rpath/libSDL-whatever.dylib"
  9. # !!! FIXME: instead of "/usr/local/lib/libSDL-whatever.dylib"), but I'm
  10. # !!! FIXME: punting for now and leaving the existing behavior. Until this
  11. # !!! FIXME: properly resolved, this line silences a warning in CMake 3.0+.
  12. # !!! FIXME: remove it and this comment entirely once the problem is
  13. # !!! FIXME: properly resolved.
  14. #cmake_policy(SET CMP0042 OLD)
  15. include(CheckFunctionExists)
  16. include(CheckLibraryExists)
  17. include(CheckIncludeFiles)
  18. include(CheckIncludeFile)
  19. include(CheckSymbolExists)
  20. include(CheckCSourceCompiles)
  21. include(CheckCSourceRuns)
  22. include(CheckCCompilerFlag)
  23. include(CheckTypeSize)
  24. include(CheckStructHasMember)
  25. include(CMakeDependentOption)
  26. include(FindPkgConfig)
  27. include(GNUInstallDirs)
  28. set(CMAKE_MODULE_PATH "${SDL2_SOURCE_DIR}/cmake")
  29. include(${SDL2_SOURCE_DIR}/cmake/macros.cmake)
  30. include(${SDL2_SOURCE_DIR}/cmake/sdlchecks.cmake)
  31. # General settings
  32. # Edit include/SDL_version.h and change the version, then:
  33. # SDL_MICRO_VERSION += 1;
  34. # SDL_INTERFACE_AGE += 1;
  35. # SDL_BINARY_AGE += 1;
  36. # if any functions have been added, set SDL_INTERFACE_AGE to 0.
  37. # if backwards compatibility has been broken,
  38. # set SDL_BINARY_AGE and SDL_INTERFACE_AGE to 0.
  39. set(SDL_MAJOR_VERSION 2)
  40. set(SDL_MINOR_VERSION 0)
  41. set(SDL_MICRO_VERSION 10)
  42. set(SDL_INTERFACE_AGE 0)
  43. set(SDL_BINARY_AGE 10)
  44. set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}")
  45. # the following should match the versions in Xcode project file:
  46. set(DYLIB_CURRENT_VERSION 10.0.0)
  47. set(DYLIB_COMPATIBILITY_VERSION 1.0.0)
  48. # Set defaults preventing destination file conflicts
  49. set(SDL_CMAKE_DEBUG_POSTFIX "d"
  50. CACHE STRING "Name suffix for debug builds")
  51. mark_as_advanced(CMAKE_IMPORT_LIBRARY_SUFFIX SDL_CMAKE_DEBUG_POSTFIX)
  52. # Calculate a libtool-like version number
  53. math(EXPR LT_CURRENT "${SDL_MICRO_VERSION} - ${SDL_INTERFACE_AGE}")
  54. math(EXPR LT_AGE "${SDL_BINARY_AGE} - ${SDL_INTERFACE_AGE}")
  55. math(EXPR LT_MAJOR "${LT_CURRENT}- ${LT_AGE}")
  56. set(LT_REVISION "${SDL_INTERFACE_AGE}")
  57. set(LT_RELEASE "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}")
  58. set(LT_VERSION "${LT_MAJOR}.${LT_AGE}.${LT_REVISION}")
  59. #message(STATUS "${LT_VERSION} :: ${LT_AGE} :: ${LT_REVISION} :: ${LT_CURRENT} :: ${LT_RELEASE}")
  60. # General settings & flags
  61. set(LIBRARY_OUTPUT_DIRECTORY "build")
  62. # Check for 64 or 32 bit
  63. set(SIZEOF_VOIDP ${CMAKE_SIZEOF_VOID_P})
  64. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  65. set(ARCH_64 TRUE)
  66. set(PROCESSOR_ARCH "x64")
  67. else()
  68. set(ARCH_64 FALSE)
  69. set(PROCESSOR_ARCH "x86")
  70. endif()
  71. set(LIBNAME SDL2)
  72. if(NOT LIBTYPE)
  73. set(LIBTYPE SHARED)
  74. endif()
  75. # Get the platform
  76. if(WIN32)
  77. if(NOT WINDOWS)
  78. set(WINDOWS TRUE)
  79. endif()
  80. elseif(UNIX AND NOT APPLE)
  81. if(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
  82. set(LINUX TRUE)
  83. elseif(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*")
  84. set(FREEBSD TRUE)
  85. elseif(CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*")
  86. set(NETBSD TRUE)
  87. elseif(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
  88. set(OPENBSD TRUE)
  89. elseif(CMAKE_SYSTEM_NAME MATCHES ".*GNU.*")
  90. set(GNU TRUE)
  91. elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
  92. set(BSDI TRUE)
  93. elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")
  94. set(FREEBSD TRUE)
  95. elseif(CMAKE_SYSTEM_NAME MATCHES "SYSV5.*")
  96. set(SYSV5 TRUE)
  97. elseif(CMAKE_SYSTEM_NAME MATCHES "Solaris.*")
  98. set(SOLARIS TRUE)
  99. elseif(CMAKE_SYSTEM_NAME MATCHES "HP-UX.*")
  100. set(HPUX TRUE)
  101. elseif(CMAKE_SYSTEM_NAME MATCHES "AIX.*")
  102. set(AIX TRUE)
  103. elseif(CMAKE_SYSTEM_NAME MATCHES "Minix.*")
  104. set(MINIX TRUE)
  105. endif()
  106. elseif(APPLE)
  107. if(CMAKE_SYSTEM_NAME MATCHES ".*Darwin.*")
  108. set(DARWIN TRUE)
  109. elseif(CMAKE_SYSTEM_NAME MATCHES ".*MacOS.*")
  110. set(MACOSX TRUE)
  111. endif()
  112. # TODO: iOS?
  113. elseif(CMAKE_SYSTEM_NAME MATCHES "BeOS.*")
  114. message_error("BeOS support has been removed as of SDL 2.0.2.")
  115. elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku.*")
  116. set(HAIKU TRUE)
  117. endif()
  118. # Don't mistake osx for unix
  119. if(UNIX AND NOT APPLE)
  120. set(UNIX_SYS ON)
  121. else()
  122. set(UNIX_SYS OFF)
  123. endif()
  124. if(UNIX OR APPLE)
  125. set(UNIX_OR_MAC_SYS ON)
  126. else()
  127. set(UNIX_OR_MAC_SYS OFF)
  128. endif()
  129. if (UNIX_OR_MAC_SYS AND NOT EMSCRIPTEN) # JavaScript does not yet have threading support, so disable pthreads when building for Emscripten.
  130. set(SDL_PTHREADS_ENABLED_BY_DEFAULT ON)
  131. else()
  132. set(SDL_PTHREADS_ENABLED_BY_DEFAULT OFF)
  133. endif()
  134. # Default option knobs
  135. if(APPLE OR ARCH_64)
  136. if(NOT "${CMAKE_OSX_ARCHITECTURES}" MATCHES "arm")
  137. set(OPT_DEF_SSEMATH ON)
  138. endif()
  139. endif()
  140. if(UNIX OR MINGW OR MSYS)
  141. set(OPT_DEF_LIBC ON)
  142. endif()
  143. # The hidraw support doesn't catch Xbox, PS4 and Nintendo controllers,
  144. # so we'll just use libusb when it's available. Except that libusb
  145. # requires root permissions to open devices, so that's not generally
  146. # useful, and we'll disable this by default on Unix. Windows and macOS
  147. # can use it without root access, though, so enable by default there.
  148. if(WINDOWS OR APPLE OR ANDROID)
  149. set(HIDAPI_SKIP_LIBUSB TRUE)
  150. else()
  151. set(HIDAPI_SKIP_LIBUSB FALSE)
  152. endif()
  153. if (HIDAPI_SKIP_LIBUSB)
  154. set(OPT_DEF_HIDAPI ON)
  155. endif()
  156. # Compiler info
  157. if(CMAKE_COMPILER_IS_GNUCC)
  158. set(USE_GCC TRUE)
  159. set(OPT_DEF_ASM TRUE)
  160. elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
  161. set(USE_CLANG TRUE)
  162. set(OPT_DEF_ASM TRUE)
  163. elseif(MSVC_VERSION GREATER 1400) # VisualStudio 8.0+
  164. set(OPT_DEF_ASM TRUE)
  165. #set(CMAKE_C_FLAGS "/ZI /WX- /
  166. else()
  167. set(OPT_DEF_ASM FALSE)
  168. endif()
  169. if(USE_GCC OR USE_CLANG)
  170. set(OPT_DEF_GCC_ATOMICS ON)
  171. endif()
  172. # Default flags, if not set otherwise
  173. if("$ENV{CFLAGS}" STREQUAL "")
  174. if(CMAKE_BUILD_TYPE STREQUAL "")
  175. if(USE_GCC OR USE_CLANG)
  176. set(CMAKE_C_FLAGS "-g -O3")
  177. endif()
  178. endif()
  179. else()
  180. set(CMAKE_C_FLAGS "$ENV{CFLAGS}")
  181. list(APPEND EXTRA_CFLAGS "$ENV{CFLAGS}")
  182. endif()
  183. if(NOT ("$ENV{CFLAGS}" STREQUAL "")) # Hackish, but does the trick on Win32
  184. list(APPEND EXTRA_LDFLAGS "$ENV{LDFLAGS}")
  185. endif()
  186. if(MSVC)
  187. option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
  188. if(FORCE_STATIC_VCRT)
  189. foreach(flag_var
  190. CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  191. CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
  192. if(${flag_var} MATCHES "/MD")
  193. string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
  194. endif()
  195. endforeach()
  196. endif()
  197. # Make sure /RTC1 is disabled, otherwise it will use functions from the CRT
  198. foreach(flag_var
  199. CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  200. CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
  201. string(REGEX REPLACE "/RTC(su|[1su])" "" ${flag_var} "${${flag_var}}")
  202. endforeach(flag_var)
  203. endif()
  204. # Those are used for pkg-config and friends, so that the SDL2.pc, sdl2-config,
  205. # etc. are created correctly.
  206. set(SDL_LIBS "-lSDL2")
  207. set(SDL_CFLAGS "")
  208. # When building shared lib for Windows with MinGW,
  209. # avoid the DLL having a "lib" prefix
  210. if(WINDOWS)
  211. set(CMAKE_SHARED_LIBRARY_PREFIX "")
  212. endif()
  213. # Emscripten toolchain has a nonempty default value for this, and the checks
  214. # in this file need to change that, so remember the original value, and
  215. # restore back to that afterwards. For check_function_exists() to work in
  216. # Emscripten, this value must be at its default value.
  217. set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
  218. if(CYGWIN)
  219. # We build SDL on cygwin without the UNIX emulation layer
  220. include_directories("-I/usr/include/mingw")
  221. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mno-cygwin")
  222. check_c_source_compiles("int main(int argc, char **argv) {}"
  223. HAVE_GCC_NO_CYGWIN)
  224. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  225. if(HAVE_GCC_NO_CYGWIN)
  226. list(APPEND EXTRA_LDFLAGS "-mno-cygwin")
  227. list(APPEND SDL_LIBS "-mno-cygwin")
  228. endif()
  229. set(SDL_CFLAGS "${SDL_CFLAGS} -I/usr/include/mingw")
  230. endif()
  231. add_definitions(-DUSING_GENERATED_CONFIG_H)
  232. # General includes
  233. include_directories(${SDL2_BINARY_DIR}/include ${SDL2_SOURCE_DIR}/include)
  234. if(USE_GCC OR USE_CLANG)
  235. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -idirafter ${SDL2_SOURCE_DIR}/src/video/khronos")
  236. else()
  237. include_directories(${SDL2_SOURCE_DIR}/src/video/khronos)
  238. endif()
  239. # All these ENABLED_BY_DEFAULT vars will default to ON if not specified, so
  240. # you only need to have a platform override them if they are disabling.
  241. set(OPT_DEF_ASM TRUE)
  242. if(EMSCRIPTEN)
  243. # Set up default values for the currently supported set of subsystems:
  244. # Emscripten/Javascript does not have assembly support, a dynamic library
  245. # loading architecture, low-level CPU inspection or multithreading.
  246. set(OPT_DEF_ASM FALSE)
  247. set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
  248. set(SDL_ATOMIC_ENABLED_BY_DEFAULT OFF)
  249. set(SDL_THREADS_ENABLED_BY_DEFAULT OFF)
  250. set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF)
  251. set(SDL_CPUINFO_ENABLED_BY_DEFAULT OFF)
  252. set(SDL_DLOPEN_ENABLED_BY_DEFAULT OFF)
  253. endif()
  254. # When defined, respect CMake's BUILD_SHARED_LIBS setting:
  255. set(SDL_STATIC_ENABLED_BY_DEFAULT ON)
  256. if (NOT DEFINED SDL_SHARED_ENABLED_BY_DEFAULT)
  257. # ...unless decided already (as for EMSCRIPTEN)
  258. set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
  259. if (NOT DEFINED BUILD_SHARED_LIBS)
  260. # No preference? Build both, just like the AC/AM configure
  261. set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
  262. elseif (BUILD_SHARED_LIBS)
  263. # In this case, we assume the user wants a shared lib and don't build
  264. # the static one
  265. set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
  266. set(SDL_STATIC_ENABLED_BY_DEFAULT OFF)
  267. endif()
  268. endif()
  269. set(SDL_SUBSYSTEMS
  270. Atomic Audio Video Render Events Joystick Haptic Power Threads Timers
  271. File Loadso CPUinfo Filesystem Dlopen Sensor)
  272. foreach(_SUB ${SDL_SUBSYSTEMS})
  273. string(TOUPPER ${_SUB} _OPT)
  274. if (NOT DEFINED SDL_${_OPT}_ENABLED_BY_DEFAULT)
  275. set(SDL_${_OPT}_ENABLED_BY_DEFAULT ON)
  276. endif()
  277. option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ${SDL_${_OPT}_ENABLED_BY_DEFAULT})
  278. endforeach()
  279. option_string(ASSERTIONS "Enable internal sanity checks (auto/disabled/release/enabled/paranoid)" "auto")
  280. #set_option(DEPENDENCY_TRACKING "Use gcc -MMD -MT dependency tracking" ON)
  281. set_option(LIBC "Use the system C library" ${OPT_DEF_LIBC})
  282. set_option(GCC_ATOMICS "Use gcc builtin atomics" ${OPT_DEF_GCC_ATOMICS})
  283. set_option(ASSEMBLY "Enable assembly routines" ${OPT_DEF_ASM})
  284. set_option(SSEMATH "Allow GCC to use SSE floating point math" ${OPT_DEF_SSEMATH})
  285. set_option(MMX "Use MMX assembly routines" ${OPT_DEF_ASM})
  286. set_option(3DNOW "Use 3Dnow! MMX assembly routines" ${OPT_DEF_ASM})
  287. set_option(SSE "Use SSE assembly routines" ${OPT_DEF_ASM})
  288. set_option(SSE2 "Use SSE2 assembly routines" ${OPT_DEF_SSEMATH})
  289. set_option(SSE3 "Use SSE3 assembly routines" ${OPT_DEF_SSEMATH})
  290. set_option(ALTIVEC "Use Altivec assembly routines" ${OPT_DEF_ASM})
  291. set_option(DISKAUDIO "Support the disk writer audio driver" ON)
  292. set_option(DUMMYAUDIO "Support the dummy audio driver" ON)
  293. set_option(VIDEO_DIRECTFB "Use DirectFB video driver" OFF)
  294. dep_option(DIRECTFB_SHARED "Dynamically load directfb support" ON "VIDEO_DIRECTFB" OFF)
  295. set_option(VIDEO_DUMMY "Use dummy video driver" ON)
  296. set_option(VIDEO_OPENGL "Include OpenGL support" ON)
  297. set_option(VIDEO_OPENGLES "Include OpenGL ES support" ON)
  298. set_option(PTHREADS "Use POSIX threads for multi-threading" ${SDL_PTHREADS_ENABLED_BY_DEFAULT})
  299. dep_option(PTHREADS_SEM "Use pthread semaphores" ON "PTHREADS" OFF)
  300. set_option(SDL_DLOPEN "Use dlopen for shared object loading" ${SDL_DLOPEN_ENABLED_BY_DEFAULT})
  301. set_option(OSS "Support the OSS audio API" ${UNIX_SYS})
  302. set_option(ALSA "Support the ALSA audio API" ${UNIX_SYS})
  303. dep_option(ALSA_SHARED "Dynamically load ALSA audio support" ON "ALSA" OFF)
  304. set_option(JACK "Support the JACK audio API" ${UNIX_SYS})
  305. dep_option(JACK_SHARED "Dynamically load JACK audio support" ON "JACK" OFF)
  306. set_option(ESD "Support the Enlightened Sound Daemon" ${UNIX_SYS})
  307. dep_option(ESD_SHARED "Dynamically load ESD audio support" ON "ESD" OFF)
  308. set_option(PULSEAUDIO "Use PulseAudio" ${UNIX_SYS})
  309. dep_option(PULSEAUDIO_SHARED "Dynamically load PulseAudio support" ON "PULSEAUDIO" OFF)
  310. set_option(ARTS "Support the Analog Real Time Synthesizer" ${UNIX_SYS})
  311. dep_option(ARTS_SHARED "Dynamically load aRts audio support" ON "ARTS" OFF)
  312. set_option(NAS "Support the NAS audio API" ${UNIX_SYS})
  313. set_option(NAS_SHARED "Dynamically load NAS audio API" ${UNIX_SYS})
  314. set_option(SNDIO "Support the sndio audio API" ${UNIX_SYS})
  315. set_option(FUSIONSOUND "Use FusionSound audio driver" OFF)
  316. dep_option(FUSIONSOUND_SHARED "Dynamically load fusionsound audio support" ON "FUSIONSOUND" OFF)
  317. set_option(LIBSAMPLERATE "Use libsamplerate for audio rate conversion" ${UNIX_SYS})
  318. dep_option(LIBSAMPLERATE_SHARED "Dynamically load libsamplerate" ON "LIBSAMPLERATE" OFF)
  319. set_option(RPATH "Use an rpath when linking SDL" ${UNIX_SYS})
  320. set_option(CLOCK_GETTIME "Use clock_gettime() instead of gettimeofday()" OFF)
  321. set_option(INPUT_TSLIB "Use the Touchscreen library for input" ${UNIX_SYS})
  322. set_option(VIDEO_X11 "Use X11 video driver" ${UNIX_SYS})
  323. set_option(VIDEO_WAYLAND "Use Wayland video driver" ${UNIX_SYS})
  324. dep_option(WAYLAND_SHARED "Dynamically load Wayland support" ON "VIDEO_WAYLAND" OFF)
  325. dep_option(VIDEO_WAYLAND_QT_TOUCH "QtWayland server support for Wayland video driver" ON "VIDEO_WAYLAND" OFF)
  326. set_option(VIDEO_RPI "Use Raspberry Pi video driver" ${UNIX_SYS})
  327. dep_option(X11_SHARED "Dynamically load X11 support" ON "VIDEO_X11" OFF)
  328. set(SDL_X11_OPTIONS Xcursor Xinerama XInput Xrandr Xscrnsaver XShape Xvm)
  329. foreach(_SUB ${SDL_X11_OPTIONS})
  330. string(TOUPPER "VIDEO_X11_${_SUB}" _OPT)
  331. dep_option(${_OPT} "Enable ${_SUB} support" ON "VIDEO_X11" OFF)
  332. endforeach()
  333. set_option(VIDEO_COCOA "Use Cocoa video driver" ${APPLE})
  334. set_option(DIRECTX "Use DirectX for Windows audio/video" ${WINDOWS})
  335. set_option(WASAPI "Use the Windows WASAPI audio driver" ${WINDOWS})
  336. set_option(RENDER_D3D "Enable the Direct3D render driver" ${WINDOWS})
  337. set_option(VIDEO_VIVANTE "Use Vivante EGL video driver" ${UNIX_SYS})
  338. dep_option(VIDEO_VULKAN "Enable Vulkan support" ON "ANDROID OR APPLE OR LINUX OR WINDOWS" OFF)
  339. set_option(VIDEO_KMSDRM "Use KMS DRM video driver" ${UNIX_SYS})
  340. dep_option(KMSDRM_SHARED "Dynamically load KMS DRM support" ON "VIDEO_KMSDRM" OFF)
  341. option_string(BACKGROUNDING_SIGNAL "number to use for magic backgrounding signal or 'OFF'" "OFF")
  342. option_string(FOREGROUNDING_SIGNAL "number to use for magic foregrounding signal or 'OFF'" "OFF")
  343. set_option(HIDAPI "Use HIDAPI for low level joystick drivers" ${OPT_DEF_HIDAPI})
  344. set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared version of the library")
  345. set(SDL_STATIC ${SDL_STATIC_ENABLED_BY_DEFAULT} CACHE BOOL "Build a static version of the library")
  346. dep_option(SDL_STATIC_PIC "Static version of the library should be built with Position Independent Code" OFF "SDL_STATIC" OFF)
  347. set_option(SDL_TEST "Build the test directory" OFF)
  348. # General source files
  349. file(GLOB SOURCE_FILES
  350. ${SDL2_SOURCE_DIR}/src/*.c
  351. ${SDL2_SOURCE_DIR}/src/atomic/*.c
  352. ${SDL2_SOURCE_DIR}/src/audio/*.c
  353. ${SDL2_SOURCE_DIR}/src/cpuinfo/*.c
  354. ${SDL2_SOURCE_DIR}/src/dynapi/*.c
  355. ${SDL2_SOURCE_DIR}/src/events/*.c
  356. ${SDL2_SOURCE_DIR}/src/file/*.c
  357. ${SDL2_SOURCE_DIR}/src/libm/*.c
  358. ${SDL2_SOURCE_DIR}/src/render/*.c
  359. ${SDL2_SOURCE_DIR}/src/render/*/*.c
  360. ${SDL2_SOURCE_DIR}/src/stdlib/*.c
  361. ${SDL2_SOURCE_DIR}/src/thread/*.c
  362. ${SDL2_SOURCE_DIR}/src/timer/*.c
  363. ${SDL2_SOURCE_DIR}/src/video/*.c
  364. ${SDL2_SOURCE_DIR}/src/video/yuv2rgb/*.c)
  365. if(ASSERTIONS STREQUAL "auto")
  366. # Do nada - use optimization settings to determine the assertion level
  367. elseif(ASSERTIONS STREQUAL "disabled")
  368. set(SDL_DEFAULT_ASSERT_LEVEL 0)
  369. elseif(ASSERTIONS STREQUAL "release")
  370. set(SDL_DEFAULT_ASSERT_LEVEL 1)
  371. elseif(ASSERTIONS STREQUAL "enabled")
  372. set(SDL_DEFAULT_ASSERT_LEVEL 2)
  373. elseif(ASSERTIONS STREQUAL "paranoid")
  374. set(SDL_DEFAULT_ASSERT_LEVEL 3)
  375. else()
  376. message_error("unknown assertion level")
  377. endif()
  378. set(HAVE_ASSERTIONS ${ASSERTIONS})
  379. if(NOT BACKGROUNDING_SIGNAL STREQUAL "OFF")
  380. add_definitions("-DSDL_BACKGROUNDING_SIGNAL=${BACKGROUNDING_SIGNAL}")
  381. endif()
  382. if(NOT FOREGROUNDING_SIGNAL STREQUAL "OFF")
  383. add_definitions("-DSDL_FOREGROUNDING_SIGNAL=${FOREGROUNDING_SIGNAL}")
  384. endif()
  385. # Compiler option evaluation
  386. if(USE_GCC OR USE_CLANG)
  387. # Check for -Wall first, so later things can override pieces of it.
  388. check_c_compiler_flag(-Wall HAVE_GCC_WALL)
  389. if(HAVE_GCC_WALL)
  390. list(APPEND EXTRA_CFLAGS "-Wall")
  391. if(HAIKU)
  392. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")
  393. endif()
  394. endif()
  395. check_c_compiler_flag(-fno-strict-aliasing HAVE_GCC_NO_STRICT_ALIASING)
  396. if(HAVE_GCC_NO_STRICT_ALIASING)
  397. list(APPEND EXTRA_CFLAGS "-fno-strict-aliasing")
  398. endif()
  399. check_c_compiler_flag(-Wdeclaration-after-statement HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
  400. if(HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
  401. check_c_compiler_flag(-Werror=declaration-after-statement HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
  402. if(HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
  403. list(APPEND EXTRA_CFLAGS "-Werror=declaration-after-statement")
  404. endif()
  405. list(APPEND EXTRA_CFLAGS "-Wdeclaration-after-statement")
  406. endif()
  407. if(DEPENDENCY_TRACKING)
  408. check_c_source_compiles("
  409. #if !defined(__GNUC__) || __GNUC__ < 3
  410. #error Dependency tracking requires GCC 3.0 or newer
  411. #endif
  412. int main(int argc, char **argv) { }" HAVE_DEPENDENCY_TRACKING)
  413. endif()
  414. if(GCC_ATOMICS)
  415. check_c_source_compiles("int main(int argc, char **argv) {
  416. int a;
  417. void *x, *y, *z;
  418. __sync_lock_test_and_set(&a, 4);
  419. __sync_lock_test_and_set(&x, y);
  420. __sync_fetch_and_add(&a, 1);
  421. __sync_bool_compare_and_swap(&a, 5, 10);
  422. __sync_bool_compare_and_swap(&x, y, z); }" HAVE_GCC_ATOMICS)
  423. if(NOT HAVE_GCC_ATOMICS)
  424. check_c_source_compiles("int main(int argc, char **argv) {
  425. int a;
  426. __sync_lock_test_and_set(&a, 1);
  427. __sync_lock_release(&a); }" HAVE_GCC_SYNC_LOCK_TEST_AND_SET)
  428. endif()
  429. endif()
  430. set(CMAKE_REQUIRED_FLAGS "-mpreferred-stack-boundary=2")
  431. check_c_source_compiles("int x = 0; int main(int argc, char **argv) {}"
  432. HAVE_GCC_PREFERRED_STACK_BOUNDARY)
  433. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  434. set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden -Werror")
  435. check_c_source_compiles("
  436. #if !defined(__GNUC__) || __GNUC__ < 4
  437. #error SDL only uses visibility attributes in GCC 4 or newer
  438. #endif
  439. int main(int argc, char **argv) {}" HAVE_GCC_FVISIBILITY)
  440. if(HAVE_GCC_FVISIBILITY)
  441. list(APPEND EXTRA_CFLAGS "-fvisibility=hidden")
  442. endif()
  443. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  444. check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW)
  445. if(HAVE_GCC_WSHADOW)
  446. list(APPEND EXTRA_CFLAGS "-Wshadow")
  447. endif()
  448. if(APPLE)
  449. list(APPEND EXTRA_LDFLAGS "-Wl,-undefined,error")
  450. list(APPEND EXTRA_LDFLAGS "-Wl,-compatibility_version,${DYLIB_COMPATIBILITY_VERSION}")
  451. list(APPEND EXTRA_LDFLAGS "-Wl,-current_version,${DYLIB_CURRENT_VERSION}")
  452. else()
  453. set(CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined")
  454. check_c_compiler_flag("" HAVE_NO_UNDEFINED)
  455. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  456. if(HAVE_NO_UNDEFINED)
  457. list(APPEND EXTRA_LDFLAGS "-Wl,--no-undefined")
  458. endif()
  459. endif()
  460. endif()
  461. if(ASSEMBLY)
  462. if(USE_GCC OR USE_CLANG)
  463. set(SDL_ASSEMBLY_ROUTINES 1)
  464. # TODO: Those all seem to be quite GCC specific - needs to be
  465. # reworked for better compiler support
  466. set(HAVE_ASSEMBLY TRUE)
  467. if(MMX)
  468. set(CMAKE_REQUIRED_FLAGS "-mmmx")
  469. check_c_source_compiles("
  470. #ifdef __MINGW32__
  471. #include <_mingw.h>
  472. #ifdef __MINGW64_VERSION_MAJOR
  473. #include <intrin.h>
  474. #else
  475. #include <mmintrin.h>
  476. #endif
  477. #else
  478. #include <mmintrin.h>
  479. #endif
  480. #ifndef __MMX__
  481. #error Assembler CPP flag not enabled
  482. #endif
  483. int main(int argc, char **argv) { }" HAVE_MMX)
  484. if(HAVE_MMX)
  485. list(APPEND EXTRA_CFLAGS "-mmmx")
  486. endif()
  487. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  488. endif()
  489. if(3DNOW)
  490. set(CMAKE_REQUIRED_FLAGS "-m3dnow")
  491. check_c_source_compiles("
  492. #include <mm3dnow.h>
  493. #ifndef __3dNOW__
  494. #error Assembler CPP flag not enabled
  495. #endif
  496. int main(int argc, char **argv) {
  497. void *p = 0;
  498. _m_prefetch(p);
  499. }" HAVE_3DNOW)
  500. if(HAVE_3DNOW)
  501. list(APPEND EXTRA_CFLAGS "-m3dnow")
  502. endif()
  503. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  504. endif()
  505. if(SSE)
  506. set(CMAKE_REQUIRED_FLAGS "-msse")
  507. check_c_source_compiles("
  508. #ifdef __MINGW32__
  509. #include <_mingw.h>
  510. #ifdef __MINGW64_VERSION_MAJOR
  511. #include <intrin.h>
  512. #else
  513. #include <xmmintrin.h>
  514. #endif
  515. #else
  516. #include <xmmintrin.h>
  517. #endif
  518. #ifndef __SSE__
  519. #error Assembler CPP flag not enabled
  520. #endif
  521. int main(int argc, char **argv) { }" HAVE_SSE)
  522. if(HAVE_SSE)
  523. list(APPEND EXTRA_CFLAGS "-msse")
  524. endif()
  525. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  526. endif()
  527. if(SSE2)
  528. set(CMAKE_REQUIRED_FLAGS "-msse2")
  529. check_c_source_compiles("
  530. #ifdef __MINGW32__
  531. #include <_mingw.h>
  532. #ifdef __MINGW64_VERSION_MAJOR
  533. #include <intrin.h>
  534. #else
  535. #include <emmintrin.h>
  536. #endif
  537. #else
  538. #include <emmintrin.h>
  539. #endif
  540. #ifndef __SSE2__
  541. #error Assembler CPP flag not enabled
  542. #endif
  543. int main(int argc, char **argv) { }" HAVE_SSE2)
  544. if(HAVE_SSE2)
  545. list(APPEND EXTRA_CFLAGS "-msse2")
  546. endif()
  547. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  548. endif()
  549. if(SSE3)
  550. set(CMAKE_REQUIRED_FLAGS "-msse3")
  551. check_c_source_compiles("
  552. #ifdef __MINGW32__
  553. #include <_mingw.h>
  554. #ifdef __MINGW64_VERSION_MAJOR
  555. #include <intrin.h>
  556. #else
  557. #include <pmmintrin.h>
  558. #endif
  559. #else
  560. #include <pmmintrin.h>
  561. #endif
  562. #ifndef __SSE3__
  563. #error Assembler CPP flag not enabled
  564. #endif
  565. int main(int argc, char **argv) { }" HAVE_SSE3)
  566. if(HAVE_SSE3)
  567. list(APPEND EXTRA_CFLAGS "-msse3")
  568. endif()
  569. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  570. endif()
  571. if(NOT SSEMATH)
  572. if(SSE OR SSE2 OR SSE3)
  573. if(USE_GCC)
  574. check_c_compiler_flag(-mfpmath=387 HAVE_FP_387)
  575. if(HAVE_FP_387)
  576. list(APPEND EXTRA_CFLAGS "-mfpmath=387")
  577. endif()
  578. endif()
  579. set(HAVE_SSEMATH TRUE)
  580. endif()
  581. endif()
  582. check_include_file("immintrin.h" HAVE_IMMINTRIN_H)
  583. if(ALTIVEC)
  584. set(CMAKE_REQUIRED_FLAGS "-maltivec")
  585. check_c_source_compiles("
  586. #include <altivec.h>
  587. vector unsigned int vzero() {
  588. return vec_splat_u32(0);
  589. }
  590. int main(int argc, char **argv) { }" HAVE_ALTIVEC_H_HDR)
  591. check_c_source_compiles("
  592. vector unsigned int vzero() {
  593. return vec_splat_u32(0);
  594. }
  595. int main(int argc, char **argv) { }" HAVE_ALTIVEC)
  596. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  597. if(HAVE_ALTIVEC OR HAVE_ALTIVEC_H_HDR)
  598. set(HAVE_ALTIVEC TRUE) # if only HAVE_ALTIVEC_H_HDR is set
  599. list(APPEND EXTRA_CFLAGS "-maltivec")
  600. set(SDL_ALTIVEC_BLITTERS 1)
  601. if(HAVE_ALTIVEC_H_HDR)
  602. set(HAVE_ALTIVEC_H 1)
  603. endif()
  604. endif()
  605. endif()
  606. elseif(MSVC_VERSION GREATER 1500)
  607. # TODO: SDL_cpuinfo.h needs to support the user's configuration wish
  608. # for MSVC - right now it is always activated
  609. if(NOT ARCH_64)
  610. set(HAVE_MMX TRUE)
  611. set(HAVE_3DNOW TRUE)
  612. endif()
  613. set(HAVE_SSE TRUE)
  614. set(HAVE_SSE2 TRUE)
  615. set(HAVE_SSE3 TRUE)
  616. set(SDL_ASSEMBLY_ROUTINES 1)
  617. endif()
  618. # TODO:
  619. #else()
  620. # if(USE_GCC OR USE_CLANG)
  621. # list(APPEND EXTRA_CFLAGS "-mno-sse" "-mno-sse2" "-mno-sse3" "-mno-mmx")
  622. # endif()
  623. endif()
  624. # TODO: Can't deactivate on FreeBSD? w/o LIBC, SDL_stdinc.h can't define
  625. # anything.
  626. if(LIBC)
  627. if(WINDOWS AND NOT MINGW)
  628. set(HAVE_LIBC TRUE)
  629. foreach(_HEADER stdio.h string.h wchar.h ctype.h math.h limits.h)
  630. string(TOUPPER "HAVE_${_HEADER}" _UPPER)
  631. string(REPLACE "." "_" _HAVE_H ${_UPPER})
  632. set(${_HAVE_H} 1)
  633. endforeach()
  634. set(HAVE_SIGNAL_H 1)
  635. foreach(_FN
  636. malloc calloc realloc free qsort abs memset memcpy memmove memcmp
  637. wcslen wcscmp
  638. strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
  639. _ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp
  640. _stricmp _strnicmp sscanf
  641. acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf
  642. copysign copysignf cos cosf exp expf fabs fabsf floor floorf fmod fmodf
  643. log logf log10 log10f pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf)
  644. string(TOUPPER ${_FN} _UPPER)
  645. set(HAVE_${_UPPER} 1)
  646. endforeach()
  647. if(NOT CYGWIN AND NOT MINGW)
  648. set(HAVE_ALLOCA 1)
  649. endif()
  650. set(HAVE_M_PI 1)
  651. add_definitions(-D_USE_MATH_DEFINES) # needed for M_PI
  652. set(STDC_HEADERS 1)
  653. else()
  654. set(HAVE_LIBC TRUE)
  655. check_include_file(sys/types.h HAVE_SYS_TYPES_H)
  656. foreach(_HEADER
  657. stdio.h stdlib.h stddef.h stdarg.h malloc.h memory.h string.h limits.h
  658. strings.h wchar.h inttypes.h stdint.h ctype.h math.h iconv.h signal.h libunwind.h)
  659. string(TOUPPER "HAVE_${_HEADER}" _UPPER)
  660. string(REPLACE "." "_" _HAVE_H ${_UPPER})
  661. check_include_file("${_HEADER}" ${_HAVE_H})
  662. endforeach()
  663. check_include_files("dlfcn.h;stdint.h;stddef.h;inttypes.h;stdlib.h;strings.h;string.h;float.h" STDC_HEADERS)
  664. check_type_size("size_t" SIZEOF_SIZE_T)
  665. check_symbol_exists(M_PI math.h HAVE_M_PI)
  666. # TODO: refine the mprotect check
  667. check_c_source_compiles("#include <sys/types.h>
  668. #include <sys/mman.h>
  669. int main() { }" HAVE_MPROTECT)
  670. foreach(_FN
  671. strtod malloc calloc realloc free getenv setenv putenv unsetenv
  672. qsort abs bcopy memset memcpy memmove memcmp strlen strlcpy strlcat
  673. _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
  674. _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull
  675. atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp
  676. vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp
  677. nanosleep sysconf sysctlbyname getauxval poll _Exit
  678. )
  679. string(TOUPPER ${_FN} _UPPER)
  680. set(_HAVEVAR "HAVE_${_UPPER}")
  681. check_function_exists("${_FN}" ${_HAVEVAR})
  682. endforeach()
  683. check_library_exists(m pow "" HAVE_LIBM)
  684. if(HAVE_LIBM)
  685. set(CMAKE_REQUIRED_LIBRARIES m)
  686. foreach(_FN
  687. atan atan2 ceil copysign cos cosf fabs floor log pow scalbn sin
  688. sinf sqrt sqrtf tan tanf acos asin)
  689. string(TOUPPER ${_FN} _UPPER)
  690. set(_HAVEVAR "HAVE_${_UPPER}")
  691. check_function_exists("${_FN}" ${_HAVEVAR})
  692. endforeach()
  693. set(CMAKE_REQUIRED_LIBRARIES)
  694. list(APPEND EXTRA_LIBS m)
  695. endif()
  696. check_library_exists(iconv iconv_open "" HAVE_LIBICONV)
  697. if(HAVE_LIBICONV)
  698. list(APPEND EXTRA_LIBS iconv)
  699. set(HAVE_ICONV 1)
  700. endif()
  701. if(NOT APPLE)
  702. check_include_file(alloca.h HAVE_ALLOCA_H)
  703. check_function_exists(alloca HAVE_ALLOCA)
  704. else()
  705. set(HAVE_ALLOCA_H 1)
  706. set(HAVE_ALLOCA 1)
  707. endif()
  708. check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION)
  709. endif()
  710. else()
  711. if(WINDOWS)
  712. set(HAVE_STDARG_H 1)
  713. set(HAVE_STDDEF_H 1)
  714. endif()
  715. endif()
  716. # Enable/disable various subsystems of the SDL library
  717. foreach(_SUB ${SDL_SUBSYSTEMS})
  718. string(TOUPPER ${_SUB} _OPT)
  719. if(NOT SDL_${_OPT})
  720. set(SDL_${_OPT}_DISABLED 1)
  721. endif()
  722. endforeach()
  723. if(SDL_JOYSTICK)
  724. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/*.c)
  725. set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  726. endif()
  727. if(SDL_HAPTIC)
  728. if(NOT SDL_JOYSTICK)
  729. # Haptic requires some private functions from the joystick subsystem.
  730. message_error("SDL_HAPTIC requires SDL_JOYSTICK, which is not enabled")
  731. endif()
  732. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/*.c)
  733. set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  734. endif()
  735. if(SDL_SENSOR)
  736. file(GLOB SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/*.c)
  737. set(SOURCE_FILES ${SOURCE_FILES} ${SENSOR_SOURCES})
  738. endif()
  739. if(SDL_POWER)
  740. file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/*.c)
  741. set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
  742. endif()
  743. # TODO: in configure.ac, the test for LOADSO and SDL_DLOPEN is a bit weird:
  744. # if LOADSO is not wanted, SDL_LOADSO_DISABLED is set
  745. # If however on Unix or APPLE dlopen() is detected via CheckDLOPEN(),
  746. # SDL_LOADSO_DISABLED will not be set, regardless of the LOADSO settings
  747. # General SDL subsystem options, valid for all platforms
  748. if(SDL_AUDIO)
  749. # CheckDummyAudio/CheckDiskAudio - valid for all platforms
  750. if(DUMMYAUDIO)
  751. set(SDL_AUDIO_DRIVER_DUMMY 1)
  752. file(GLOB DUMMYAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dummy/*.c)
  753. set(SOURCE_FILES ${SOURCE_FILES} ${DUMMYAUDIO_SOURCES})
  754. set(HAVE_DUMMYAUDIO TRUE)
  755. endif()
  756. if(DISKAUDIO)
  757. set(SDL_AUDIO_DRIVER_DISK 1)
  758. file(GLOB DISKAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/disk/*.c)
  759. set(SOURCE_FILES ${SOURCE_FILES} ${DISKAUDIO_SOURCES})
  760. set(HAVE_DISKAUDIO TRUE)
  761. endif()
  762. endif()
  763. if(SDL_DLOPEN)
  764. # Relevant for Unix/Darwin only
  765. if(UNIX OR APPLE)
  766. CheckDLOPEN()
  767. endif()
  768. endif()
  769. if(SDL_VIDEO)
  770. if(VIDEO_DUMMY)
  771. set(SDL_VIDEO_DRIVER_DUMMY 1)
  772. file(GLOB VIDEO_DUMMY_SOURCES ${SDL2_SOURCE_DIR}/src/video/dummy/*.c)
  773. set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_DUMMY_SOURCES})
  774. set(HAVE_VIDEO_DUMMY TRUE)
  775. set(HAVE_SDL_VIDEO TRUE)
  776. endif()
  777. endif()
  778. # Platform-specific options and settings
  779. if(ANDROID)
  780. file(GLOB ANDROID_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/android/*.c)
  781. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_CORE_SOURCES})
  782. # SDL_spinlock.c Needs to be compiled in ARM mode.
  783. # There seems to be no better way currently to set the ARM mode.
  784. # see: https://issuetracker.google.com/issues/62264618
  785. # Another option would be to set ARM mode to all compiled files
  786. check_c_compiler_flag(-marm HAVE_ARM_MODE)
  787. if(HAVE_ARM_MODE)
  788. set_source_files_properties(${SDL2_SOURCE_DIR}/src/atomic/SDL_spinlock.c PROPERTIES COMPILE_FLAGS -marm)
  789. endif()
  790. file(GLOB ANDROID_MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/android/*.c)
  791. set(SDLMAIN_SOURCES ${SDLMAIN_SOURCES} ${ANDROID_MAIN_SOURCES})
  792. if(SDL_AUDIO)
  793. set(SDL_AUDIO_DRIVER_ANDROID 1)
  794. file(GLOB ANDROID_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/android/*.c)
  795. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_AUDIO_SOURCES})
  796. set(HAVE_SDL_AUDIO TRUE)
  797. endif()
  798. if(SDL_FILESYSTEM)
  799. set(SDL_FILESYSTEM_ANDROID 1)
  800. file(GLOB ANDROID_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/android/*.c)
  801. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_FILESYSTEM_SOURCES})
  802. set(HAVE_SDL_FILESYSTEM TRUE)
  803. endif()
  804. if(SDL_HAPTIC)
  805. set(SDL_HAPTIC_ANDROID 1)
  806. file(GLOB ANDROID_HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/android/*.c)
  807. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_HAPTIC_SOURCES})
  808. set(HAVE_SDL_HAPTIC TRUE)
  809. endif()
  810. if(SDL_JOYSTICK)
  811. CheckHIDAPI()
  812. set(SDL_JOYSTICK_ANDROID 1)
  813. file(GLOB ANDROID_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/android/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
  814. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_JOYSTICK_SOURCES})
  815. set(HAVE_SDL_JOYSTICK TRUE)
  816. endif()
  817. if(SDL_LOADSO)
  818. set(SDL_LOADSO_DLOPEN 1)
  819. file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dlopen/*.c)
  820. set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
  821. set(HAVE_SDL_LOADSO TRUE)
  822. endif()
  823. if(SDL_POWER)
  824. set(SDL_POWER_ANDROID 1)
  825. file(GLOB ANDROID_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/android/*.c)
  826. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_POWER_SOURCES})
  827. set(HAVE_SDL_POWER TRUE)
  828. endif()
  829. if(SDL_TIMERS)
  830. set(SDL_TIMER_UNIX 1)
  831. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
  832. set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  833. set(HAVE_SDL_TIMERS TRUE)
  834. endif()
  835. if(SDL_SENSOR)
  836. set(SDL_SENSOR_ANDROID 1)
  837. set(HAVE_SDL_SENSORS TRUE)
  838. file(GLOB ANDROID_SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/android/*.c)
  839. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_SENSOR_SOURCES})
  840. endif()
  841. if(SDL_VIDEO)
  842. set(SDL_VIDEO_DRIVER_ANDROID 1)
  843. file(GLOB ANDROID_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/android/*.c)
  844. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_VIDEO_SOURCES})
  845. set(HAVE_SDL_VIDEO TRUE)
  846. # Core stuff
  847. find_library(ANDROID_DL_LIBRARY dl)
  848. find_library(ANDROID_LOG_LIBRARY log)
  849. find_library(ANDROID_LIBRARY_LIBRARY android)
  850. list(APPEND EXTRA_LIBS ${ANDROID_DL_LIBRARY} ${ANDROID_LOG_LIBRARY} ${ANDROID_LIBRARY_LIBRARY})
  851. add_definitions(-DGL_GLEXT_PROTOTYPES)
  852. #enable gles
  853. if(VIDEO_OPENGLES)
  854. set(SDL_VIDEO_OPENGL_EGL 1)
  855. set(HAVE_VIDEO_OPENGLES TRUE)
  856. set(SDL_VIDEO_OPENGL_ES 1)
  857. set(SDL_VIDEO_RENDER_OGL_ES 1)
  858. set(SDL_VIDEO_OPENGL_ES2 1)
  859. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  860. find_library(OpenGLES1_LIBRARY GLESv1_CM)
  861. find_library(OpenGLES2_LIBRARY GLESv2)
  862. list(APPEND EXTRA_LIBS ${OpenGLES1_LIBRARY} ${OpenGLES2_LIBRARY})
  863. endif()
  864. CHECK_C_SOURCE_COMPILES("
  865. #if defined(__ARM_ARCH) && __ARM_ARCH < 7
  866. #error Vulkan doesn't work on this configuration
  867. #endif
  868. int main()
  869. {
  870. return 0;
  871. }
  872. " VULKAN_PASSED_ANDROID_CHECKS)
  873. if(NOT VULKAN_PASSED_ANDROID_CHECKS)
  874. set(VIDEO_VULKAN OFF)
  875. message(STATUS "Vulkan doesn't work on this configuration")
  876. endif()
  877. endif()
  878. CheckPTHREAD()
  879. elseif(EMSCRIPTEN)
  880. # Hide noisy warnings that intend to aid mostly during initial stages of porting a new
  881. # project. Uncomment at will for verbose cross-compiling -I/../ path info.
  882. add_definitions(-Wno-warn-absolute-paths)
  883. if(SDL_AUDIO)
  884. set(SDL_AUDIO_DRIVER_EMSCRIPTEN 1)
  885. file(GLOB EM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/emscripten/*.c)
  886. set(SOURCE_FILES ${SOURCE_FILES} ${EM_AUDIO_SOURCES})
  887. set(HAVE_SDL_AUDIO TRUE)
  888. endif()
  889. if(SDL_FILESYSTEM)
  890. set(SDL_FILESYSTEM_EMSCRIPTEN 1)
  891. file(GLOB EM_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/emscripten/*.c)
  892. set(SOURCE_FILES ${SOURCE_FILES} ${EM_FILESYSTEM_SOURCES})
  893. set(HAVE_SDL_FILESYSTEM TRUE)
  894. endif()
  895. if(SDL_JOYSTICK)
  896. set(SDL_JOYSTICK_EMSCRIPTEN 1)
  897. file(GLOB EM_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/emscripten/*.c)
  898. set(SOURCE_FILES ${SOURCE_FILES} ${EM_JOYSTICK_SOURCES})
  899. set(HAVE_SDL_JOYSTICK TRUE)
  900. endif()
  901. if(SDL_POWER)
  902. set(SDL_POWER_EMSCRIPTEN 1)
  903. file(GLOB EM_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/emscripten/*.c)
  904. set(SOURCE_FILES ${SOURCE_FILES} ${EM_POWER_SOURCES})
  905. set(HAVE_SDL_POWER TRUE)
  906. endif()
  907. if(SDL_TIMERS)
  908. set(SDL_TIMER_UNIX 1)
  909. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
  910. set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  911. set(HAVE_SDL_TIMERS TRUE)
  912. if(CLOCK_GETTIME)
  913. set(HAVE_CLOCK_GETTIME 1)
  914. endif()
  915. endif()
  916. if(SDL_VIDEO)
  917. set(SDL_VIDEO_DRIVER_EMSCRIPTEN 1)
  918. file(GLOB EM_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/emscripten/*.c)
  919. set(SOURCE_FILES ${SOURCE_FILES} ${EM_VIDEO_SOURCES})
  920. set(HAVE_SDL_VIDEO TRUE)
  921. #enable gles
  922. if(VIDEO_OPENGLES)
  923. set(SDL_VIDEO_OPENGL_EGL 1)
  924. set(HAVE_VIDEO_OPENGLES TRUE)
  925. set(SDL_VIDEO_OPENGL_ES2 1)
  926. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  927. endif()
  928. endif()
  929. elseif(UNIX AND NOT APPLE AND NOT ANDROID)
  930. if(SDL_AUDIO)
  931. if(SYSV5 OR SOLARIS OR HPUX)
  932. set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
  933. file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
  934. set(SOURCE_FILES ${SOURCE_FILES} ${SUN_AUDIO_SOURCES})
  935. set(HAVE_SDL_AUDIO TRUE)
  936. elseif(NETBSD)
  937. set(SDL_AUDIO_DRIVER_NETBSD 1)
  938. file(GLOB NETBSD_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/netbsd/*.c)
  939. set(SOURCE_FILES ${SOURCE_FILES} ${NETBSD_AUDIO_SOURCES})
  940. set(HAVE_SDL_AUDIO TRUE)
  941. elseif(AIX)
  942. set(SDL_AUDIO_DRIVER_PAUDIO 1)
  943. file(GLOB AIX_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/paudio/*.c)
  944. set(SOURCE_FILES ${SOURCE_FILES} ${AIX_AUDIO_SOURCES})
  945. set(HAVE_SDL_AUDIO TRUE)
  946. endif()
  947. CheckOSS()
  948. CheckALSA()
  949. CheckJACK()
  950. CheckPulseAudio()
  951. CheckESD()
  952. CheckARTS()
  953. CheckNAS()
  954. CheckSNDIO()
  955. CheckFusionSound()
  956. CheckLibSampleRate()
  957. endif()
  958. if(SDL_VIDEO)
  959. # Need to check for Raspberry PI first and add platform specific compiler flags, otherwise the test for GLES fails!
  960. CheckRPI()
  961. CheckX11()
  962. CheckDirectFB()
  963. CheckOpenGLX11()
  964. CheckOpenGLESX11()
  965. CheckWayland()
  966. CheckVivante()
  967. CheckKMSDRM()
  968. endif()
  969. if(UNIX)
  970. file(GLOB CORE_UNIX_SOURCES ${SDL2_SOURCE_DIR}/src/core/unix/*.c)
  971. set(SOURCE_FILES ${SOURCE_FILES} ${CORE_UNIX_SOURCES})
  972. endif()
  973. if(LINUX)
  974. check_c_source_compiles("
  975. #include <linux/input.h>
  976. #ifndef EVIOCGNAME
  977. #error EVIOCGNAME() ioctl not available
  978. #endif
  979. int main(int argc, char** argv) {}" HAVE_INPUT_EVENTS)
  980. check_c_source_compiles("
  981. #include <linux/kd.h>
  982. #include <linux/keyboard.h>
  983. int main(int argc, char **argv)
  984. {
  985. struct kbentry kbe;
  986. kbe.kb_table = KG_CTRL;
  987. ioctl(0, KDGKBENT, &kbe);
  988. }" HAVE_INPUT_KD)
  989. file(GLOB CORE_LINUX_SOURCES ${SDL2_SOURCE_DIR}/src/core/linux/*.c)
  990. set(SOURCE_FILES ${SOURCE_FILES} ${CORE_LINUX_SOURCES})
  991. if(HAVE_INPUT_EVENTS)
  992. set(SDL_INPUT_LINUXEV 1)
  993. endif()
  994. if(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
  995. set(SDL_HAPTIC_LINUX 1)
  996. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/linux/*.c)
  997. set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  998. set(HAVE_SDL_HAPTIC TRUE)
  999. endif()
  1000. if(HAVE_INPUT_KD)
  1001. set(SDL_INPUT_LINUXKD 1)
  1002. endif()
  1003. check_include_file("libudev.h" HAVE_LIBUDEV_H)
  1004. if(PKG_CONFIG_FOUND)
  1005. pkg_search_module(DBUS dbus-1 dbus)
  1006. if(DBUS_FOUND)
  1007. set(HAVE_DBUS_DBUS_H TRUE)
  1008. include_directories(${DBUS_INCLUDE_DIRS})
  1009. list(APPEND EXTRA_LIBS ${DBUS_LIBRARIES})
  1010. endif()
  1011. pkg_search_module(IBUS ibus-1.0 ibus)
  1012. if(IBUS_FOUND)
  1013. set(HAVE_IBUS_IBUS_H TRUE)
  1014. include_directories(${IBUS_INCLUDE_DIRS})
  1015. list(APPEND EXTRA_LIBS ${IBUS_LIBRARIES})
  1016. endif()
  1017. if(HAVE_LIBUNWIND_H)
  1018. # We've already found the header, so REQUIRE the lib to be present
  1019. pkg_search_module(UNWIND REQUIRED libunwind)
  1020. pkg_search_module(UNWIND_GENERIC REQUIRED libunwind-generic)
  1021. list(APPEND EXTRA_LIBS ${UNWIND_LIBRARIES} ${UNWIND_GENERIC_LIBRARIES})
  1022. endif()
  1023. endif()
  1024. check_include_file("fcitx/frontend.h" HAVE_FCITX_FRONTEND_H)
  1025. endif()
  1026. if(INPUT_TSLIB)
  1027. check_c_source_compiles("
  1028. #include \"tslib.h\"
  1029. int main(int argc, char** argv) { }" HAVE_INPUT_TSLIB)
  1030. if(HAVE_INPUT_TSLIB)
  1031. set(SDL_INPUT_TSLIB 1)
  1032. list(APPEND EXTRA_LIBS ts)
  1033. endif()
  1034. endif()
  1035. if(SDL_JOYSTICK)
  1036. CheckUSBHID() # seems to be BSD specific - limit the test to BSD only?
  1037. CheckHIDAPI()
  1038. if(LINUX AND NOT ANDROID)
  1039. set(SDL_JOYSTICK_LINUX 1)
  1040. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
  1041. set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1042. set(HAVE_SDL_JOYSTICK TRUE)
  1043. endif()
  1044. endif()
  1045. CheckPTHREAD()
  1046. if(CLOCK_GETTIME)
  1047. check_library_exists(rt clock_gettime "" FOUND_CLOCK_GETTIME)
  1048. if(FOUND_CLOCK_GETTIME)
  1049. list(APPEND EXTRA_LIBS rt)
  1050. set(HAVE_CLOCK_GETTIME 1)
  1051. else()
  1052. check_library_exists(c clock_gettime "" FOUND_CLOCK_GETTIME)
  1053. if(FOUND_CLOCK_GETTIME)
  1054. set(HAVE_CLOCK_GETTIME 1)
  1055. endif()
  1056. endif()
  1057. endif()
  1058. check_include_file(linux/version.h HAVE_LINUX_VERSION_H)
  1059. if(HAVE_LINUX_VERSION_H)
  1060. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_LINUX_VERSION_H")
  1061. endif()
  1062. if(SDL_POWER)
  1063. if(LINUX)
  1064. set(SDL_POWER_LINUX 1)
  1065. file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/linux/*.c)
  1066. set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
  1067. set(HAVE_SDL_POWER TRUE)
  1068. endif()
  1069. endif()
  1070. if(SDL_FILESYSTEM)
  1071. set(SDL_FILESYSTEM_UNIX 1)
  1072. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/unix/*.c)
  1073. set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1074. set(HAVE_SDL_FILESYSTEM TRUE)
  1075. endif()
  1076. if(SDL_TIMERS)
  1077. set(SDL_TIMER_UNIX 1)
  1078. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
  1079. set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1080. set(HAVE_SDL_TIMERS TRUE)
  1081. endif()
  1082. if(RPATH)
  1083. set(SDL_RLD_FLAGS "")
  1084. if(BSDI OR FREEBSD OR LINUX OR NETBSD)
  1085. set(CMAKE_REQUIRED_FLAGS "-Wl,--enable-new-dtags")
  1086. check_c_compiler_flag("" HAVE_ENABLE_NEW_DTAGS)
  1087. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  1088. if(HAVE_ENABLE_NEW_DTAGS)
  1089. set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir} -Wl,--enable-new-dtags")
  1090. else()
  1091. set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir}")
  1092. endif()
  1093. elseif(SOLARIS)
  1094. set(SDL_RLD_FLAGS "-R\${libdir}")
  1095. endif()
  1096. set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  1097. set(HAVE_RPATH TRUE)
  1098. endif()
  1099. elseif(WINDOWS)
  1100. find_program(WINDRES windres)
  1101. check_c_source_compiles("
  1102. #include <windows.h>
  1103. int main(int argc, char **argv) { }" HAVE_WIN32_CC)
  1104. file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
  1105. set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
  1106. if(MSVC)
  1107. # Prevent codegen that would use the VC runtime libraries.
  1108. set_property(DIRECTORY . APPEND PROPERTY COMPILE_OPTIONS "/GS-")
  1109. if(NOT ARCH_64)
  1110. set_property(DIRECTORY . APPEND PROPERTY COMPILE_OPTIONS "/arch:SSE")
  1111. endif()
  1112. endif()
  1113. # Check for DirectX
  1114. if(DIRECTX)
  1115. if(DEFINED MSVC_VERSION AND NOT ${MSVC_VERSION} LESS 1700)
  1116. set(USE_WINSDK_DIRECTX TRUE)
  1117. endif()
  1118. if(NOT CMAKE_COMPILER_IS_MINGW AND NOT USE_WINSDK_DIRECTX)
  1119. if("$ENV{DXSDK_DIR}" STREQUAL "")
  1120. message_error("DIRECTX requires the \$DXSDK_DIR environment variable to be set")
  1121. endif()
  1122. set(CMAKE_REQUIRED_FLAGS "/I\"$ENV{DXSDK_DIR}\\Include\"")
  1123. endif()
  1124. if(HAVE_WIN32_CC)
  1125. # xinput.h may need windows.h, but doesn't include it itself.
  1126. check_c_source_compiles("
  1127. #include <windows.h>
  1128. #include <xinput.h>
  1129. int main(int argc, char **argv) { }" HAVE_XINPUT_H)
  1130. check_c_source_compiles("
  1131. #include <windows.h>
  1132. #include <xinput.h>
  1133. XINPUT_GAMEPAD_EX x1;
  1134. int main(int argc, char **argv) { }" HAVE_XINPUT_GAMEPAD_EX)
  1135. check_c_source_compiles("
  1136. #include <windows.h>
  1137. #include <xinput.h>
  1138. XINPUT_STATE_EX s1;
  1139. int main(int argc, char **argv) { }" HAVE_XINPUT_STATE_EX)
  1140. else()
  1141. check_include_file(xinput.h HAVE_XINPUT_H)
  1142. endif()
  1143. check_include_file(d3d9.h HAVE_D3D_H)
  1144. check_include_file(d3d11_1.h HAVE_D3D11_H)
  1145. check_include_file(ddraw.h HAVE_DDRAW_H)
  1146. check_include_file(dsound.h HAVE_DSOUND_H)
  1147. check_include_file(dinput.h HAVE_DINPUT_H)
  1148. check_include_file(dxgi.h HAVE_DXGI_H)
  1149. if(HAVE_D3D_H OR HAVE_D3D11_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H)
  1150. set(HAVE_DIRECTX TRUE)
  1151. if(NOT CMAKE_COMPILER_IS_MINGW AND NOT USE_WINSDK_DIRECTX)
  1152. # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks
  1153. link_directories($ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH})
  1154. include_directories($ENV{DXSDK_DIR}\\Include)
  1155. endif()
  1156. endif()
  1157. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  1158. endif()
  1159. # headers needed elsewhere ...
  1160. check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
  1161. check_include_file(audioclient.h HAVE_AUDIOCLIENT_H)
  1162. check_include_file(endpointvolume.h HAVE_ENDPOINTVOLUME_H)
  1163. if(SDL_AUDIO)
  1164. set(SDL_AUDIO_DRIVER_WINMM 1)
  1165. file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c)
  1166. set(SOURCE_FILES ${SOURCE_FILES} ${WINMM_AUDIO_SOURCES})
  1167. set(HAVE_SDL_AUDIO TRUE)
  1168. if(HAVE_DSOUND_H)
  1169. set(SDL_AUDIO_DRIVER_DSOUND 1)
  1170. file(GLOB DSOUND_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/directsound/*.c)
  1171. set(SOURCE_FILES ${SOURCE_FILES} ${DSOUND_AUDIO_SOURCES})
  1172. endif()
  1173. if(WASAPI AND HAVE_AUDIOCLIENT_H AND HAVE_MMDEVICEAPI_H)
  1174. set(SDL_AUDIO_DRIVER_WASAPI 1)
  1175. file(GLOB WASAPI_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/wasapi/*.c)
  1176. set(SOURCE_FILES ${SOURCE_FILES} ${WASAPI_AUDIO_SOURCES})
  1177. endif()
  1178. endif()
  1179. if(SDL_VIDEO)
  1180. # requires SDL_LOADSO on Windows (IME, DX, etc.)
  1181. if(NOT SDL_LOADSO)
  1182. message_error("SDL_VIDEO requires SDL_LOADSO, which is not enabled")
  1183. endif()
  1184. set(SDL_VIDEO_DRIVER_WINDOWS 1)
  1185. file(GLOB WIN_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/windows/*.c)
  1186. set(SOURCE_FILES ${SOURCE_FILES} ${WIN_VIDEO_SOURCES})
  1187. if(RENDER_D3D AND HAVE_D3D_H)
  1188. set(SDL_VIDEO_RENDER_D3D 1)
  1189. set(HAVE_RENDER_D3D TRUE)
  1190. endif()
  1191. if(RENDER_D3D AND HAVE_D3D11_H)
  1192. set(SDL_VIDEO_RENDER_D3D11 1)
  1193. set(HAVE_RENDER_D3D TRUE)
  1194. endif()
  1195. set(HAVE_SDL_VIDEO TRUE)
  1196. endif()
  1197. if(SDL_THREADS)
  1198. set(SDL_THREAD_WINDOWS 1)
  1199. set(SOURCE_FILES ${SOURCE_FILES}
  1200. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_sysmutex.c
  1201. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_syssem.c
  1202. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systhread.c
  1203. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systls.c
  1204. ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c)
  1205. set(HAVE_SDL_THREADS TRUE)
  1206. endif()
  1207. if(SDL_POWER)
  1208. set(SDL_POWER_WINDOWS 1)
  1209. set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/power/windows/SDL_syspower.c)
  1210. set(HAVE_SDL_POWER TRUE)
  1211. endif()
  1212. if(SDL_FILESYSTEM)
  1213. set(SDL_FILESYSTEM_WINDOWS 1)
  1214. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/windows/*.c)
  1215. set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1216. set(HAVE_SDL_FILESYSTEM TRUE)
  1217. endif()
  1218. # Libraries for Win32 native and MinGW
  1219. list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 setupapi shell32)
  1220. # TODO: in configure.ac the check for timers is set on
  1221. # cygwin | mingw32* - does this include mingw32CE?
  1222. if(SDL_TIMERS)
  1223. set(SDL_TIMER_WINDOWS 1)
  1224. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/windows/*.c)
  1225. set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1226. set(HAVE_SDL_TIMERS TRUE)
  1227. endif()
  1228. if(SDL_LOADSO)
  1229. set(SDL_LOADSO_WINDOWS 1)
  1230. file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/windows/*.c)
  1231. set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
  1232. set(HAVE_SDL_LOADSO TRUE)
  1233. endif()
  1234. file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
  1235. set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
  1236. if(SDL_VIDEO)
  1237. if(VIDEO_OPENGL)
  1238. set(SDL_VIDEO_OPENGL 1)
  1239. set(SDL_VIDEO_OPENGL_WGL 1)
  1240. set(SDL_VIDEO_RENDER_OGL 1)
  1241. set(HAVE_VIDEO_OPENGL TRUE)
  1242. endif()
  1243. if(VIDEO_OPENGLES)
  1244. set(SDL_VIDEO_OPENGL_EGL 1)
  1245. set(SDL_VIDEO_OPENGL_ES2 1)
  1246. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  1247. set(HAVE_VIDEO_OPENGLES TRUE)
  1248. endif()
  1249. endif()
  1250. if(SDL_JOYSTICK)
  1251. CheckHIDAPI()
  1252. if(HAVE_HIDAPI)
  1253. set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/windows/hid.c)
  1254. endif()
  1255. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/windows/*.c)
  1256. set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1257. if(HAVE_DINPUT_H)
  1258. set(SDL_JOYSTICK_DINPUT 1)
  1259. list(APPEND EXTRA_LIBS dinput8)
  1260. if(CMAKE_COMPILER_IS_MINGW)
  1261. list(APPEND EXTRA_LIBS dxerr8)
  1262. elseif (NOT USE_WINSDK_DIRECTX)
  1263. list(APPEND EXTRA_LIBS dxerr)
  1264. endif()
  1265. endif()
  1266. if(HAVE_XINPUT_H)
  1267. set(SDL_JOYSTICK_XINPUT 1)
  1268. endif()
  1269. if(NOT HAVE_DINPUT_H AND NOT HAVE_XINPUT_H)
  1270. set(SDL_JOYSTICK_WINMM 1)
  1271. endif()
  1272. set(HAVE_SDL_JOYSTICK TRUE)
  1273. if(SDL_HAPTIC)
  1274. if(HAVE_DINPUT_H OR HAVE_XINPUT_H)
  1275. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/windows/*.c)
  1276. if(HAVE_DINPUT_H)
  1277. set(SDL_HAPTIC_DINPUT 1)
  1278. endif()
  1279. if(HAVE_XINPUT_H)
  1280. set(SDL_HAPTIC_XINPUT 1)
  1281. endif()
  1282. else()
  1283. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  1284. set(SDL_HAPTIC_DUMMY 1)
  1285. endif()
  1286. set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1287. set(HAVE_SDL_HAPTIC TRUE)
  1288. endif()
  1289. endif()
  1290. file(GLOB VERSION_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.rc)
  1291. file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.c)
  1292. if(MINGW OR CYGWIN)
  1293. list(APPEND EXTRA_LIBS mingw32)
  1294. list(APPEND EXTRA_LDFLAGS "-mwindows")
  1295. set(SDL_CFLAGS "${SDL_CFLAGS} -Dmain=SDL_main")
  1296. list(APPEND SDL_LIBS "-lmingw32" "-lSDL2main" "-mwindows")
  1297. endif()
  1298. elseif(APPLE)
  1299. # TODO: rework this all for proper MacOS X, iOS and Darwin support
  1300. # We always need these libs on macOS at the moment.
  1301. # !!! FIXME: we need Carbon for some very old API calls in
  1302. # !!! FIXME: src/video/cocoa/SDL_cocoakeyboard.c, but we should figure out
  1303. # !!! FIXME: how to dump those.
  1304. if(NOT IOS)
  1305. set(SDL_FRAMEWORK_COCOA 1)
  1306. set(SDL_FRAMEWORK_CARBON 1)
  1307. endif()
  1308. # Requires the darwin file implementation
  1309. if(SDL_FILE)
  1310. file(GLOB EXTRA_SOURCES ${SDL2_SOURCE_DIR}/src/file/cocoa/*.m)
  1311. set(SOURCE_FILES ${EXTRA_SOURCES} ${SOURCE_FILES})
  1312. # !!! FIXME: modern CMake doesn't need "LANGUAGE C" for Objective-C.
  1313. set_source_files_properties(${EXTRA_SOURCES} PROPERTIES LANGUAGE C)
  1314. set(HAVE_SDL_FILE TRUE)
  1315. # !!! FIXME: why is COREVIDEO inside this if() block?
  1316. set(SDL_FRAMEWORK_COREVIDEO 1)
  1317. else()
  1318. message_error("SDL_FILE must be enabled to build on MacOS X")
  1319. endif()
  1320. if(SDL_AUDIO)
  1321. set(SDL_AUDIO_DRIVER_COREAUDIO 1)
  1322. file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.m)
  1323. # !!! FIXME: modern CMake doesn't need "LANGUAGE C" for Objective-C.
  1324. set_source_files_properties(${AUDIO_SOURCES} PROPERTIES LANGUAGE C)
  1325. set(SOURCE_FILES ${SOURCE_FILES} ${AUDIO_SOURCES})
  1326. set(HAVE_SDL_AUDIO TRUE)
  1327. set(SDL_FRAMEWORK_COREAUDIO 1)
  1328. set(SDL_FRAMEWORK_AUDIOTOOLBOX 1)
  1329. endif()
  1330. if(SDL_JOYSTICK)
  1331. CheckHIDAPI()
  1332. if(HAVE_HIDAPI)
  1333. if(IOS)
  1334. set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/ios/hid.m)
  1335. else()
  1336. set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/mac/hid.c)
  1337. endif()
  1338. endif()
  1339. set(SDL_JOYSTICK_IOKIT 1)
  1340. if (IOS)
  1341. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
  1342. else()
  1343. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
  1344. endif()
  1345. set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1346. set(HAVE_SDL_JOYSTICK TRUE)
  1347. set(SDL_FRAMEWORK_IOKIT 1)
  1348. set(SDL_FRAMEWORK_FF 1)
  1349. endif()
  1350. if(SDL_HAPTIC)
  1351. set(SDL_HAPTIC_IOKIT 1)
  1352. if (IOS)
  1353. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  1354. set(SDL_HAPTIC_DUMMY 1)
  1355. else()
  1356. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/darwin/*.c)
  1357. endif()
  1358. set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1359. set(HAVE_SDL_HAPTIC TRUE)
  1360. set(SDL_FRAMEWORK_IOKIT 1)
  1361. set(SDL_FRAMEWORK_FF 1)
  1362. if(NOT SDL_JOYSTICK)
  1363. message(FATAL_ERROR "SDL_HAPTIC requires SDL_JOYSTICK to be enabled")
  1364. endif()
  1365. endif()
  1366. if(SDL_POWER)
  1367. set(SDL_POWER_MACOSX 1)
  1368. if (IOS)
  1369. file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/uikit/*.m)
  1370. else()
  1371. file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/macosx/*.c)
  1372. endif()
  1373. set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
  1374. set(HAVE_SDL_POWER TRUE)
  1375. set(SDL_FRAMEWORK_IOKIT 1)
  1376. endif()
  1377. if(SDL_TIMERS)
  1378. set(SDL_TIMER_UNIX 1)
  1379. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
  1380. set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1381. set(HAVE_SDL_TIMERS TRUE)
  1382. endif(SDL_TIMERS)
  1383. if(SDL_FILESYSTEM)
  1384. set(SDL_FILESYSTEM_COCOA 1)
  1385. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
  1386. # !!! FIXME: modern CMake doesn't need "LANGUAGE C" for Objective-C.
  1387. set_source_files_properties(${FILESYSTEM_SOURCES} PROPERTIES LANGUAGE C)
  1388. set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1389. set(HAVE_SDL_FILESYSTEM TRUE)
  1390. endif()
  1391. # Actually load the frameworks at the end so we don't duplicate include.
  1392. if(SDL_FRAMEWORK_COREVIDEO)
  1393. find_library(COREVIDEO CoreVideo)
  1394. list(APPEND EXTRA_LIBS ${COREVIDEO})
  1395. endif()
  1396. if(SDL_FRAMEWORK_COCOA)
  1397. find_library(COCOA_LIBRARY Cocoa)
  1398. list(APPEND EXTRA_LIBS ${COCOA_LIBRARY})
  1399. endif()
  1400. if(SDL_FRAMEWORK_IOKIT)
  1401. find_library(IOKIT IOKit)
  1402. list(APPEND EXTRA_LIBS ${IOKIT})
  1403. endif()
  1404. if(SDL_FRAMEWORK_FF)
  1405. find_library(FORCEFEEDBACK ForceFeedback)
  1406. list(APPEND EXTRA_LIBS ${FORCEFEEDBACK})
  1407. endif()
  1408. if(SDL_FRAMEWORK_CARBON)
  1409. find_library(CARBON_LIBRARY Carbon)
  1410. list(APPEND EXTRA_LIBS ${CARBON_LIBRARY})
  1411. endif()
  1412. if(SDL_FRAMEWORK_COREAUDIO)
  1413. find_library(COREAUDIO CoreAudio)
  1414. list(APPEND EXTRA_LIBS ${COREAUDIO})
  1415. endif()
  1416. if(SDL_FRAMEWORK_AUDIOTOOLBOX)
  1417. find_library(AUDIOTOOLBOX AudioToolbox)
  1418. list(APPEND EXTRA_LIBS ${AUDIOTOOLBOX})
  1419. endif()
  1420. # iOS hack needed - http://code.google.com/p/ios-cmake/ ?
  1421. if(SDL_VIDEO)
  1422. if (IOS)
  1423. set(SDL_VIDEO_DRIVER_UIKIT 1)
  1424. file(GLOB UIKITVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/uikit/*.m)
  1425. set(SOURCE_FILES ${SOURCE_FILES} ${UIKITVIDEO_SOURCES})
  1426. else()
  1427. CheckCOCOA()
  1428. if(VIDEO_OPENGL)
  1429. set(SDL_VIDEO_OPENGL 1)
  1430. set(SDL_VIDEO_OPENGL_CGL 1)
  1431. set(SDL_VIDEO_RENDER_OGL 1)
  1432. set(HAVE_VIDEO_OPENGL TRUE)
  1433. endif()
  1434. if(VIDEO_OPENGLES)
  1435. set(SDL_VIDEO_OPENGL_EGL 1)
  1436. set(SDL_VIDEO_OPENGL_ES2 1)
  1437. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  1438. set(HAVE_VIDEO_OPENGLES TRUE)
  1439. endif()
  1440. endif()
  1441. endif()
  1442. CheckPTHREAD()
  1443. elseif(HAIKU)
  1444. if(SDL_VIDEO)
  1445. set(SDL_VIDEO_DRIVER_HAIKU 1)
  1446. file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.c)
  1447. set(SOURCE_FILES ${SOURCE_FILES} ${HAIKUVIDEO_SOURCES})
  1448. set(HAVE_SDL_VIDEO TRUE)
  1449. set(SDL_FILESYSTEM_HAIKU 1)
  1450. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/haiku/*.cc)
  1451. set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1452. set(HAVE_SDL_FILESYSTEM TRUE)
  1453. if(SDL_TIMERS)
  1454. set(SDL_TIMER_HAIKU 1)
  1455. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/haiku/*.c)
  1456. set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1457. set(HAVE_SDL_TIMERS TRUE)
  1458. endif(SDL_TIMERS)
  1459. if(VIDEO_OPENGL)
  1460. # TODO: Use FIND_PACKAGE(OpenGL) instead
  1461. set(SDL_VIDEO_OPENGL 1)
  1462. set(SDL_VIDEO_OPENGL_BGL 1)
  1463. set(SDL_VIDEO_RENDER_OGL 1)
  1464. list(APPEND EXTRA_LIBS GL)
  1465. set(HAVE_VIDEO_OPENGL TRUE)
  1466. endif()
  1467. endif()
  1468. CheckPTHREAD()
  1469. endif()
  1470. if(VIDEO_VULKAN)
  1471. set(SDL_VIDEO_VULKAN 1)
  1472. set(HAVE_VIDEO_VULKAN TRUE)
  1473. endif()
  1474. # Dummies
  1475. # configure.ac does it differently:
  1476. # if not have X
  1477. # if enable_X { SDL_X_DISABLED = 1 }
  1478. # [add dummy sources]
  1479. # so it always adds a dummy, without checking, if it was actually requested.
  1480. # This leads to missing internal references on building, since the
  1481. # src/X/*.c does not get included.
  1482. if(NOT HAVE_SDL_JOYSTICK)
  1483. set(SDL_JOYSTICK_DUMMY 1)
  1484. if(SDL_JOYSTICK AND NOT APPLE) # results in unresolved symbols on OSX
  1485. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dummy/*.c)
  1486. set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1487. endif()
  1488. endif()
  1489. if(NOT HAVE_SDL_HAPTIC)
  1490. set(SDL_HAPTIC_DUMMY 1)
  1491. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  1492. set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1493. endif()
  1494. if(NOT HAVE_SDL_SENSORS)
  1495. set(SDL_SENSOR_DUMMY 1)
  1496. file(GLOB SENSORS_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/dummy/*.c)
  1497. set(SOURCE_FILES ${SOURCE_FILES} ${SENSORS_SOURCES})
  1498. endif()
  1499. if(NOT HAVE_SDL_LOADSO)
  1500. set(SDL_LOADSO_DISABLED 1)
  1501. file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
  1502. set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
  1503. endif()
  1504. if(NOT HAVE_SDL_FILESYSTEM)
  1505. set(SDL_FILESYSTEM_DISABLED 1)
  1506. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c)
  1507. set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1508. endif()
  1509. # We always need to have threads and timers around
  1510. if(NOT HAVE_SDL_THREADS)
  1511. set(SDL_THREADS_DISABLED 1)
  1512. file(GLOB THREADS_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/*.c)
  1513. set(SOURCE_FILES ${SOURCE_FILES} ${THREADS_SOURCES})
  1514. endif()
  1515. if(NOT HAVE_SDL_TIMERS)
  1516. set(SDL_TIMERS_DISABLED 1)
  1517. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/dummy/*.c)
  1518. set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1519. endif()
  1520. if(NOT SDLMAIN_SOURCES)
  1521. file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/dummy/*.c)
  1522. endif()
  1523. # Append the -MMD -MT flags
  1524. # if(DEPENDENCY_TRACKING)
  1525. # if(COMPILER_IS_GNUCC)
  1526. # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MMD -MT \$@")
  1527. # endif()
  1528. # endif()
  1529. configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
  1530. "${SDL2_BINARY_DIR}/include/SDL_config.h")
  1531. # Prepare the flags and remove duplicates
  1532. if(EXTRA_LDFLAGS)
  1533. list(REMOVE_DUPLICATES EXTRA_LDFLAGS)
  1534. endif()
  1535. if(EXTRA_LIBS)
  1536. list(REMOVE_DUPLICATES EXTRA_LIBS)
  1537. endif()
  1538. if(EXTRA_CFLAGS)
  1539. list(REMOVE_DUPLICATES EXTRA_CFLAGS)
  1540. endif()
  1541. listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
  1542. set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
  1543. # Compat helpers for the configuration files
  1544. if(NOT WINDOWS OR CYGWIN)
  1545. # TODO: we need a Windows script, too
  1546. execute_process(COMMAND sh ${SDL2_SOURCE_DIR}/build-scripts/updaterev.sh)
  1547. set(prefix ${CMAKE_INSTALL_PREFIX})
  1548. set(exec_prefix "\${prefix}")
  1549. set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
  1550. set(bindir "\${exec_prefix}/bin")
  1551. set(includedir "\${prefix}/include")
  1552. if(SDL_STATIC)
  1553. set(ENABLE_STATIC_TRUE "")
  1554. set(ENABLE_STATIC_FALSE "#")
  1555. else()
  1556. set(ENABLE_STATIC_TRUE "#")
  1557. set(ENABLE_STATIC_FALSE "")
  1558. endif()
  1559. if(SDL_SHARED)
  1560. set(ENABLE_SHARED_TRUE "")
  1561. set(ENABLE_SHARED_FALSE "#")
  1562. else()
  1563. set(ENABLE_SHARED_TRUE "#")
  1564. set(ENABLE_SHARED_FALSE "")
  1565. endif()
  1566. # Clean up the different lists
  1567. listtostr(EXTRA_LIBS _EXTRA_LIBS "-l")
  1568. set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
  1569. list(REMOVE_DUPLICATES SDL_STATIC_LIBS)
  1570. listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS)
  1571. set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS})
  1572. listtostr(SDL_LIBS _SDL_LIBS)
  1573. set(SDL_LIBS ${_SDL_LIBS})
  1574. # MESSAGE(STATUS "SDL_LIBS: ${SDL_LIBS}")
  1575. # MESSAGE(STATUS "SDL_STATIC_LIBS: ${SDL_STATIC_LIBS}")
  1576. configure_file("${SDL2_SOURCE_DIR}/sdl2.pc.in"
  1577. "${SDL2_BINARY_DIR}/sdl2.pc" @ONLY)
  1578. configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1579. "${SDL2_BINARY_DIR}/sdl2-config")
  1580. configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1581. "${SDL2_BINARY_DIR}/sdl2-config" @ONLY)
  1582. configure_file("${SDL2_SOURCE_DIR}/SDL2.spec.in"
  1583. "${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
  1584. endif()
  1585. ##### Info output #####
  1586. message(STATUS "")
  1587. message(STATUS "SDL2 was configured with the following options:")
  1588. message(STATUS "")
  1589. message(STATUS "Platform: ${CMAKE_SYSTEM}")
  1590. message(STATUS "64-bit: ${ARCH_64}")
  1591. message(STATUS "Compiler: ${CMAKE_C_COMPILER}")
  1592. message(STATUS "")
  1593. message(STATUS "Subsystems:")
  1594. foreach(_SUB ${SDL_SUBSYSTEMS})
  1595. string(TOUPPER ${_SUB} _OPT)
  1596. message_bool_option(${_SUB} SDL_${_OPT})
  1597. endforeach()
  1598. message(STATUS "")
  1599. message(STATUS "Options:")
  1600. list(SORT ALLOPTIONS)
  1601. foreach(_OPT ${ALLOPTIONS})
  1602. # Longest option is VIDEO_X11_XSCREENSAVER = 22 characters
  1603. # Get the padding
  1604. string(LENGTH ${_OPT} _OPTLEN)
  1605. math(EXPR _PADLEN "23 - ${_OPTLEN}")
  1606. string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
  1607. message_tested_option(${_OPT} ${_PADDING})
  1608. endforeach()
  1609. message(STATUS "")
  1610. message(STATUS " CFLAGS: ${CMAKE_C_FLAGS}")
  1611. message(STATUS " EXTRA_CFLAGS: ${EXTRA_CFLAGS}")
  1612. message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS}")
  1613. message(STATUS " EXTRA_LIBS: ${EXTRA_LIBS}")
  1614. message(STATUS "")
  1615. message(STATUS " Build Shared Library: ${SDL_SHARED}")
  1616. message(STATUS " Build Static Library: ${SDL_STATIC}")
  1617. if(SDL_STATIC)
  1618. message(STATUS " Build Static Library with Position Independent Code: ${SDL_STATIC_PIC}")
  1619. endif()
  1620. message(STATUS "")
  1621. if(UNIX)
  1622. message(STATUS "If something was not detected, although the libraries")
  1623. message(STATUS "were installed, then make sure you have set the")
  1624. message(STATUS "CFLAGS and LDFLAGS environment variables correctly.")
  1625. message(STATUS "")
  1626. endif()
  1627. # Ensure that the extra cflags are used at compile time
  1628. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
  1629. # Always build SDLmain
  1630. add_library(SDL2main STATIC ${SDLMAIN_SOURCES})
  1631. target_include_directories(SDL2main PUBLIC "$<BUILD_INTERFACE:${SDL2_SOURCE_DIR}/include>" $<INSTALL_INTERFACE:include/SDL2>)
  1632. set(_INSTALL_LIBS "SDL2main")
  1633. if (NOT ANDROID)
  1634. set_target_properties(SDL2main PROPERTIES DEBUG_POSTFIX ${SDL_CMAKE_DEBUG_POSTFIX})
  1635. endif()
  1636. if(SDL_SHARED)
  1637. add_library(SDL2 SHARED ${SOURCE_FILES} ${VERSION_SOURCES})
  1638. if(APPLE)
  1639. set_target_properties(SDL2 PROPERTIES
  1640. MACOSX_RPATH 1
  1641. OUTPUT_NAME "SDL2-${LT_RELEASE}")
  1642. elseif(UNIX AND NOT ANDROID)
  1643. set_target_properties(SDL2 PROPERTIES
  1644. VERSION ${LT_VERSION}
  1645. SOVERSION ${LT_REVISION}
  1646. OUTPUT_NAME "SDL2-${LT_RELEASE}")
  1647. else()
  1648. set_target_properties(SDL2 PROPERTIES
  1649. VERSION ${SDL_VERSION}
  1650. SOVERSION ${LT_REVISION}
  1651. OUTPUT_NAME "SDL2")
  1652. endif()
  1653. if(MSVC AND NOT LIBC)
  1654. # Don't try to link with the default set of libraries.
  1655. set_target_properties(SDL2 PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
  1656. set_target_properties(SDL2 PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
  1657. set_target_properties(SDL2 PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
  1658. endif()
  1659. set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
  1660. target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1661. target_include_directories(SDL2 PUBLIC "$<BUILD_INTERFACE:${SDL2_SOURCE_DIR}/include>" $<INSTALL_INTERFACE:include/SDL2>)
  1662. if (NOT ANDROID)
  1663. set_target_properties(SDL2 PROPERTIES DEBUG_POSTFIX ${SDL_CMAKE_DEBUG_POSTFIX})
  1664. endif()
  1665. endif()
  1666. if(ANDROID)
  1667. if(HAVE_HIDAPI)
  1668. add_library(hidapi SHARED ${SDL2_SOURCE_DIR}/src/hidapi/android/hid.cpp)
  1669. endif()
  1670. if(MSVC AND NOT LIBC)
  1671. # Don't try to link with the default set of libraries.
  1672. set_target_properties(hidapi PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
  1673. set_target_properties(hidapi PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
  1674. set_target_properties(hidapi PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
  1675. endif()
  1676. target_link_libraries(hidapi log)
  1677. endif()
  1678. if(SDL_STATIC)
  1679. set (BUILD_SHARED_LIBS FALSE)
  1680. add_library(SDL2-static STATIC ${SOURCE_FILES})
  1681. if (NOT SDL_SHARED OR NOT WIN32)
  1682. set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
  1683. # Note: Apparently, OUTPUT_NAME must really be unique; even when
  1684. # CMAKE_IMPORT_LIBRARY_SUFFIX or the like are given. Otherwise
  1685. # the static build may race with the import lib and one will get
  1686. # clobbered, when the suffix is realized via subsequent rename.
  1687. endif()
  1688. set_target_properties(SDL2-static PROPERTIES POSITION_INDEPENDENT_CODE ${SDL_STATIC_PIC})
  1689. if(MSVC AND NOT LIBC)
  1690. set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
  1691. set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
  1692. set_target_properties(SDL2-static PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
  1693. endif()
  1694. # TODO: Win32 platforms keep the same suffix .lib for import and static
  1695. # libraries - do we need to consider this?
  1696. set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS})
  1697. target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1698. target_include_directories(SDL2-static PUBLIC "$<BUILD_INTERFACE:${SDL2_SOURCE_DIR}/include>" $<INSTALL_INTERFACE:include/SDL2>)
  1699. if (NOT ANDROID)
  1700. set_target_properties(SDL2-static PROPERTIES DEBUG_POSTFIX ${SDL_CMAKE_DEBUG_POSTFIX})
  1701. endif()
  1702. endif()
  1703. ##### Tests #####
  1704. if(SDL_TEST)
  1705. file(GLOB TEST_SOURCES ${SDL2_SOURCE_DIR}/src/test/*.c)
  1706. add_library(SDL2_test STATIC ${TEST_SOURCES})
  1707. add_subdirectory(test)
  1708. endif()
  1709. ##### Installation targets #####
  1710. install(TARGETS ${_INSTALL_LIBS} EXPORT SDL2Targets
  1711. LIBRARY DESTINATION "lib${LIB_SUFFIX}"
  1712. ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
  1713. RUNTIME DESTINATION bin)
  1714. ##### Export files #####
  1715. if (WINDOWS)
  1716. set(PKG_PREFIX "cmake")
  1717. else ()
  1718. set(PKG_PREFIX "lib/cmake/SDL2")
  1719. endif ()
  1720. include(CMakePackageConfigHelpers)
  1721. write_basic_package_version_file("${CMAKE_BINARY_DIR}/SDL2ConfigVersion.cmake"
  1722. VERSION ${SDL_VERSION}
  1723. COMPATIBILITY AnyNewerVersion
  1724. )
  1725. install(EXPORT SDL2Targets
  1726. FILE SDL2Targets.cmake
  1727. NAMESPACE SDL2::
  1728. DESTINATION ${PKG_PREFIX}
  1729. )
  1730. install(
  1731. FILES
  1732. ${CMAKE_CURRENT_SOURCE_DIR}/SDL2Config.cmake
  1733. ${CMAKE_BINARY_DIR}/SDL2ConfigVersion.cmake
  1734. DESTINATION ${PKG_PREFIX}
  1735. COMPONENT Devel
  1736. )
  1737. file(GLOB INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/*.h)
  1738. file(GLOB BIN_INCLUDE_FILES ${SDL2_BINARY_DIR}/include/*.h)
  1739. foreach(_FNAME ${BIN_INCLUDE_FILES})
  1740. get_filename_component(_INCNAME ${_FNAME} NAME)
  1741. list(REMOVE_ITEM INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/${_INCNAME})
  1742. endforeach()
  1743. list(APPEND INCLUDE_FILES ${BIN_INCLUDE_FILES})
  1744. install(FILES ${INCLUDE_FILES} DESTINATION include/SDL2)
  1745. string(TOUPPER "${CMAKE_BUILD_TYPE}" UPPER_BUILD_TYPE)
  1746. if (UPPER_BUILD_TYPE MATCHES DEBUG)
  1747. set(SOPOSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
  1748. else()
  1749. set(SOPOSTFIX "")
  1750. endif()
  1751. if(NOT (WINDOWS OR CYGWIN))
  1752. if(SDL_SHARED)
  1753. set(SOEXT ${CMAKE_SHARED_LIBRARY_SUFFIX}) # ".so", ".dylib", etc.
  1754. get_target_property(SONAME SDL2 OUTPUT_NAME)
  1755. if(NOT ANDROID)
  1756. install(CODE "
  1757. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
  1758. \"lib${SONAME}${SOPOSTFIX}${SOEXT}\" \"libSDL2${SOPOSTFIX}${SOEXT}\"
  1759. WORKING_DIRECTORY \"${SDL2_BINARY_DIR}\")")
  1760. install(FILES ${SDL2_BINARY_DIR}/libSDL2${SOPOSTFIX}${SOEXT} DESTINATION "lib${LIB_SUFFIX}")
  1761. endif()
  1762. endif()
  1763. if(FREEBSD)
  1764. # FreeBSD uses ${PREFIX}/libdata/pkgconfig
  1765. install(FILES ${SDL2_BINARY_DIR}/sdl2.pc DESTINATION "libdata/pkgconfig")
  1766. else()
  1767. install(FILES ${SDL2_BINARY_DIR}/sdl2.pc
  1768. DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
  1769. endif()
  1770. install(PROGRAMS ${SDL2_BINARY_DIR}/sdl2-config DESTINATION bin)
  1771. # TODO: what about the .spec file? Is it only needed for RPM creation?
  1772. install(FILES "${SDL2_SOURCE_DIR}/sdl2.m4" DESTINATION "${CMAKE_INSTALL_FULL_DATAROOTDIR}/aclocal")
  1773. endif()
  1774. ##### Uninstall target #####
  1775. if(NOT TARGET uninstall)
  1776. configure_file(
  1777. "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  1778. "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  1779. IMMEDIATE @ONLY)
  1780. add_custom_target(uninstall
  1781. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
  1782. endif()