🛠️🐜 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.

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