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

3570 lines
122 KiB

  1. if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
  2. message(FATAL_ERROR "Prevented in-tree build. Please create a build directory outside of the SDL source code and run \"cmake -S ${CMAKE_SOURCE_DIR} -B .\" from there")
  3. endif()
  4. cmake_minimum_required(VERSION 3.0.0)
  5. project(SDL2 C CXX)
  6. if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
  7. set(SDL2_SUBPROJECT OFF)
  8. else()
  9. set(SDL2_SUBPROJECT ON)
  10. endif()
  11. if (HAIKU)
  12. set(LINKER_LANGUAGE CXX)
  13. endif()
  14. set(EXTRA_LIBS)
  15. set(EXTRA_LDFLAGS)
  16. # This is a virtual "library" that just exists to collect up compiler and
  17. # linker options that used to be global to this CMake project. When you
  18. # specify it as part of a real library's target_link_libraries(), that
  19. # library will also gain all those build options too. This is meant to
  20. # modularize old calls to the global add_definitions and include_directories,
  21. # etc. See https://github.com/libsdl-org/SDL/issues/4150
  22. add_library(sdl-build-options INTERFACE)
  23. if(WINDOWS_STORE)
  24. cmake_minimum_required(VERSION 3.11.0)
  25. target_compile_definitions(sdl-build-options INTERFACE "-DSDL_BUILDING_WINRT=1")
  26. target_compile_options(sdl-build-options INTERFACE "-ZW")
  27. endif()
  28. # Build in parallel under Visual Studio. Not enabled by default.
  29. if(MSVC)
  30. target_compile_options(sdl-build-options INTERFACE "/MP")
  31. endif()
  32. # CMake 3.0 expands the "if(${A})" in "set(OFF 1);set(A OFF);if(${A})" to "if(1)"
  33. # CMake 3.24+ emits a warning when not set.
  34. unset(OFF)
  35. unset(ON)
  36. if(POLICY CMP0054)
  37. cmake_policy(SET CMP0054 NEW)
  38. endif()
  39. # !!! FIXME: this should probably do "MACOSX_RPATH ON" as a target property
  40. # !!! FIXME: for the SDL2 shared library (so you get an
  41. # !!! FIXME: install_name ("soname") of "@rpath/libSDL-whatever.dylib"
  42. # !!! FIXME: instead of "/usr/local/lib/libSDL-whatever.dylib"), but I'm
  43. # !!! FIXME: punting for now and leaving the existing behavior. Until this
  44. # !!! FIXME: properly resolved, this line silences a warning in CMake 3.0+.
  45. # !!! FIXME: remove it and this comment entirely once the problem is
  46. # !!! FIXME: properly resolved.
  47. #cmake_policy(SET CMP0042 OLD)
  48. include(CheckLibraryExists)
  49. include(CheckIncludeFiles)
  50. include(CheckIncludeFile)
  51. include(CheckLanguage)
  52. include(CheckSymbolExists)
  53. include(CheckCSourceCompiles)
  54. include(CheckCSourceRuns)
  55. include(CheckCCompilerFlag)
  56. include(CheckCXXCompilerFlag)
  57. include(CheckStructHasMember)
  58. include(CMakeDependentOption)
  59. include(CMakePushCheckState)
  60. include(GNUInstallDirs)
  61. find_package(PkgConfig)
  62. list(APPEND CMAKE_MODULE_PATH "${SDL2_SOURCE_DIR}/cmake")
  63. include(${SDL2_SOURCE_DIR}/cmake/macros.cmake)
  64. include(${SDL2_SOURCE_DIR}/cmake/sdlchecks.cmake)
  65. include(${SDL2_SOURCE_DIR}/cmake/CheckCPUArchitecture.cmake)
  66. # Enable large file support on 32-bit glibc, so that we can access files
  67. # with large inode numbers
  68. check_symbol_exists("__GLIBC__" "stdlib.h" LIBC_IS_GLIBC)
  69. if (LIBC_IS_GLIBC AND CMAKE_SIZEOF_VOID_P EQUAL 4)
  70. add_definitions(-D_FILE_OFFSET_BITS=64)
  71. endif()
  72. # See docs/release_checklist.md
  73. set(SDL_MAJOR_VERSION 2)
  74. set(SDL_MINOR_VERSION 26)
  75. set(SDL_MICRO_VERSION 3)
  76. set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}")
  77. # Set defaults preventing destination file conflicts
  78. set(SDL_CMAKE_DEBUG_POSTFIX "d"
  79. CACHE STRING "Name suffix for debug builds")
  80. mark_as_advanced(CMAKE_IMPORT_LIBRARY_SUFFIX SDL_CMAKE_DEBUG_POSTFIX)
  81. # Calculate a libtool-like version number
  82. math(EXPR SDL_BINARY_AGE "${SDL_MINOR_VERSION} * 100 + ${SDL_MICRO_VERSION}")
  83. if(SDL_MINOR_VERSION MATCHES "[02468]$")
  84. # Stable branch, 2.24.1 -> libSDL2-2.0.so.0.2400.1
  85. set(SDL_INTERFACE_AGE ${SDL_MICRO_VERSION})
  86. else()
  87. # Development branch, 2.23.1 -> libSDL2-2.0.so.0.2301.0
  88. set(SDL_INTERFACE_AGE 0)
  89. endif()
  90. # Increment this if there is an incompatible change - but if that happens,
  91. # we should rename the library from SDL2 to SDL3, at which point this would
  92. # reset to 0 anyway.
  93. set(LT_MAJOR "0")
  94. math(EXPR LT_AGE "${SDL_BINARY_AGE} - ${SDL_INTERFACE_AGE}")
  95. math(EXPR LT_CURRENT "${LT_MAJOR} + ${LT_AGE}")
  96. set(LT_REVISION "${SDL_INTERFACE_AGE}")
  97. # For historical reasons, the library name redundantly includes the major
  98. # version twice: libSDL2-2.0.so.0.
  99. # TODO: in SDL 3, set the OUTPUT_NAME to plain SDL3, which will simplify
  100. # it to libSDL3.so.0
  101. set(LT_RELEASE "2.0")
  102. set(LT_VERSION "${LT_MAJOR}.${LT_AGE}.${LT_REVISION}")
  103. # The following should match the versions in the Xcode project file.
  104. # Each version is 1 higher than you might expect, for compatibility
  105. # with libtool: macOS ABI versioning is 1-based, unlike other platforms
  106. # which are normally 0-based.
  107. math(EXPR DYLIB_CURRENT_VERSION_MAJOR "${LT_MAJOR} + ${LT_AGE} + 1")
  108. math(EXPR DYLIB_CURRENT_VERSION_MINOR "${LT_REVISION}")
  109. set(DYLIB_CURRENT_VERSION "${DYLIB_CURRENT_VERSION_MAJOR}.${DYLIB_CURRENT_VERSION_MINOR}.0")
  110. set(DYLIB_COMPATIBILITY_VERSION "${DYLIB_CURRENT_VERSION_MAJOR}.0.0")
  111. # This list holds all generated headers.
  112. # To avoid generating them twice, these are added to a dummy target on which all sdl targets depend.
  113. set(SDL_GENERATED_HEADERS)
  114. #message(STATUS "${LT_VERSION} :: ${LT_AGE} :: ${LT_REVISION} :: ${LT_CURRENT} :: ${LT_RELEASE}")
  115. # General settings & flags
  116. set(LIBRARY_OUTPUT_DIRECTORY "build")
  117. # Check for 64 or 32 bit
  118. set(SIZEOF_VOIDP ${CMAKE_SIZEOF_VOID_P})
  119. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  120. set(ARCH_64 TRUE)
  121. set(PROCESSOR_ARCH "x64")
  122. else()
  123. set(ARCH_64 FALSE)
  124. set(PROCESSOR_ARCH "x86")
  125. endif()
  126. set(LIBNAME SDL2)
  127. if(NOT LIBTYPE)
  128. set(LIBTYPE SHARED)
  129. endif()
  130. # Get the platform
  131. if(WIN32)
  132. if(NOT WINDOWS)
  133. set(WINDOWS TRUE)
  134. endif()
  135. elseif(UNIX AND NOT APPLE)
  136. if(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
  137. set(LINUX TRUE)
  138. elseif(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*")
  139. set(FREEBSD TRUE)
  140. elseif(CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*")
  141. set(NETBSD TRUE)
  142. elseif(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
  143. set(OPENBSD TRUE)
  144. elseif(CMAKE_SYSTEM_NAME MATCHES ".*GNU.*")
  145. set(GNU TRUE)
  146. elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
  147. set(BSDI TRUE)
  148. elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")
  149. set(FREEBSD TRUE)
  150. elseif(CMAKE_SYSTEM_NAME MATCHES "SYSV5.*")
  151. set(SYSV5 TRUE)
  152. elseif(CMAKE_SYSTEM_NAME MATCHES "Solaris.*|SunOS.*")
  153. set(SOLARIS TRUE)
  154. elseif(CMAKE_SYSTEM_NAME MATCHES "HP-UX.*")
  155. set(HPUX TRUE)
  156. elseif(CMAKE_SYSTEM_NAME MATCHES "AIX.*")
  157. set(AIX TRUE)
  158. elseif(CMAKE_SYSTEM_NAME MATCHES "Minix.*")
  159. set(MINIX TRUE)
  160. endif()
  161. elseif(APPLE)
  162. if(CMAKE_SYSTEM_NAME MATCHES ".*Darwin.*")
  163. set(DARWIN TRUE)
  164. elseif(CMAKE_SYSTEM_NAME MATCHES ".*MacOS.*")
  165. set(MACOSX TRUE)
  166. elseif(CMAKE_SYSTEM_NAME MATCHES ".*tvOS.*")
  167. set(TVOS TRUE)
  168. elseif(CMAKE_SYSTEM_NAME MATCHES ".*iOS.*")
  169. # !!! FIXME: remove the version check when we start requiring >= 3.14.0
  170. if(CMAKE_VERSION VERSION_LESS 3.14)
  171. set(IOS TRUE)
  172. endif()
  173. endif()
  174. elseif(CMAKE_SYSTEM_NAME MATCHES "BeOS.*")
  175. message_error("BeOS support has been removed as of SDL 2.0.2.")
  176. elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku.*")
  177. set(HAIKU TRUE)
  178. elseif(NINTENDO_3DS)
  179. set(N3DS TRUE)
  180. endif()
  181. # Don't mistake osx for unix
  182. if(UNIX AND NOT ANDROID AND NOT APPLE AND NOT RISCOS)
  183. set(UNIX_SYS ON)
  184. else()
  185. set(UNIX_SYS OFF)
  186. endif()
  187. if(UNIX OR APPLE)
  188. set(UNIX_OR_MAC_SYS ON)
  189. else()
  190. set(UNIX_OR_MAC_SYS OFF)
  191. endif()
  192. # Emscripten pthreads work, but you need to have a non-pthread fallback build
  193. # for systems without support. It's not currently enough to not use
  194. # pthread functions in a pthread-build; it won't start up on unsupported
  195. # browsers. As such, you have to explicitly enable it on Emscripten builds
  196. # for the time being. This default with change to ON once this becomes
  197. # commonly supported in browsers or the Emscripten teams makes a single
  198. # binary work everywhere.
  199. if (UNIX_OR_MAC_SYS AND NOT EMSCRIPTEN)
  200. set(SDL_PTHREADS_ENABLED_BY_DEFAULT ON)
  201. else()
  202. set(SDL_PTHREADS_ENABLED_BY_DEFAULT OFF)
  203. endif()
  204. if(UNIX_SYS OR ANDROID)
  205. set(SDL_CLOCK_GETTIME_ENABLED_BY_DEFAULT ON)
  206. else()
  207. set(SDL_CLOCK_GETTIME_ENABLED_BY_DEFAULT OFF)
  208. endif()
  209. # The hidraw support doesn't catch Xbox, PS4 and Nintendo controllers,
  210. # so we'll just use libusb when it's available. libusb does not support iOS,
  211. # so we default to yes on iOS.
  212. # TODO: Windows can support libusb, the hid.c file just depends on Unix APIs
  213. if((WINDOWS AND NOT WINDOWS_STORE) OR IOS OR TVOS OR ANDROID)
  214. set(HIDAPI_SKIP_LIBUSB TRUE)
  215. else()
  216. set(HIDAPI_SKIP_LIBUSB FALSE)
  217. endif()
  218. # On the other hand, *BSD specifically uses libusb only, so we make a special
  219. # case just for them.
  220. if(FREEBSD OR NETBSD OR OPENBSD OR BSDI)
  221. set(HIDAPI_ONLY_LIBUSB TRUE)
  222. else()
  223. set(HIDAPI_ONLY_LIBUSB FALSE)
  224. endif()
  225. # Compiler info
  226. if(CMAKE_C_COMPILER_ID MATCHES "Clang")
  227. set(USE_CLANG TRUE)
  228. set(OPT_DEF_ASM TRUE)
  229. # Visual Studio 2019 v16.2 added support for Clang/LLVM.
  230. # Check if a Visual Studio project is being generated with the Clang toolset.
  231. if(MSVC)
  232. set(MSVC_CLANG TRUE)
  233. endif()
  234. elseif(CMAKE_COMPILER_IS_GNUCC)
  235. set(USE_GCC TRUE)
  236. set(OPT_DEF_ASM TRUE)
  237. elseif(MSVC_VERSION GREATER 1400) # VisualStudio 8.0+
  238. set(OPT_DEF_ASM TRUE)
  239. #set(CMAKE_C_FLAGS "/ZI /WX- /
  240. else()
  241. set(OPT_DEF_ASM FALSE)
  242. endif()
  243. if(USE_GCC OR USE_CLANG)
  244. set(OPT_DEF_GCC_ATOMICS ON)
  245. endif()
  246. # Default option knobs
  247. if(APPLE OR ARCH_64 OR MSVC_CLANG)
  248. if(NOT "${CMAKE_OSX_ARCHITECTURES}" MATCHES "arm")
  249. set(OPT_DEF_SSEMATH ON)
  250. endif()
  251. endif()
  252. if(UNIX OR MINGW OR MSYS OR (USE_CLANG AND NOT WINDOWS) OR VITA OR PSP OR PS2 OR N3DS)
  253. set(OPT_DEF_LIBC ON)
  254. endif()
  255. if(NOT ("$ENV{CFLAGS}" STREQUAL ""))
  256. if(CMAKE_VERSION VERSION_LESS 3.11.0)
  257. message(WARNING "SDL's CMakeLists.txt no longer checks the CFLAGS environment.")
  258. message(WARNING "Please use CMake's CMAKE_C_FLAGS and CMAKE_BUILD_TYPE variables directly.")
  259. message(WARNING "Or upgrade to CMake >= 3.11.0, which respects the CFLAGS environment var.")
  260. endif()
  261. endif()
  262. if(MSVC)
  263. option(SDL_FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
  264. if(SDL_FORCE_STATIC_VCRT)
  265. foreach(flag_var
  266. CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  267. CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
  268. if(${flag_var} MATCHES "/MD")
  269. string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
  270. endif()
  271. endforeach()
  272. endif()
  273. if(NOT SDL_LIBC)
  274. # Make sure /RTC1 is disabled, otherwise it will use functions from the CRT
  275. foreach(flag_var
  276. CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  277. CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
  278. string(REGEX REPLACE "/RTC(su|[1su])" "" ${flag_var} "${${flag_var}}")
  279. endforeach(flag_var)
  280. endif()
  281. if(MSVC_CLANG)
  282. # clang-cl treats /W4 as '-Wall -Wextra' -- we don't need -Wextra
  283. foreach(flag_var
  284. CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  285. CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
  286. string(REGEX REPLACE "/W4" "/W3" ${flag_var} "${${flag_var}}")
  287. endforeach(flag_var)
  288. endif()
  289. endif()
  290. # Those are used for pkg-config and friends, so that the sdl2.pc, sdl2-config,
  291. # etc. are created correctly.
  292. set(SDL_LIBS "-lSDL2")
  293. set(SDL_CFLAGS )
  294. # When building shared lib for Windows with MinGW,
  295. # avoid the DLL having a "lib" prefix
  296. if(WINDOWS)
  297. set(CMAKE_SHARED_LIBRARY_PREFIX "")
  298. endif()
  299. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_GNU_SOURCE=1")
  300. # Emscripten toolchain has a nonempty default value for this, and the checks
  301. # in this file need to change that, so remember the original value, and
  302. # restore back to that afterwards. For check_function_exists() to work in
  303. # Emscripten, this value must be at its default value.
  304. set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
  305. if(CYGWIN)
  306. # We build SDL on cygwin without the UNIX emulation layer
  307. target_include_directories(sdl-build-options INTERFACE "/usr/include/mingw")
  308. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mno-cygwin")
  309. check_c_source_compiles("int main(int argc, char **argv) { return 0; }"
  310. HAVE_GCC_NO_CYGWIN)
  311. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  312. if(HAVE_GCC_NO_CYGWIN)
  313. list(APPEND EXTRA_LDFLAGS_BUILD "-mno-cygwin")
  314. list(APPEND SDL_LIBS "-mno-cygwin")
  315. endif()
  316. list(APPEND SDL_CFLAGS "-I/usr/include/mingw")
  317. endif()
  318. # General includes
  319. target_compile_definitions(sdl-build-options INTERFACE "-DUSING_GENERATED_CONFIG_H")
  320. target_include_directories(sdl-build-options BEFORE INTERFACE "${SDL2_BINARY_DIR}/include" "${SDL2_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>")
  321. # Note: The clang toolset for Visual Studio does not support the '-idirafter' option.
  322. if(USE_GCC OR (USE_CLANG AND NOT MSVC_CLANG))
  323. # !!! FIXME: do we _need_ to mess with CMAKE_C_FLAGS here?
  324. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -idirafter \"${SDL2_SOURCE_DIR}/src/video/khronos\"")
  325. else()
  326. target_include_directories(sdl-build-options INTERFACE "${SDL2_SOURCE_DIR}/src/video/khronos")
  327. endif()
  328. # All these ENABLED_BY_DEFAULT vars will default to ON if not specified, so
  329. # you only need to have a platform override them if they are disabling.
  330. set(OPT_DEF_ASM TRUE)
  331. if(EMSCRIPTEN)
  332. # Set up default values for the currently supported set of subsystems:
  333. # Emscripten/Javascript does not have assembly support, a dynamic library
  334. # loading architecture, or low-level CPU inspection.
  335. # SDL_THREADS_ENABLED_BY_DEFAULT now defaults to ON, but pthread support might be disabled by default.
  336. # !!! FIXME: most of these subsystems should default to ON if there are dummy implementations to be used.
  337. set(OPT_DEF_ASM FALSE)
  338. set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
  339. set(SDL_ATOMIC_ENABLED_BY_DEFAULT OFF)
  340. set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF)
  341. set(SDL_CPUINFO_ENABLED_BY_DEFAULT OFF)
  342. endif()
  343. if(VITA OR PSP OR PS2 OR N3DS)
  344. set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
  345. set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF)
  346. endif()
  347. # When defined, respect CMake's BUILD_SHARED_LIBS setting:
  348. set(SDL_STATIC_ENABLED_BY_DEFAULT ON)
  349. if (NOT DEFINED SDL_SHARED_ENABLED_BY_DEFAULT)
  350. # ...unless decided already (as for EMSCRIPTEN)
  351. set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
  352. if (NOT DEFINED BUILD_SHARED_LIBS)
  353. # No preference? Build both, just like the AC/AM configure
  354. set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
  355. elseif (BUILD_SHARED_LIBS)
  356. # In this case, we assume the user wants a shared lib and don't build
  357. # the static one
  358. set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
  359. set(SDL_STATIC_ENABLED_BY_DEFAULT OFF)
  360. endif()
  361. endif()
  362. if (NOT DEFINED SDL_TEST_ENABLED_BY_DEFAULT)
  363. set(SDL_TEST_ENABLED_BY_DEFAULT ON)
  364. endif()
  365. set(LONGESTOPTIONNAME 0) # set_option and friends will change this.
  366. set(SDL_SUBSYSTEMS
  367. Atomic Audio Video Render Events Joystick Haptic Hidapi Power Threads Timers
  368. File Loadso CPUinfo Filesystem Sensor Locale Misc)
  369. foreach(_SUB ${SDL_SUBSYSTEMS})
  370. string(TOUPPER ${_SUB} _OPT)
  371. if (NOT DEFINED SDL_${_OPT}_ENABLED_BY_DEFAULT)
  372. set(SDL_${_OPT}_ENABLED_BY_DEFAULT ON)
  373. endif()
  374. option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ${SDL_${_OPT}_ENABLED_BY_DEFAULT})
  375. endforeach()
  376. # Allow some projects to be built conditionally.
  377. set_option(SDL2_DISABLE_SDL2MAIN "Disable building/installation of SDL2main" OFF)
  378. set_option(SDL2_DISABLE_INSTALL "Disable installation of SDL2" ${SDL2_SUBPROJECT})
  379. set_option(SDL2_DISABLE_UNINSTALL "Disable uninstallation of SDL2" OFF)
  380. option_string(SDL_ASSERTIONS "Enable internal sanity checks (auto/disabled/release/enabled/paranoid)" "auto")
  381. #set_option(SDL_DEPENDENCY_TRACKING "Use gcc -MMD -MT dependency tracking" ON)
  382. set_option(SDL_LIBC "Use the system C library" ${OPT_DEF_LIBC})
  383. set_option(SDL_GCC_ATOMICS "Use gcc builtin atomics" ${OPT_DEF_GCC_ATOMICS})
  384. set_option(SDL_ASSEMBLY "Enable assembly routines" ${OPT_DEF_ASM})
  385. set_option(SDL_SSEMATH "Allow GCC to use SSE floating point math" ${OPT_DEF_SSEMATH})
  386. set_option(SDL_MMX "Use MMX assembly routines" ${OPT_DEF_ASM})
  387. set_option(SDL_3DNOW "Use 3Dnow! MMX assembly routines" ${OPT_DEF_ASM})
  388. set_option(SDL_SSE "Use SSE assembly routines" ${OPT_DEF_ASM})
  389. set_option(SDL_SSE2 "Use SSE2 assembly routines" ${OPT_DEF_SSEMATH})
  390. set_option(SDL_SSE3 "Use SSE3 assembly routines" ${OPT_DEF_SSEMATH})
  391. set_option(SDL_ALTIVEC "Use Altivec assembly routines" ${OPT_DEF_ASM})
  392. set_option(SDL_ARMSIMD "use SIMD assembly blitters on ARM" OFF)
  393. set_option(SDL_ARMNEON "use NEON assembly blitters on ARM" OFF)
  394. dep_option(SDL_DBUS "Enable D-Bus support" ON ${UNIX_SYS} OFF)
  395. set_option(SDL_DISKAUDIO "Support the disk writer audio driver" ON)
  396. set_option(SDL_DUMMYAUDIO "Support the dummy audio driver" ON)
  397. set_option(SDL_DIRECTFB "Use DirectFB video driver" OFF)
  398. dep_option(SDL_DIRECTFB_SHARED "Dynamically load directfb support" ON "SDL_DIRECTFB" OFF)
  399. set_option(SDL_DUMMYVIDEO "Use dummy video driver" ON)
  400. dep_option(SDL_IBUS "Enable IBus support" ON ${UNIX_SYS} OFF)
  401. set_option(SDL_SYSTEM_ICONV "Use iconv() from system-installed libraries" ON)
  402. set_option(SDL_OPENGL "Include OpenGL support" ON)
  403. set_option(SDL_OPENGLES "Include OpenGL ES support" ON)
  404. set_option(SDL_PTHREADS "Use POSIX threads for multi-threading" ${SDL_PTHREADS_ENABLED_BY_DEFAULT})
  405. dep_option(SDL_PTHREADS_SEM "Use pthread semaphores" ON "SDL_PTHREADS" OFF)
  406. dep_option(SDL_OSS "Support the OSS audio API" ON "UNIX_SYS OR RISCOS" OFF)
  407. set_option(SDL_ALSA "Support the ALSA audio API" ${UNIX_SYS})
  408. dep_option(SDL_ALSA_SHARED "Dynamically load ALSA audio support" ON "SDL_ALSA" OFF)
  409. set_option(SDL_JACK "Support the JACK audio API" ${UNIX_SYS})
  410. dep_option(SDL_JACK_SHARED "Dynamically load JACK audio support" ON "SDL_JACK" OFF)
  411. set_option(SDL_ESD "Support the Enlightened Sound Daemon" ${UNIX_SYS})
  412. dep_option(SDL_ESD_SHARED "Dynamically load ESD audio support" ON "SDL_ESD" OFF)
  413. set_option(SDL_PIPEWIRE "Use Pipewire audio" ${UNIX_SYS})
  414. dep_option(SDL_PIPEWIRE_SHARED "Dynamically load Pipewire support" ON "SDL_PIPEWIRE" OFF)
  415. set_option(SDL_PULSEAUDIO "Use PulseAudio" ${UNIX_SYS})
  416. dep_option(SDL_PULSEAUDIO_SHARED "Dynamically load PulseAudio support" ON "SDL_PULSEAUDIO" OFF)
  417. set_option(SDL_ARTS "Support the Analog Real Time Synthesizer" ${UNIX_SYS})
  418. dep_option(SDL_ARTS_SHARED "Dynamically load aRts audio support" ON "SDL_ARTS" OFF)
  419. set_option(SDL_NAS "Support the NAS audio API" ${UNIX_SYS})
  420. dep_option(SDL_NAS_SHARED "Dynamically load NAS audio support" ON "SDL_NAS" OFF)
  421. set_option(SDL_SNDIO "Support the sndio audio API" ${UNIX_SYS})
  422. dep_option(SDL_SNDIO_SHARED "Dynamically load the sndio audio API" ON "SDL_SNDIO" OFF)
  423. set_option(SDL_FUSIONSOUND "Use FusionSound audio driver" OFF)
  424. dep_option(SDL_FUSIONSOUND_SHARED "Dynamically load fusionsound audio support" ON "SDL_FUSIONSOUND" OFF)
  425. set_option(SDL_LIBSAMPLERATE "Use libsamplerate for audio rate conversion" ${UNIX_SYS})
  426. dep_option(SDL_LIBSAMPLERATE_SHARED "Dynamically load libsamplerate" ON "SDL_LIBSAMPLERATE" OFF)
  427. set_option(SDL_RPATH "Use an rpath when linking SDL" ${UNIX_SYS})
  428. set_option(SDL_CLOCK_GETTIME "Use clock_gettime() instead of gettimeofday()" ${SDL_CLOCK_GETTIME_ENABLED_BY_DEFAULT})
  429. set_option(SDL_X11 "Use X11 video driver" ${UNIX_SYS})
  430. dep_option(SDL_X11_SHARED "Dynamically load X11 support" ON "SDL_X11" OFF)
  431. set(SDL_X11_OPTIONS Xcursor Xdbe XInput Xfixes Xrandr Xscrnsaver XShape)
  432. foreach(_SUB ${SDL_X11_OPTIONS})
  433. string(TOUPPER "SDL_X11_${_SUB}" _OPT)
  434. dep_option(${_OPT} "Enable ${_SUB} support" ON "SDL_X11" OFF)
  435. endforeach()
  436. set_option(SDL_WAYLAND "Use Wayland video driver" ${UNIX_SYS})
  437. dep_option(SDL_WAYLAND_SHARED "Dynamically load Wayland support" ON "SDL_WAYLAND" OFF)
  438. dep_option(SDL_WAYLAND_LIBDECOR "Use client-side window decorations on Wayland" ON "SDL_WAYLAND" OFF)
  439. dep_option(SDL_WAYLAND_LIBDECOR_SHARED "Dynamically load libdecor support" ON "SDL_WAYLAND_LIBDECOR;SDL_WAYLAND_SHARED" OFF)
  440. dep_option(SDL_WAYLAND_QT_TOUCH "QtWayland server support for Wayland video driver" ON "SDL_WAYLAND" OFF)
  441. set_option(SDL_RPI "Use Raspberry Pi video driver" ${UNIX_SYS})
  442. set_option(SDL_COCOA "Use Cocoa video driver" ${APPLE})
  443. set_option(SDL_DIRECTX "Use DirectX for Windows audio/video" ${WINDOWS})
  444. set_option(SDL_XINPUT "Use Xinput for Windows" ${WINDOWS})
  445. set_option(SDL_WASAPI "Use the Windows WASAPI audio driver" ${WINDOWS})
  446. set_option(SDL_RENDER_D3D "Enable the Direct3D render driver" ${WINDOWS})
  447. set_option(SDL_RENDER_METAL "Enable the Metal render driver" ${APPLE})
  448. set_option(SDL_VIVANTE "Use Vivante EGL video driver" ${UNIX_SYS})
  449. dep_option(SDL_VULKAN "Enable Vulkan support" ON "ANDROID OR APPLE OR LINUX OR WINDOWS" OFF)
  450. set_option(SDL_METAL "Enable Metal support" ${APPLE})
  451. set_option(SDL_KMSDRM "Use KMS DRM video driver" ${UNIX_SYS})
  452. dep_option(SDL_KMSDRM_SHARED "Dynamically load KMS DRM support" ON "SDL_KMSDRM" OFF)
  453. set_option(SDL_OFFSCREEN "Use offscreen video driver" ON)
  454. option_string(SDL_BACKGROUNDING_SIGNAL "number to use for magic backgrounding signal or 'OFF'" OFF)
  455. option_string(SDL_FOREGROUNDING_SIGNAL "number to use for magic foregrounding signal or 'OFF'" OFF)
  456. set_option(SDL_HIDAPI "Enable the HIDAPI subsystem" ON)
  457. dep_option(SDL_HIDAPI_LIBUSB "Use libusb for low level joystick drivers" OFF SDL_HIDAPI OFF)
  458. dep_option(SDL_HIDAPI_JOYSTICK "Use HIDAPI for low level joystick drivers" ON SDL_HIDAPI OFF)
  459. dep_option(SDL_VIRTUAL_JOYSTICK "Enable the virtual-joystick driver" ON SDL_HIDAPI OFF)
  460. set_option(SDL_ASAN "Use AddressSanitizer to detect memory errors" OFF)
  461. option_string(SDL_VENDOR_INFO "Vendor name and/or version to add to SDL_REVISION" "")
  462. set_option(SDL_CCACHE "Use Ccache to speed up build" ON)
  463. option(SDL_WERROR "Enable -Werror" OFF)
  464. option(SDL_SHARED "Build a shared version of the library" ${SDL_SHARED_ENABLED_BY_DEFAULT})
  465. option(SDL_STATIC "Build a static version of the library" ${SDL_STATIC_ENABLED_BY_DEFAULT})
  466. option(SDL_TEST "Build the SDL2_test library" ${SDL_TEST_ENABLED_BY_DEFAULT})
  467. dep_option(SDL_STATIC_PIC "Static version of the library should be built with Position Independent Code" "${CMAKE_POSITION_INDEPENDENT_CODE}" "SDL_STATIC" OFF)
  468. dep_option(SDL_TESTS "Build the test directory" OFF SDL_TEST OFF)
  469. set_option(SDL_INSTALL_TESTS "Install test-cases" OFF)
  470. set(HAVE_STATIC_PIC "${SDL_STATIC_PIC}")
  471. if(SDL_HIDAPI)
  472. if(HIDAPI_ONLY_LIBUSB)
  473. set(SDL_HIDAPI_LIBUSB ON CACHE BOOL "" FORCE)
  474. elseif(HIDAPI_SKIP_LIBUSB)
  475. set(SDL_HIDAPI_LIBUSB OFF CACHE BOOL "" FORCE)
  476. endif()
  477. endif()
  478. if(VITA)
  479. set_option(VIDEO_VITA_PIB "Build with PSVita piglet gles2 support" OFF)
  480. set_option(VIDEO_VITA_PVR "Build with PSVita PVR gles/gles2 support" OFF)
  481. endif()
  482. # General source files
  483. file(GLOB SOURCE_FILES
  484. ${SDL2_SOURCE_DIR}/src/*.c
  485. ${SDL2_SOURCE_DIR}/src/atomic/*.c
  486. ${SDL2_SOURCE_DIR}/src/audio/*.c
  487. ${SDL2_SOURCE_DIR}/src/cpuinfo/*.c
  488. ${SDL2_SOURCE_DIR}/src/dynapi/*.c
  489. ${SDL2_SOURCE_DIR}/src/events/*.c
  490. ${SDL2_SOURCE_DIR}/src/file/*.c
  491. ${SDL2_SOURCE_DIR}/src/joystick/*.c
  492. ${SDL2_SOURCE_DIR}/src/haptic/*.c
  493. ${SDL2_SOURCE_DIR}/src/hidapi/*.c
  494. ${SDL2_SOURCE_DIR}/src/libm/*.c
  495. ${SDL2_SOURCE_DIR}/src/locale/*.c
  496. ${SDL2_SOURCE_DIR}/src/misc/*.c
  497. ${SDL2_SOURCE_DIR}/src/power/*.c
  498. ${SDL2_SOURCE_DIR}/src/render/*.c
  499. ${SDL2_SOURCE_DIR}/src/render/*/*.c
  500. ${SDL2_SOURCE_DIR}/src/sensor/*.c
  501. ${SDL2_SOURCE_DIR}/src/stdlib/*.c
  502. ${SDL2_SOURCE_DIR}/src/thread/*.c
  503. ${SDL2_SOURCE_DIR}/src/timer/*.c
  504. ${SDL2_SOURCE_DIR}/src/video/*.c
  505. ${SDL2_SOURCE_DIR}/src/video/yuv2rgb/*.c)
  506. set(SDL_DEFAULT_ASSERT_LEVEL_CONFIGURED 1)
  507. if(SDL_ASSERTIONS MATCHES "^(auto|)$")
  508. # Do nada - use optimization settings to determine the assertion level
  509. set(SDL_DEFAULT_ASSERT_LEVEL )
  510. set(SDL_DEFAULT_ASSERT_LEVEL_CONFIGURED 0)
  511. elseif(SDL_ASSERTIONS MATCHES "^(disabled|0)$")
  512. set(SDL_DEFAULT_ASSERT_LEVEL 0)
  513. elseif(SDL_ASSERTIONS MATCHES "^(release|1)$")
  514. set(SDL_DEFAULT_ASSERT_LEVEL 1)
  515. elseif(SDL_ASSERTIONS MATCHES "^(enabled|2)$")
  516. set(SDL_DEFAULT_ASSERT_LEVEL 2)
  517. elseif(SDL_ASSERTIONS MATCHES "^(paranoid|3)$")
  518. set(SDL_DEFAULT_ASSERT_LEVEL 3)
  519. else()
  520. message_error("unknown assertion level")
  521. endif()
  522. set(HAVE_ASSERTIONS ${SDL_ASSERTIONS})
  523. if(NOT SDL_BACKGROUNDING_SIGNAL STREQUAL "OFF")
  524. target_compile_definitions(sdl-build-options INTERFACE "-DSDL_BACKGROUNDING_SIGNAL=${SDL_BACKGROUNDING_SIGNAL}")
  525. endif()
  526. if(NOT SDL_FOREGROUNDING_SIGNAL STREQUAL "OFF")
  527. target_compile_definitions(sdl-build-options INTERFACE "-DSDL_FOREGROUNDING_SIGNAL=${SDL_FOREGROUNDING_SIGNAL}")
  528. endif()
  529. # Compiler option evaluation
  530. if(USE_GCC OR USE_CLANG)
  531. # Check for -Wall first, so later things can override pieces of it.
  532. # Note: clang-cl treats -Wall as -Weverything (which is very loud),
  533. # /W3 as -Wall, and /W4 as -Wall -Wextra. So: /W3 is enough.
  534. check_c_compiler_flag(-Wall HAVE_GCC_WALL)
  535. if(MSVC_CLANG)
  536. list(APPEND EXTRA_CFLAGS "/W3")
  537. elseif(HAVE_GCC_WALL)
  538. list(APPEND EXTRA_CFLAGS "-Wall")
  539. if(HAIKU)
  540. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")
  541. endif()
  542. endif()
  543. check_c_compiler_flag(-fno-strict-aliasing HAVE_GCC_NO_STRICT_ALIASING)
  544. if(HAVE_GCC_NO_STRICT_ALIASING)
  545. list(APPEND EXTRA_CFLAGS "-fno-strict-aliasing")
  546. endif()
  547. check_c_compiler_flag(-Wdeclaration-after-statement HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
  548. if(HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
  549. if(SDL_WERROR)
  550. check_c_compiler_flag(-Werror=declaration-after-statement HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
  551. if(HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
  552. list(APPEND EXTRA_CFLAGS "-Werror=declaration-after-statement")
  553. endif()
  554. endif()
  555. list(APPEND EXTRA_CFLAGS "-Wdeclaration-after-statement")
  556. endif()
  557. if(DEPENDENCY_TRACKING)
  558. check_c_source_compiles("
  559. #if !defined(__GNUC__) || __GNUC__ < 3
  560. #error Dependency tracking requires GCC 3.0 or newer
  561. #endif
  562. int main(int argc, char **argv) { return 0; }" HAVE_DEPENDENCY_TRACKING)
  563. endif()
  564. if(SDL_GCC_ATOMICS)
  565. check_c_source_compiles("int main(int argc, char **argv) {
  566. int a;
  567. void *x, *y, *z;
  568. __sync_lock_test_and_set(&a, 4);
  569. __sync_lock_test_and_set(&x, y);
  570. __sync_fetch_and_add(&a, 1);
  571. __sync_bool_compare_and_swap(&a, 5, 10);
  572. __sync_bool_compare_and_swap(&x, y, z);
  573. return 0; }" HAVE_GCC_ATOMICS)
  574. if(NOT HAVE_GCC_ATOMICS)
  575. check_c_source_compiles("int main(int argc, char **argv) {
  576. int a;
  577. __sync_lock_test_and_set(&a, 1);
  578. __sync_lock_release(&a);
  579. return 0; }" HAVE_GCC_SYNC_LOCK_TEST_AND_SET)
  580. endif()
  581. endif()
  582. set(CMAKE_REQUIRED_FLAGS "-mpreferred-stack-boundary=2")
  583. check_c_source_compiles("int x = 0; int main(int argc, char **argv) { return 0; }"
  584. HAVE_GCC_PREFERRED_STACK_BOUNDARY)
  585. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  586. set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden -Werror")
  587. check_c_source_compiles("
  588. #if !defined(__GNUC__) || __GNUC__ < 4
  589. #error SDL only uses visibility attributes in GCC 4 or newer
  590. #endif
  591. int main(int argc, char **argv) { return 0; }" HAVE_GCC_FVISIBILITY)
  592. if(HAVE_GCC_FVISIBILITY)
  593. list(APPEND EXTRA_CFLAGS "-fvisibility=hidden")
  594. endif()
  595. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  596. check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW)
  597. if(HAVE_GCC_WSHADOW)
  598. list(APPEND EXTRA_CFLAGS "-Wshadow")
  599. endif()
  600. if(APPLE)
  601. cmake_push_check_state(RESET)
  602. # FIXME: don't use deprecated declarations
  603. check_c_compiler_flag(-Wno-error=deprecated-declarations HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS)
  604. if(HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS)
  605. target_compile_options(sdl-build-options INTERFACE "-Wno-error=deprecated-declarations")
  606. endif()
  607. cmake_pop_check_state()
  608. # FIXME: use generator expression instead of appending to EXTRA_LDFLAGS_BUILD
  609. list(APPEND EXTRA_LDFLAGS_BUILD "-Wl,-compatibility_version,${DYLIB_COMPATIBILITY_VERSION}")
  610. list(APPEND EXTRA_LDFLAGS_BUILD "-Wl,-current_version,${DYLIB_CURRENT_VERSION}")
  611. elseif(NOT OPENBSD)
  612. set(CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined")
  613. check_c_compiler_flag("" HAVE_NO_UNDEFINED)
  614. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  615. if(HAVE_NO_UNDEFINED AND NOT (USE_CLANG AND WINDOWS))
  616. list(APPEND EXTRA_LDFLAGS_BUILD "-Wl,--no-undefined")
  617. endif()
  618. endif()
  619. if(MINGW)
  620. # See if GCC's -gdwarf-4 is supported
  621. # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101377 for why this is needed on Windows
  622. cmake_push_check_state(RESET)
  623. check_c_compiler_flag("-gdwarf-4" HAVE_GDWARF_4)
  624. if(HAVE_GDWARF_4)
  625. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -gdwarf-4")
  626. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -gdwarf-4")
  627. endif()
  628. cmake_pop_check_state()
  629. endif()
  630. # Force color diagnostics when one of these conditions are met
  631. if(DEFINED ENV{CI} OR DEFINED ENV{USE_CCACHE} OR CMAKE_GENERATOR MATCHES Ninja)
  632. if(EMSCRIPTEN OR (USE_GCC AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9))
  633. list(APPEND EXTRA_CFLAGS -fdiagnostics-color=always)
  634. elseif(USE_CLANG AND NOT CMAKE_C_COMPILER_ID MATCHES AppleClang)
  635. list(APPEND EXTRA_CFLAGS -fcolor-diagnostics)
  636. endif()
  637. endif()
  638. endif()
  639. if(MSVC)
  640. target_compile_definitions(sdl-build-options INTERFACE "-D_CRT_SECURE_NO_DEPRECATE")
  641. target_compile_definitions(sdl-build-options INTERFACE "-D_CRT_NONSTDC_NO_DEPRECATE")
  642. target_compile_definitions(sdl-build-options INTERFACE "-D_CRT_SECURE_NO_WARNINGS")
  643. # CET support was added in VS 16.7
  644. if(MSVC_VERSION GREATER 1926 AND CMAKE_GENERATOR_PLATFORM MATCHES "Win32|x64")
  645. list(APPEND EXTRA_LDFLAGS_BUILD "-CETCOMPAT")
  646. endif()
  647. endif()
  648. if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
  649. # Due to a limitation of Microsoft's LTO implementation, LTO must be disabled for memcpy and memset.
  650. # The same applies to various functions normally belonging in the C library (for x86 architecture).
  651. set_property(SOURCE src/stdlib/SDL_mslibc.c APPEND_STRING PROPERTY COMPILE_FLAGS " /GL-")
  652. endif()
  653. if(SDL_ASSEMBLY)
  654. if(USE_GCC OR USE_CLANG)
  655. # TODO: Those all seem to be quite GCC specific - needs to be
  656. # reworked for better compiler support
  657. set(HAVE_ASSEMBLY TRUE)
  658. if(SDL_MMX)
  659. set(CMAKE_REQUIRED_FLAGS "-mmmx")
  660. check_c_source_compiles("
  661. #ifdef __MINGW32__
  662. #include <_mingw.h>
  663. #ifdef __MINGW64_VERSION_MAJOR
  664. #include <intrin.h>
  665. #else
  666. #include <mmintrin.h>
  667. #endif
  668. #else
  669. #include <mmintrin.h>
  670. #endif
  671. #ifndef __MMX__
  672. #error Assembler CPP flag not enabled
  673. #endif
  674. int main(int argc, char **argv) { return 0; }" HAVE_MMX)
  675. if(HAVE_MMX)
  676. list(APPEND EXTRA_CFLAGS "-mmmx")
  677. endif()
  678. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  679. endif()
  680. if(SDL_3DNOW)
  681. set(CMAKE_REQUIRED_FLAGS "-m3dnow")
  682. check_c_source_compiles("
  683. #include <mm3dnow.h>
  684. #ifndef __3dNOW__
  685. #error Assembler CPP flag not enabled
  686. #endif
  687. int main(int argc, char **argv) {
  688. void *p = 0;
  689. _m_prefetch(p);
  690. return 0;
  691. }" HAVE_3DNOW)
  692. if(HAVE_3DNOW)
  693. list(APPEND EXTRA_CFLAGS "-m3dnow")
  694. endif()
  695. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  696. endif()
  697. if(SDL_SSE)
  698. set(CMAKE_REQUIRED_FLAGS "-msse")
  699. check_c_source_compiles("
  700. #ifdef __MINGW32__
  701. #include <_mingw.h>
  702. #ifdef __MINGW64_VERSION_MAJOR
  703. #include <intrin.h>
  704. #else
  705. #include <xmmintrin.h>
  706. #endif
  707. #else
  708. #include <xmmintrin.h>
  709. #endif
  710. #ifndef __SSE__
  711. #error Assembler CPP flag not enabled
  712. #endif
  713. int main(int argc, char **argv) { return 0; }" HAVE_SSE)
  714. if(HAVE_SSE)
  715. list(APPEND EXTRA_CFLAGS "-msse")
  716. endif()
  717. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  718. endif()
  719. if(SDL_SSE2)
  720. set(CMAKE_REQUIRED_FLAGS "-msse2")
  721. check_c_source_compiles("
  722. #ifdef __MINGW32__
  723. #include <_mingw.h>
  724. #ifdef __MINGW64_VERSION_MAJOR
  725. #include <intrin.h>
  726. #else
  727. #include <emmintrin.h>
  728. #endif
  729. #else
  730. #include <emmintrin.h>
  731. #endif
  732. #ifndef __SSE2__
  733. #error Assembler CPP flag not enabled
  734. #endif
  735. int main(int argc, char **argv) { return 0; }" HAVE_SSE2)
  736. if(HAVE_SSE2)
  737. list(APPEND EXTRA_CFLAGS "-msse2")
  738. endif()
  739. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  740. endif()
  741. if(SDL_SSE3)
  742. set(CMAKE_REQUIRED_FLAGS "-msse3")
  743. check_c_source_compiles("
  744. #ifdef __MINGW32__
  745. #include <_mingw.h>
  746. #ifdef __MINGW64_VERSION_MAJOR
  747. #include <intrin.h>
  748. #else
  749. #include <pmmintrin.h>
  750. #endif
  751. #else
  752. #include <pmmintrin.h>
  753. #endif
  754. #ifndef __SSE3__
  755. #error Assembler CPP flag not enabled
  756. #endif
  757. int main(int argc, char **argv) { return 0; }" HAVE_SSE3)
  758. if(HAVE_SSE3)
  759. list(APPEND EXTRA_CFLAGS "-msse3")
  760. endif()
  761. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  762. endif()
  763. if(NOT SDL_SSEMATH)
  764. if(SDL_SSE OR SDL_SSE2 OR SDL_SSE3)
  765. if(USE_GCC)
  766. check_c_compiler_flag(-mfpmath=387 HAVE_FP_387)
  767. if(HAVE_FP_387)
  768. list(APPEND EXTRA_CFLAGS "-mfpmath=387")
  769. endif()
  770. endif()
  771. endif()
  772. else()
  773. set(HAVE_SSEMATH TRUE)
  774. endif()
  775. check_include_file("immintrin.h" HAVE_IMMINTRIN_H)
  776. if(SDL_ALTIVEC)
  777. set(CMAKE_REQUIRED_FLAGS "-maltivec")
  778. check_c_source_compiles("
  779. #include <altivec.h>
  780. vector unsigned int vzero() {
  781. return vec_splat_u32(0);
  782. }
  783. int main(int argc, char **argv) { return 0; }" HAVE_ALTIVEC_H_HDR)
  784. check_c_source_compiles("
  785. vector unsigned int vzero() {
  786. return vec_splat_u32(0);
  787. }
  788. int main(int argc, char **argv) { return 0; }" HAVE_ALTIVEC)
  789. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  790. if(HAVE_ALTIVEC OR HAVE_ALTIVEC_H_HDR)
  791. set(HAVE_ALTIVEC TRUE) # if only HAVE_ALTIVEC_H_HDR is set
  792. list(APPEND EXTRA_CFLAGS "-maltivec")
  793. set(SDL_ALTIVEC_BLITTERS 1)
  794. if(HAVE_ALTIVEC_H_HDR)
  795. set(HAVE_ALTIVEC_H 1)
  796. endif()
  797. endif()
  798. endif()
  799. if(SDL_ARMSIMD)
  800. set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  801. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -x assembler-with-cpp")
  802. check_c_source_compiles("
  803. .text
  804. .arch armv6
  805. .object_arch armv4
  806. .arm
  807. .altmacro
  808. #ifndef __ARM_EABI__
  809. #error EABI is required (to be sure that calling conventions are compatible)
  810. #endif
  811. pld [r0]
  812. uqadd8 r0, r0, r0
  813. " ARMSIMD_FOUND)
  814. set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  815. if(ARMSIMD_FOUND)
  816. set(HAVE_ARMSIMD TRUE)
  817. set(SDL_ARM_SIMD_BLITTERS 1)
  818. file(GLOB ARMSIMD_SOURCES ${SDL2_SOURCE_DIR}/src/video/arm/pixman-arm-simd*.S)
  819. list(APPEND SOURCE_FILES ${ARMSIMD_SOURCES})
  820. set(WARN_ABOUT_ARM_SIMD_ASM_MIT TRUE)
  821. endif()
  822. endif()
  823. if(SDL_ARMNEON)
  824. set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  825. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -x assembler-with-cpp")
  826. check_c_source_compiles("
  827. .text
  828. .fpu neon
  829. .arch armv7a
  830. .object_arch armv4
  831. .eabi_attribute 10, 0
  832. .arm
  833. .altmacro
  834. #ifndef __ARM_EABI__
  835. #error EABI is required (to be sure that calling conventions are compatible)
  836. #endif
  837. pld [r0]
  838. vmovn.u16 d0, q0
  839. " ARMNEON_FOUND)
  840. set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  841. if(ARMNEON_FOUND)
  842. set(HAVE_ARMNEON TRUE)
  843. set(SDL_ARM_NEON_BLITTERS 1)
  844. file(GLOB ARMNEON_SOURCES ${SDL2_SOURCE_DIR}/src/video/arm/pixman-arm-neon*.S)
  845. list(APPEND SOURCE_FILES ${ARMNEON_SOURCES})
  846. set(WARN_ABOUT_ARM_NEON_ASM_MIT TRUE)
  847. endif()
  848. endif()
  849. elseif(MSVC_VERSION GREATER 1500)
  850. # TODO: SDL_cpuinfo.h needs to support the user's configuration wish
  851. # for MSVC - right now it is always activated
  852. if(NOT ARCH_64)
  853. set(HAVE_MMX TRUE)
  854. set(HAVE_3DNOW TRUE)
  855. endif()
  856. set(HAVE_SSE TRUE)
  857. set(HAVE_SSE2 TRUE)
  858. set(HAVE_SSE3 TRUE)
  859. check_include_file("immintrin.h" HAVE_IMMINTRIN_H)
  860. endif()
  861. endif()
  862. # TODO: Can't deactivate on FreeBSD? w/o LIBC, SDL_stdinc.h can't define
  863. # anything.
  864. if(SDL_LIBC)
  865. if(WINDOWS AND NOT MINGW)
  866. set(HAVE_LIBC TRUE)
  867. check_include_file(stdint.h HAVE_STDINT_H)
  868. foreach(_HEADER stdio.h string.h wchar.h ctype.h math.h limits.h)
  869. string(TOUPPER "HAVE_${_HEADER}" _UPPER)
  870. string(REPLACE "." "_" _HAVE_H ${_UPPER})
  871. set(${_HAVE_H} 1)
  872. endforeach()
  873. set(HAVE_SIGNAL_H 1)
  874. foreach(_FN
  875. malloc calloc realloc free bsearch qsort abs memset memcpy memmove memcmp
  876. wcslen _wcsdup wcsdup wcsstr wcscmp wcsncmp _wcsicmp _wcsnicmp
  877. strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
  878. _ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp
  879. _stricmp _strnicmp sscanf
  880. acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf
  881. copysign copysignf cos cosf exp expf fabs fabsf floor floorf fmod fmodf
  882. log logf log10 log10f lround lroundf pow powf round roundf scalbn scalbnf
  883. sin sinf sqrt sqrtf tan tanf trunc truncf)
  884. string(TOUPPER ${_FN} _UPPER)
  885. set(HAVE_${_UPPER} 1)
  886. endforeach()
  887. set(HAVE_ALLOCA 1)
  888. check_symbol_exists(M_PI math.h HAVE_M_PI)
  889. target_compile_definitions(sdl-build-options INTERFACE "-D_USE_MATH_DEFINES") # needed for M_PI
  890. set(STDC_HEADERS 1)
  891. else()
  892. set(HAVE_LIBC TRUE)
  893. set(headers_to_check
  894. ctype.h
  895. float.h
  896. iconv.h
  897. inttypes.h
  898. limits.h
  899. malloc.h
  900. math.h
  901. memory.h
  902. signal.h
  903. stdarg.h
  904. stddef.h
  905. stdint.h
  906. stdio.h
  907. stdlib.h
  908. string.h
  909. strings.h
  910. sys/types.h
  911. wchar.h
  912. )
  913. if(NOT EMSCRIPTEN)
  914. list(APPEND headers_to_check libunwind.h)
  915. endif()
  916. foreach(_HEADER ${headers_to_check})
  917. string(TOUPPER "HAVE_${_HEADER}" _UPPER)
  918. string(REGEX REPLACE "[./]" "_" _HAVE_H ${_UPPER})
  919. check_include_file("${_HEADER}" ${_HAVE_H})
  920. endforeach()
  921. check_include_file(linux/input.h HAVE_LINUX_INPUT_H)
  922. set(STDC_HEADER_NAMES "stddef.h;stdarg.h;stdlib.h;string.h;stdio.h;wchar.h;float.h")
  923. check_include_files("${STDC_HEADER_NAMES}" STDC_HEADERS)
  924. check_symbol_exists(M_PI math.h HAVE_M_PI)
  925. # TODO: refine the mprotect check
  926. check_c_source_compiles("#include <sys/types.h>
  927. #include <sys/mman.h>
  928. int main(void) { return 0; }" HAVE_MPROTECT)
  929. foreach(_FN
  930. strtod malloc calloc realloc free getenv setenv putenv unsetenv
  931. bsearch qsort abs bcopy memset memcpy memmove memcmp strlen strlcpy strlcat
  932. _strrev _strupr _strlwr index rindex strchr strrchr strstr strtok_r
  933. itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull
  934. atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp strcasestr
  935. wcscmp _wcsdup wcsdup wcslcat wcslcpy wcslen wcsncmp wcsstr
  936. wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp
  937. sscanf vsscanf vsnprintf fopen64 fseeko fseeko64 _Exit
  938. )
  939. string(TOUPPER ${_FN} _UPPER)
  940. set(_HAVEVAR "HAVE_${_UPPER}")
  941. check_symbol_exists("${_FN}" "${STDC_HEADER_NAMES}" ${_HAVEVAR})
  942. endforeach()
  943. check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
  944. check_symbol_exists(setjmp "setjmp.h" HAVE_SETJMP)
  945. check_symbol_exists(nanosleep "time.h" HAVE_NANOSLEEP)
  946. check_symbol_exists(sysconf "unistd.h" HAVE_SYSCONF)
  947. check_symbol_exists(sysctlbyname "sys/types.h;sys/sysctl.h" HAVE_SYSCTLBYNAME)
  948. check_symbol_exists(getauxval "sys/auxv.h" HAVE_GETAUXVAL)
  949. check_symbol_exists(elf_aux_info "sys/auxv.h" HAVE_ELF_AUX_INFO)
  950. check_symbol_exists(poll "poll.h" HAVE_POLL)
  951. check_library_exists(m pow "" HAVE_LIBM)
  952. if(HAVE_LIBM)
  953. set(CMAKE_REQUIRED_LIBRARIES m)
  954. endif()
  955. foreach(_FN
  956. atan atan2 atanf atan2f ceil ceilf copysign copysignf cos cosf
  957. exp expf fabs fabsf floor floorf fmod fmodf log logf log10 log10f
  958. lround lroundf pow powf round roundf scalbn scalbnf sin sinf sqrt
  959. sqrtf tan tanf acos acosf asin asinf trunc truncf)
  960. string(TOUPPER ${_FN} _UPPER)
  961. set(_HAVEVAR "HAVE_${_UPPER}")
  962. check_symbol_exists("${_FN}" "math.h" ${_HAVEVAR})
  963. endforeach()
  964. if(HAVE_LIBM)
  965. set(CMAKE_REQUIRED_LIBRARIES)
  966. if(NOT VITA)
  967. list(APPEND EXTRA_LIBS m)
  968. endif()
  969. endif()
  970. if(SDL_SYSTEM_ICONV)
  971. check_library_exists(iconv iconv_open "" HAVE_LIBICONV)
  972. if(HAVE_LIBICONV)
  973. list(APPEND EXTRA_LIBS iconv)
  974. set(HAVE_ICONV 1)
  975. set(HAVE_SYSTEM_ICONV TRUE)
  976. else()
  977. check_library_exists(c iconv_open "" HAVE_BUILTIN_ICONV)
  978. if(HAVE_BUILTIN_ICONV)
  979. set(HAVE_ICONV 1)
  980. set(HAVE_SYSTEM_ICONV TRUE)
  981. endif()
  982. endif()
  983. endif()
  984. if(NOT APPLE)
  985. check_include_file(alloca.h HAVE_ALLOCA_H)
  986. check_symbol_exists(alloca "alloca.h" HAVE_ALLOCA1)
  987. check_symbol_exists(alloca "stdlib.h" HAVE_ALLOCA2)
  988. check_symbol_exists(alloca "malloc.h" HAVE_ALLOCA3)
  989. if(HAVE_ALLOCA1 OR HAVE_ALLOCA2 OR HAVE_ALLOCA3)
  990. set(HAVE_ALLOCA 1)
  991. endif()
  992. else()
  993. set(HAVE_ALLOCA_H 1)
  994. set(HAVE_ALLOCA 1)
  995. endif()
  996. check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION)
  997. endif()
  998. else()
  999. if(WINDOWS)
  1000. set(HAVE_STDARG_H 1)
  1001. set(HAVE_STDDEF_H 1)
  1002. check_include_file(stdint.h HAVE_STDINT_H)
  1003. endif()
  1004. endif()
  1005. # Enable/disable various subsystems of the SDL library
  1006. foreach(_SUB ${SDL_SUBSYSTEMS})
  1007. string(TOUPPER ${_SUB} _OPT)
  1008. if(NOT SDL_${_OPT})
  1009. set(SDL_${_OPT}_DISABLED 1)
  1010. endif()
  1011. endforeach()
  1012. if(SDL_HAPTIC)
  1013. if(NOT SDL_JOYSTICK)
  1014. # Haptic requires some private functions from the joystick subsystem.
  1015. message_error("SDL_HAPTIC requires SDL_JOYSTICK, which is not enabled")
  1016. endif()
  1017. endif()
  1018. # General SDL subsystem options, valid for all platforms
  1019. if(SDL_AUDIO)
  1020. # CheckDummyAudio/CheckDiskAudio - valid for all platforms
  1021. if(SDL_DUMMYAUDIO)
  1022. set(SDL_AUDIO_DRIVER_DUMMY 1)
  1023. file(GLOB DUMMYAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dummy/*.c)
  1024. list(APPEND SOURCE_FILES ${DUMMYAUDIO_SOURCES})
  1025. set(HAVE_DUMMYAUDIO TRUE)
  1026. set(HAVE_SDL_AUDIO TRUE)
  1027. endif()
  1028. if(SDL_DISKAUDIO)
  1029. set(SDL_AUDIO_DRIVER_DISK 1)
  1030. file(GLOB DISKAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/disk/*.c)
  1031. list(APPEND SOURCE_FILES ${DISKAUDIO_SOURCES})
  1032. set(HAVE_DISKAUDIO TRUE)
  1033. set(HAVE_SDL_AUDIO TRUE)
  1034. endif()
  1035. endif()
  1036. if(UNIX OR APPLE)
  1037. # Relevant for Unix/Darwin only
  1038. set(DYNAPI_NEEDS_DLOPEN 1)
  1039. CheckDLOPEN()
  1040. if(SDL_LOADSO AND HAVE_DLOPEN)
  1041. set(SDL_LOADSO_DLOPEN 1)
  1042. file(GLOB DLOPEN_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dlopen/*.c)
  1043. list(APPEND SOURCE_FILES ${DLOPEN_SOURCES})
  1044. set(HAVE_SDL_LOADSO TRUE)
  1045. endif()
  1046. endif()
  1047. if(UNIX OR APPLE OR HAIKU OR RISCOS)
  1048. CheckO_CLOEXEC()
  1049. endif()
  1050. if(SDL_JOYSTICK)
  1051. if(SDL_VIRTUAL_JOYSTICK)
  1052. set(HAVE_VIRTUAL_JOYSTICK TRUE)
  1053. set(SDL_JOYSTICK_VIRTUAL 1)
  1054. file(GLOB JOYSTICK_VIRTUAL_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/virtual/*.c)
  1055. list(APPEND SOURCE_FILES ${JOYSTICK_VIRTUAL_SOURCES})
  1056. endif()
  1057. endif()
  1058. if(SDL_VIDEO)
  1059. if(SDL_DUMMYVIDEO)
  1060. set(SDL_VIDEO_DRIVER_DUMMY 1)
  1061. file(GLOB VIDEO_DUMMY_SOURCES ${SDL2_SOURCE_DIR}/src/video/dummy/*.c)
  1062. list(APPEND SOURCE_FILES ${VIDEO_DUMMY_SOURCES})
  1063. set(HAVE_DUMMYVIDEO TRUE)
  1064. set(HAVE_SDL_VIDEO TRUE)
  1065. endif()
  1066. if(SDL_OFFSCREEN)
  1067. set(SDL_VIDEO_DRIVER_OFFSCREEN 1)
  1068. file(GLOB VIDEO_OFFSCREEN_SOURCES ${SDL2_SOURCE_DIR}/src/video/offscreen/*.c)
  1069. list(APPEND SOURCE_FILES ${VIDEO_OFFSCREEN_SOURCES})
  1070. set(HAVE_OFFSCREEN TRUE)
  1071. set(HAVE_SDL_VIDEO TRUE)
  1072. endif()
  1073. endif()
  1074. # Platform-specific options and settings
  1075. if(ANDROID)
  1076. file(GLOB ANDROID_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/android/*.c)
  1077. list(APPEND SOURCE_FILES ${ANDROID_CORE_SOURCES} ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
  1078. set_property(SOURCE "${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c" APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-declaration-after-statement")
  1079. if(SDL_MISC)
  1080. file(GLOB ANDROID_MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/android/*.c)
  1081. list(APPEND SOURCE_FILES ${ANDROID_MISC_SOURCES})
  1082. set(HAVE_SDL_MISC TRUE)
  1083. endif()
  1084. # SDL_spinlock.c Needs to be compiled in ARM mode.
  1085. # There seems to be no better way currently to set the ARM mode.
  1086. # see: https://issuetracker.google.com/issues/62264618
  1087. # Another option would be to set ARM mode to all compiled files
  1088. cmake_push_check_state(RESET)
  1089. set(CMAKE_REQUIRED_FLAGS "-Werror=unused-command-line-argument")
  1090. check_c_compiler_flag(-marm HAVE_ARM_MODE)
  1091. if(HAVE_ARM_MODE)
  1092. set_property(SOURCE "${SDL2_SOURCE_DIR}/src/atomic/SDL_spinlock.c" APPEND_STRING PROPERTY COMPILE_FLAGS " -marm")
  1093. endif()
  1094. cmake_pop_check_state()
  1095. file(GLOB ANDROID_MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/android/*.c)
  1096. list(APPEND SDLMAIN_SOURCES ${ANDROID_MAIN_SOURCES})
  1097. if(SDL_AUDIO)
  1098. set(SDL_AUDIO_DRIVER_ANDROID 1)
  1099. file(GLOB ANDROID_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/android/*.c)
  1100. list(APPEND SOURCE_FILES ${ANDROID_AUDIO_SOURCES})
  1101. set(SDL_AUDIO_DRIVER_OPENSLES 1)
  1102. file(GLOB OPENSLES_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/openslES/*.c)
  1103. list(APPEND SOURCE_FILES ${OPENSLES_AUDIO_SOURCES})
  1104. list(APPEND EXTRA_LIBS ${ANDROID_DL_LIBRARY} OpenSLES)
  1105. set(SDL_AUDIO_DRIVER_AAUDIO 1)
  1106. file(GLOB AAUDIO_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/aaudio/*.c)
  1107. list(APPEND SOURCE_FILES ${AAUDIO_AUDIO_SOURCES})
  1108. set(HAVE_SDL_AUDIO TRUE)
  1109. endif()
  1110. if(SDL_FILESYSTEM)
  1111. set(SDL_FILESYSTEM_ANDROID 1)
  1112. file(GLOB ANDROID_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/android/*.c)
  1113. list(APPEND SOURCE_FILES ${ANDROID_FILESYSTEM_SOURCES})
  1114. set(HAVE_SDL_FILESYSTEM TRUE)
  1115. endif()
  1116. if(SDL_HAPTIC)
  1117. set(SDL_HAPTIC_ANDROID 1)
  1118. file(GLOB ANDROID_HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/android/*.c)
  1119. list(APPEND SOURCE_FILES ${ANDROID_HAPTIC_SOURCES})
  1120. set(HAVE_SDL_HAPTIC TRUE)
  1121. endif()
  1122. if(SDL_HIDAPI)
  1123. CheckHIDAPI()
  1124. endif()
  1125. if(SDL_JOYSTICK)
  1126. set(SDL_JOYSTICK_ANDROID 1)
  1127. file(GLOB ANDROID_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/android/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
  1128. list(APPEND SOURCE_FILES ${ANDROID_JOYSTICK_SOURCES})
  1129. set(HAVE_SDL_JOYSTICK TRUE)
  1130. endif()
  1131. if(SDL_LOADSO)
  1132. set(SDL_LOADSO_DLOPEN 1)
  1133. file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dlopen/*.c)
  1134. list(APPEND SOURCE_FILES ${LOADSO_SOURCES})
  1135. set(HAVE_SDL_LOADSO TRUE)
  1136. endif()
  1137. if(SDL_POWER)
  1138. set(SDL_POWER_ANDROID 1)
  1139. file(GLOB ANDROID_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/android/*.c)
  1140. list(APPEND SOURCE_FILES ${ANDROID_POWER_SOURCES})
  1141. set(HAVE_SDL_POWER TRUE)
  1142. endif()
  1143. if(SDL_LOCALE)
  1144. file(GLOB ANDROID_LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/android/*.c)
  1145. list(APPEND SOURCE_FILES ${ANDROID_LOCALE_SOURCES})
  1146. set(HAVE_SDL_LOCALE TRUE)
  1147. endif()
  1148. if(SDL_TIMERS)
  1149. set(SDL_TIMER_UNIX 1)
  1150. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
  1151. list(APPEND SOURCE_FILES ${TIMER_SOURCES})
  1152. set(HAVE_SDL_TIMERS TRUE)
  1153. endif()
  1154. if(SDL_SENSOR)
  1155. set(SDL_SENSOR_ANDROID 1)
  1156. set(HAVE_SDL_SENSORS TRUE)
  1157. file(GLOB ANDROID_SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/android/*.c)
  1158. list(APPEND SOURCE_FILES ${ANDROID_SENSOR_SOURCES})
  1159. endif()
  1160. if(SDL_VIDEO)
  1161. set(SDL_VIDEO_DRIVER_ANDROID 1)
  1162. file(GLOB ANDROID_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/android/*.c)
  1163. list(APPEND SOURCE_FILES ${ANDROID_VIDEO_SOURCES})
  1164. set(HAVE_SDL_VIDEO TRUE)
  1165. # Core stuff
  1166. # find_library(ANDROID_DL_LIBRARY dl)
  1167. # FIXME failing dlopen https://github.com/android-ndk/ndk/issues/929
  1168. list(APPEND EXTRA_LIBS dl log android)
  1169. target_compile_definitions(sdl-build-options INTERFACE "-DGL_GLEXT_PROTOTYPES")
  1170. #enable gles
  1171. if(SDL_OPENGLES)
  1172. set(SDL_VIDEO_OPENGL_EGL 1)
  1173. set(HAVE_OPENGLES TRUE)
  1174. set(SDL_VIDEO_OPENGL_ES 1)
  1175. set(SDL_VIDEO_RENDER_OGL_ES 1)
  1176. set(SDL_VIDEO_OPENGL_ES2 1)
  1177. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  1178. list(APPEND EXTRA_LIBS GLESv1_CM GLESv2)
  1179. endif()
  1180. if(SDL_VULKAN)
  1181. CHECK_C_SOURCE_COMPILES("
  1182. #if defined(__ARM_ARCH) && __ARM_ARCH < 7
  1183. #error Vulkan doesn't work on this configuration
  1184. #endif
  1185. int main(int argc, char **argv) { return 0; }
  1186. " VULKAN_PASSED_ANDROID_CHECKS)
  1187. if(VULKAN_PASSED_ANDROID_CHECKS)
  1188. set(SDL_VIDEO_VULKAN 1)
  1189. set(HAVE_VULKAN TRUE)
  1190. endif()
  1191. endif()
  1192. endif()
  1193. CheckPTHREAD()
  1194. if(SDL_CLOCK_GETTIME)
  1195. set(HAVE_CLOCK_GETTIME 1)
  1196. endif()
  1197. elseif(EMSCRIPTEN)
  1198. # Hide noisy warnings that intend to aid mostly during initial stages of porting a new
  1199. # project. Uncomment at will for verbose cross-compiling -I/../ path info.
  1200. target_compile_options(sdl-build-options INTERFACE "-Wno-warn-absolute-paths")
  1201. if(SDL_MISC)
  1202. file(GLOB EMSRIPTEN_MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/emscripten/*.c)
  1203. list(APPEND SOURCE_FILES ${EMSRIPTEN_MISC_SOURCES})
  1204. set(HAVE_SDL_MISC TRUE)
  1205. endif()
  1206. if(SDL_AUDIO)
  1207. set(SDL_AUDIO_DRIVER_EMSCRIPTEN 1)
  1208. file(GLOB EM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/emscripten/*.c)
  1209. list(APPEND SOURCE_FILES ${EM_AUDIO_SOURCES})
  1210. set(HAVE_SDL_AUDIO TRUE)
  1211. endif()
  1212. if(SDL_FILESYSTEM)
  1213. set(SDL_FILESYSTEM_EMSCRIPTEN 1)
  1214. file(GLOB EM_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/emscripten/*.c)
  1215. list(APPEND SOURCE_FILES ${EM_FILESYSTEM_SOURCES})
  1216. set(HAVE_SDL_FILESYSTEM TRUE)
  1217. endif()
  1218. if(SDL_JOYSTICK)
  1219. set(SDL_JOYSTICK_EMSCRIPTEN 1)
  1220. file(GLOB EM_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/emscripten/*.c)
  1221. list(APPEND SOURCE_FILES ${EM_JOYSTICK_SOURCES})
  1222. set(HAVE_SDL_JOYSTICK TRUE)
  1223. endif()
  1224. if(SDL_POWER)
  1225. set(SDL_POWER_EMSCRIPTEN 1)
  1226. file(GLOB EM_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/emscripten/*.c)
  1227. list(APPEND SOURCE_FILES ${EM_POWER_SOURCES})
  1228. set(HAVE_SDL_POWER TRUE)
  1229. endif()
  1230. if(SDL_LOCALE)
  1231. file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/emscripten/*.c)
  1232. list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
  1233. set(HAVE_SDL_LOCALE TRUE)
  1234. endif()
  1235. if(SDL_TIMERS)
  1236. set(SDL_TIMER_UNIX 1)
  1237. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
  1238. list(APPEND SOURCE_FILES ${TIMER_SOURCES})
  1239. set(HAVE_SDL_TIMERS TRUE)
  1240. if(SDL_CLOCK_GETTIME)
  1241. set(HAVE_CLOCK_GETTIME 1)
  1242. endif()
  1243. endif()
  1244. if(SDL_VIDEO)
  1245. set(SDL_VIDEO_DRIVER_EMSCRIPTEN 1)
  1246. file(GLOB EM_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/emscripten/*.c)
  1247. list(APPEND SOURCE_FILES ${EM_VIDEO_SOURCES})
  1248. set(HAVE_SDL_VIDEO TRUE)
  1249. #enable gles
  1250. if(SDL_OPENGLES)
  1251. set(SDL_VIDEO_OPENGL_EGL 1)
  1252. set(HAVE_OPENGLES TRUE)
  1253. set(SDL_VIDEO_OPENGL_ES2 1)
  1254. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  1255. endif()
  1256. endif()
  1257. CheckPTHREAD()
  1258. if(HAVE_LIBUNWIND_H)
  1259. list(APPEND EXTRA_TEST_LIBS unwind)
  1260. endif()
  1261. elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
  1262. if(SDL_AUDIO)
  1263. if(SYSV5 OR SOLARIS OR HPUX)
  1264. set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
  1265. file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
  1266. list(APPEND SOURCE_FILES ${SUN_AUDIO_SOURCES})
  1267. set(HAVE_SDL_AUDIO TRUE)
  1268. elseif(NETBSD)
  1269. set(SDL_AUDIO_DRIVER_NETBSD 1)
  1270. file(GLOB NETBSD_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/netbsd/*.c)
  1271. list(APPEND SOURCE_FILES ${NETBSD_AUDIO_SOURCES})
  1272. set(HAVE_SDL_AUDIO TRUE)
  1273. elseif(AIX)
  1274. set(SDL_AUDIO_DRIVER_PAUDIO 1)
  1275. file(GLOB AIX_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/paudio/*.c)
  1276. list(APPEND SOURCE_FILES ${AIX_AUDIO_SOURCES})
  1277. set(HAVE_SDL_AUDIO TRUE)
  1278. endif()
  1279. CheckOSS()
  1280. CheckALSA()
  1281. CheckJACK()
  1282. CheckPipewire()
  1283. CheckPulseAudio()
  1284. CheckESD()
  1285. CheckARTS()
  1286. CheckNAS()
  1287. CheckSNDIO()
  1288. CheckFusionSound()
  1289. endif()
  1290. if(SDL_VIDEO)
  1291. # Need to check for Raspberry PI first and add platform specific compiler flags, otherwise the test for GLES fails!
  1292. CheckRPI()
  1293. CheckX11()
  1294. CheckDirectFB()
  1295. # Need to check for EGL first because KMSDRM and Wayland depends on it.
  1296. CheckEGL()
  1297. CheckKMSDRM()
  1298. CheckGLX()
  1299. CheckOpenGL()
  1300. CheckOpenGLES()
  1301. CheckWayland()
  1302. CheckVivante()
  1303. # FIXME: implement CheckVulkan()
  1304. if(SDL_VULKAN)
  1305. set(SDL_VIDEO_VULKAN 1)
  1306. set(HAVE_VULKAN TRUE)
  1307. endif()
  1308. endif()
  1309. if(UNIX)
  1310. file(GLOB CORE_UNIX_SOURCES ${SDL2_SOURCE_DIR}/src/core/unix/*.c)
  1311. list(APPEND SOURCE_FILES ${CORE_UNIX_SOURCES})
  1312. check_c_source_compiles("
  1313. #include <linux/input.h>
  1314. #ifndef EVIOCGNAME
  1315. #error EVIOCGNAME() ioctl not available
  1316. #endif
  1317. int main(int argc, char** argv) { return 0; }" HAVE_INPUT_EVENTS)
  1318. if(LINUX)
  1319. check_c_source_compiles("
  1320. #include <linux/kd.h>
  1321. #include <linux/keyboard.h>
  1322. #include <sys/ioctl.h>
  1323. int main(int argc, char **argv) {
  1324. struct kbentry kbe;
  1325. kbe.kb_table = KG_CTRL;
  1326. ioctl(0, KDGKBENT, &kbe);
  1327. return 0;
  1328. }" HAVE_INPUT_KD)
  1329. elseif(FREEBSD)
  1330. check_c_source_compiles("
  1331. #include <sys/kbio.h>
  1332. #include <sys/ioctl.h>
  1333. int main(int argc, char **argv) {
  1334. accentmap_t accTable;
  1335. ioctl(0, KDENABIO, 1);
  1336. return 0;
  1337. }" HAVE_INPUT_KBIO)
  1338. endif()
  1339. if(HAVE_INPUT_EVENTS)
  1340. set(SDL_INPUT_LINUXEV 1)
  1341. endif()
  1342. if(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
  1343. set(SDL_HAPTIC_LINUX 1)
  1344. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/linux/*.c)
  1345. list(APPEND SOURCE_FILES ${HAPTIC_SOURCES})
  1346. set(HAVE_SDL_HAPTIC TRUE)
  1347. endif()
  1348. if(HAVE_INPUT_KD)
  1349. set(SDL_INPUT_LINUXKD 1)
  1350. endif()
  1351. if(HAVE_INPUT_KBIO)
  1352. set(SDL_INPUT_FBSDKBIO 1)
  1353. endif()
  1354. check_include_file("libudev.h" HAVE_LIBUDEV_H)
  1355. check_include_file("sys/inotify.h" HAVE_SYS_INOTIFY_H)
  1356. check_symbol_exists(inotify_init "sys/inotify.h" HAVE_INOTIFY_INIT)
  1357. check_symbol_exists(inotify_init1 "sys/inotify.h" HAVE_INOTIFY_INIT1)
  1358. if(HAVE_SYS_INOTIFY_H AND HAVE_INOTIFY_INIT)
  1359. set(HAVE_INOTIFY 1)
  1360. endif()
  1361. if(PKG_CONFIG_FOUND)
  1362. if(SDL_DBUS)
  1363. pkg_search_module(DBUS dbus-1 dbus)
  1364. if(DBUS_FOUND)
  1365. set(HAVE_DBUS_DBUS_H TRUE)
  1366. target_include_directories(sdl-build-options INTERFACE "${DBUS_INCLUDE_DIRS}")
  1367. # Fcitx need only dbus.
  1368. set(HAVE_FCITX TRUE)
  1369. set(HAVE_DBUS TRUE)
  1370. endif()
  1371. endif()
  1372. if(SDL_IBUS)
  1373. pkg_search_module(IBUS ibus-1.0 ibus)
  1374. find_path(HAVE_SYS_INOTIFY_H NAMES sys/inotify.h)
  1375. if(IBUS_FOUND AND HAVE_SYS_INOTIFY_H)
  1376. set(HAVE_IBUS_IBUS_H TRUE)
  1377. target_include_directories(sdl-build-options INTERFACE "${IBUS_INCLUDE_DIRS}")
  1378. set(HAVE_IBUS TRUE)
  1379. endif()
  1380. endif()
  1381. if (HAVE_IBUS_IBUS_H OR HAVE_FCITX)
  1382. set(SDL_USE_IME 1)
  1383. endif()
  1384. if(FREEBSD AND NOT HAVE_INOTIFY)
  1385. pkg_search_module(INOTIFY libinotify)
  1386. if(INOTIFY_FOUND)
  1387. set(HAVE_INOTIFY 1)
  1388. target_include_directories(sdl-build-options INTERFACE "${INOTIFY_INCLUDE_DIRS}")
  1389. list(APPEND EXTRA_LIBS ${INOTIFY_LIBRARIES})
  1390. endif()
  1391. endif()
  1392. if(HAVE_LIBUNWIND_H)
  1393. # We've already found the header, so link the lib if present.
  1394. # NB: This .pc file is not present on FreeBSD where the implicitly
  1395. # linked base system libgcc_s includes all libunwind ABI.
  1396. pkg_search_module(UNWIND libunwind)
  1397. pkg_search_module(UNWIND_GENERIC libunwind-generic)
  1398. list(APPEND EXTRA_TEST_LIBS ${UNWIND_LIBRARIES} ${UNWIND_GENERIC_LIBRARIES})
  1399. endif()
  1400. endif()
  1401. if(HAVE_DBUS_DBUS_H)
  1402. list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_dbus.c")
  1403. endif()
  1404. if(SDL_USE_IME)
  1405. list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_ime.c")
  1406. endif()
  1407. if(HAVE_IBUS_IBUS_H)
  1408. list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_ibus.c")
  1409. endif()
  1410. if(HAVE_FCITX)
  1411. list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_fcitx.c")
  1412. endif()
  1413. if(HAVE_LIBUDEV_H)
  1414. list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_udev.c")
  1415. endif()
  1416. if(HAVE_INPUT_EVENTS)
  1417. list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_evdev.c")
  1418. list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_evdev_kbd.c")
  1419. endif()
  1420. if(HAVE_INPUT_KBIO)
  1421. list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/freebsd/SDL_evdev_kbd_freebsd.c")
  1422. endif()
  1423. # Always compiled for Linux, unconditionally:
  1424. list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_evdev_capabilities.c")
  1425. list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_threadprio.c")
  1426. list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_sandbox.c")
  1427. # src/core/unix/*.c is included in a generic if(UNIX) section, elsewhere.
  1428. endif()
  1429. if(SDL_HIDAPI)
  1430. CheckHIDAPI()
  1431. endif()
  1432. if(SDL_JOYSTICK)
  1433. if(FREEBSD OR NETBSD OR OPENBSD OR BSDI)
  1434. CheckUSBHID()
  1435. endif()
  1436. if(LINUX AND HAVE_LINUX_INPUT_H AND NOT ANDROID)
  1437. set(SDL_JOYSTICK_LINUX 1)
  1438. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
  1439. list(APPEND SOURCE_FILES ${JOYSTICK_SOURCES})
  1440. set(HAVE_SDL_JOYSTICK TRUE)
  1441. endif()
  1442. endif()
  1443. CheckPTHREAD()
  1444. if(SDL_CLOCK_GETTIME)
  1445. check_library_exists(rt clock_gettime "" FOUND_CLOCK_GETTIME_LIBRT)
  1446. if(FOUND_CLOCK_GETTIME_LIBRT)
  1447. list(APPEND EXTRA_LIBS rt)
  1448. set(HAVE_CLOCK_GETTIME 1)
  1449. else()
  1450. check_library_exists(c clock_gettime "" FOUND_CLOCK_GETTIME_LIBC)
  1451. if(FOUND_CLOCK_GETTIME_LIBC)
  1452. set(HAVE_CLOCK_GETTIME 1)
  1453. endif()
  1454. endif()
  1455. endif()
  1456. check_include_file(linux/version.h HAVE_LINUX_VERSION_H)
  1457. if(HAVE_LINUX_VERSION_H)
  1458. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_LINUX_VERSION_H")
  1459. endif()
  1460. if(SDL_MISC)
  1461. file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/unix/*.c)
  1462. list(APPEND SOURCE_FILES ${MISC_SOURCES})
  1463. set(HAVE_SDL_MISC TRUE)
  1464. endif()
  1465. if(SDL_POWER)
  1466. if(LINUX)
  1467. set(SDL_POWER_LINUX 1)
  1468. file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/linux/*.c)
  1469. list(APPEND SOURCE_FILES ${POWER_SOURCES})
  1470. set(HAVE_SDL_POWER TRUE)
  1471. endif()
  1472. endif()
  1473. if(SDL_LOCALE)
  1474. file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/unix/*.c)
  1475. list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
  1476. set(HAVE_SDL_LOCALE TRUE)
  1477. endif()
  1478. if(SDL_FILESYSTEM)
  1479. set(SDL_FILESYSTEM_UNIX 1)
  1480. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/unix/*.c)
  1481. list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES})
  1482. set(HAVE_SDL_FILESYSTEM TRUE)
  1483. endif()
  1484. if(SDL_TIMERS)
  1485. set(SDL_TIMER_UNIX 1)
  1486. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
  1487. list(APPEND SOURCE_FILES ${TIMER_SOURCES})
  1488. set(HAVE_SDL_TIMERS TRUE)
  1489. endif()
  1490. set(SDL_RLD_FLAGS "")
  1491. if(SDL_RPATH AND SDL_SHARED)
  1492. if(BSDI OR FREEBSD OR LINUX OR NETBSD)
  1493. set(CMAKE_REQUIRED_FLAGS "-Wl,--enable-new-dtags")
  1494. check_c_compiler_flag("" HAVE_ENABLE_NEW_DTAGS)
  1495. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  1496. if(HAVE_ENABLE_NEW_DTAGS)
  1497. set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir} -Wl,--enable-new-dtags")
  1498. else()
  1499. set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir}")
  1500. endif()
  1501. elseif(SOLARIS)
  1502. set(SDL_RLD_FLAGS "-R\${libdir}")
  1503. endif()
  1504. set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  1505. set(HAVE_RPATH TRUE)
  1506. endif()
  1507. elseif(WINDOWS)
  1508. find_program(WINDRES windres)
  1509. check_c_source_compiles("
  1510. #include <windows.h>
  1511. int main(int argc, char **argv) { return 0; }" HAVE_WIN32_CC)
  1512. file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
  1513. list(APPEND SOURCE_FILES ${CORE_SOURCES})
  1514. if(WINDOWS_STORE)
  1515. file(GLOB WINRT_SOURCE_FILES ${SDL2_SOURCE_DIR}/src/core/winrt/*.c ${SDL2_SOURCE_DIR}/src/core/winrt/*.cpp)
  1516. list(APPEND SOURCE_FILES ${WINRT_SOURCE_FILES})
  1517. endif()
  1518. if(MSVC AND NOT SDL_LIBC)
  1519. # Prevent codegen that would use the VC runtime libraries.
  1520. set_property(DIRECTORY . APPEND PROPERTY COMPILE_OPTIONS "/GS-")
  1521. if(NOT ARCH_64 AND NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM")
  1522. set_property(DIRECTORY . APPEND PROPERTY COMPILE_OPTIONS "/arch:SSE")
  1523. endif()
  1524. endif()
  1525. if(SDL_MISC)
  1526. if(WINDOWS_STORE)
  1527. file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/winrt/*.cpp)
  1528. else()
  1529. file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/windows/*.c)
  1530. endif()
  1531. list(APPEND SOURCE_FILES ${MISC_SOURCES})
  1532. set(HAVE_SDL_MISC TRUE)
  1533. endif()
  1534. # Check for DirectX
  1535. if(SDL_DIRECTX)
  1536. if(DEFINED MSVC_VERSION AND NOT ${MSVC_VERSION} LESS 1700)
  1537. set(USE_WINSDK_DIRECTX TRUE)
  1538. endif()
  1539. if(NOT MINGW AND NOT USE_WINSDK_DIRECTX)
  1540. if("$ENV{DXSDK_DIR}" STREQUAL "")
  1541. message_error("DIRECTX requires the \$DXSDK_DIR environment variable to be set")
  1542. endif()
  1543. set(CMAKE_REQUIRED_FLAGS "/I\"$ENV{DXSDK_DIR}\\Include\"")
  1544. endif()
  1545. check_include_file(d3d9.h HAVE_D3D_H)
  1546. check_include_file(d3d11_1.h HAVE_D3D11_H)
  1547. check_c_source_compiles("
  1548. #include <winsdkver.h>
  1549. #include <sdkddkver.h>
  1550. #include <d3d12.h>
  1551. ID3D12Device1 *device;
  1552. #if WDK_NTDDI_VERSION > 0x0A000008
  1553. int main(int argc, char **argv) { return 0; }
  1554. #endif" HAVE_D3D12_H)
  1555. check_include_file(ddraw.h HAVE_DDRAW_H)
  1556. check_include_file(dsound.h HAVE_DSOUND_H)
  1557. check_include_file(dinput.h HAVE_DINPUT_H)
  1558. if(WINDOWS_STORE OR CMAKE_GENERATOR_PLATFORM STREQUAL "ARM")
  1559. set(HAVE_DINPUT_H 0)
  1560. endif()
  1561. check_include_file(dxgi.h HAVE_DXGI_H)
  1562. if(HAVE_D3D_H OR HAVE_D3D11_H OR HAVE_D3D12_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H)
  1563. set(HAVE_DIRECTX TRUE)
  1564. if(NOT MINGW AND NOT USE_WINSDK_DIRECTX)
  1565. # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks
  1566. target_link_directories(sdl-build-options INTERFACE "$$ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH}")
  1567. target_include_directories(sdl-build-options INTERFACE "$ENV{DXSDK_DIR}\\Include")
  1568. endif()
  1569. endif()
  1570. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  1571. endif()
  1572. if(SDL_XINPUT)
  1573. # xinput.h may need windows.h, but does not include it itself.
  1574. check_c_source_compiles("
  1575. #include <windows.h>
  1576. #include <xinput.h>
  1577. int main(int argc, char **argv) { return 0; }" HAVE_XINPUT_H)
  1578. check_c_source_compiles("
  1579. #include <windows.h>
  1580. #include <xinput.h>
  1581. XINPUT_GAMEPAD_EX x1;
  1582. int main(int argc, char **argv) { return 0; }" HAVE_XINPUT_GAMEPAD_EX)
  1583. check_c_source_compiles("
  1584. #include <windows.h>
  1585. #include <xinput.h>
  1586. XINPUT_STATE_EX s1;
  1587. int main(int argc, char **argv) { return 0; }" HAVE_XINPUT_STATE_EX)
  1588. check_c_source_compiles("
  1589. #define COBJMACROS
  1590. #include <windows.gaming.input.h>
  1591. __x_ABI_CWindows_CGaming_CInput_CIGamepadStatics2 *s2;
  1592. int main(int argc, char **argv) { return 0; }" HAVE_WINDOWS_GAMING_INPUT_H)
  1593. endif()
  1594. # headers needed elsewhere
  1595. check_include_file(tpcshrd.h HAVE_TPCSHRD_H)
  1596. check_include_file(roapi.h HAVE_ROAPI_H)
  1597. check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
  1598. check_include_file(audioclient.h HAVE_AUDIOCLIENT_H)
  1599. check_include_file(sensorsapi.h HAVE_SENSORSAPI_H)
  1600. check_include_file(shellscalingapi.h HAVE_SHELLSCALINGAPI_H)
  1601. if(SDL_AUDIO)
  1602. if(NOT WINDOWS_STORE)
  1603. set(SDL_AUDIO_DRIVER_WINMM 1)
  1604. file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c)
  1605. list(APPEND SOURCE_FILES ${WINMM_AUDIO_SOURCES})
  1606. set(HAVE_SDL_AUDIO TRUE)
  1607. endif()
  1608. if(HAVE_DSOUND_H AND NOT WINDOWS_STORE)
  1609. set(SDL_AUDIO_DRIVER_DSOUND 1)
  1610. file(GLOB DSOUND_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/directsound/*.c)
  1611. list(APPEND SOURCE_FILES ${DSOUND_AUDIO_SOURCES})
  1612. set(HAVE_SDL_AUDIO TRUE)
  1613. endif()
  1614. if(SDL_WASAPI AND HAVE_AUDIOCLIENT_H AND HAVE_MMDEVICEAPI_H)
  1615. set(SDL_AUDIO_DRIVER_WASAPI 1)
  1616. set(HAVE_WASAPI TRUE)
  1617. file(GLOB WASAPI_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/wasapi/*.c)
  1618. if(WINDOWS_STORE)
  1619. list(APPEND WASAPI_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/wasapi/SDL_wasapi_winrt.cpp)
  1620. endif()
  1621. list(APPEND SOURCE_FILES ${WASAPI_AUDIO_SOURCES})
  1622. set(HAVE_SDL_AUDIO TRUE)
  1623. endif()
  1624. endif()
  1625. if(SDL_VIDEO)
  1626. # requires SDL_LOADSO on Windows (IME, DX, etc.)
  1627. if(NOT SDL_LOADSO)
  1628. message_error("SDL_VIDEO requires SDL_LOADSO, which is not enabled")
  1629. endif()
  1630. if(WINDOWS_STORE)
  1631. set(SDL_VIDEO_DRIVER_WINRT 1)
  1632. file(GLOB WIN_VIDEO_SOURCES
  1633. ${SDL2_SOURCE_DIR}/src/video/winrt/*.c
  1634. ${SDL2_SOURCE_DIR}/src/video/winrt/*.cpp
  1635. ${SDL2_SOURCE_DIR}/src/render/direct3d11/*.cpp
  1636. )
  1637. else()
  1638. set(SDL_VIDEO_DRIVER_WINDOWS 1)
  1639. file(GLOB WIN_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/windows/*.c)
  1640. endif()
  1641. list(APPEND SOURCE_FILES ${WIN_VIDEO_SOURCES})
  1642. if(SDL_RENDER_D3D AND HAVE_D3D_H AND NOT WINDOWS_STORE)
  1643. set(SDL_VIDEO_RENDER_D3D 1)
  1644. set(HAVE_RENDER_D3D TRUE)
  1645. endif()
  1646. if(SDL_RENDER_D3D AND HAVE_D3D11_H)
  1647. set(SDL_VIDEO_RENDER_D3D11 1)
  1648. set(HAVE_RENDER_D3D TRUE)
  1649. endif()
  1650. if(SDL_RENDER_D3D AND HAVE_D3D12_H AND NOT WINDOWS_STORE)
  1651. set(SDL_VIDEO_RENDER_D3D12 1)
  1652. set(HAVE_RENDER_D3D TRUE)
  1653. endif()
  1654. set(HAVE_SDL_VIDEO TRUE)
  1655. endif()
  1656. if(SDL_THREADS)
  1657. set(SDL_THREAD_GENERIC_COND_SUFFIX 1)
  1658. set(SDL_THREAD_WINDOWS 1)
  1659. list(APPEND SOURCE_FILES
  1660. ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c
  1661. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_syscond_cv.c
  1662. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_sysmutex.c
  1663. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_syssem.c
  1664. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systhread.c
  1665. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systls.c)
  1666. set(HAVE_SDL_THREADS TRUE)
  1667. endif()
  1668. if(SDL_SENSOR AND HAVE_SENSORSAPI_H AND NOT WINDOWS_STORE)
  1669. set(SDL_SENSOR_WINDOWS 1)
  1670. set(HAVE_SDL_SENSORS TRUE)
  1671. file(GLOB WINDOWS_SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/windows/*.c)
  1672. list(APPEND SOURCE_FILES ${WINDOWS_SENSOR_SOURCES})
  1673. endif()
  1674. if(SDL_POWER)
  1675. if(WINDOWS_STORE)
  1676. set(SDL_POWER_WINRT 1)
  1677. list(APPEND SOURCE_FILES ${SDL2_SOURCE_DIR}/src/power/winrt/SDL_syspower.cpp)
  1678. else()
  1679. set(SDL_POWER_WINDOWS 1)
  1680. list(APPEND SOURCE_FILES ${SDL2_SOURCE_DIR}/src/power/windows/SDL_syspower.c)
  1681. set(HAVE_SDL_POWER TRUE)
  1682. endif()
  1683. endif()
  1684. if(SDL_LOCALE)
  1685. if(WINDOWS_STORE)
  1686. file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/winrt/*.c)
  1687. else()
  1688. file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/windows/*.c)
  1689. endif()
  1690. list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
  1691. set(HAVE_SDL_LOCALE TRUE)
  1692. endif()
  1693. if(SDL_FILESYSTEM)
  1694. set(SDL_FILESYSTEM_WINDOWS 1)
  1695. if(WINDOWS_STORE)
  1696. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/winrt/*.cpp)
  1697. else()
  1698. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/windows/*.c)
  1699. endif()
  1700. list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES})
  1701. set(HAVE_SDL_FILESYSTEM TRUE)
  1702. endif()
  1703. # Libraries for Win32 native and MinGW
  1704. if(NOT WINDOWS_STORE)
  1705. list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 setupapi shell32)
  1706. endif()
  1707. if(WINDOWS_STORE)
  1708. list(APPEND EXTRA_LIBS
  1709. -nodefaultlib:vccorlib$<$<CONFIG:Debug>:d>
  1710. -nodefaultlib:msvcrt$<$<CONFIG:Debug>:d>
  1711. vccorlib$<$<CONFIG:Debug>:d>.lib
  1712. msvcrt$<$<CONFIG:Debug>:d>.lib
  1713. )
  1714. endif()
  1715. if(SDL_TIMERS)
  1716. set(SDL_TIMER_WINDOWS 1)
  1717. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/windows/*.c)
  1718. list(APPEND SOURCE_FILES ${TIMER_SOURCES})
  1719. set(HAVE_SDL_TIMERS TRUE)
  1720. endif()
  1721. if(SDL_LOADSO)
  1722. set(SDL_LOADSO_WINDOWS 1)
  1723. file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/windows/*.c)
  1724. list(APPEND SOURCE_FILES ${LOADSO_SOURCES})
  1725. set(HAVE_SDL_LOADSO TRUE)
  1726. endif()
  1727. file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
  1728. list(APPEND SOURCE_FILES ${CORE_SOURCES})
  1729. if(SDL_VIDEO)
  1730. if(SDL_OPENGL AND NOT WINDOWS_STORE)
  1731. set(SDL_VIDEO_OPENGL 1)
  1732. set(SDL_VIDEO_OPENGL_WGL 1)
  1733. set(SDL_VIDEO_RENDER_OGL 1)
  1734. set(HAVE_OPENGL TRUE)
  1735. endif()
  1736. if(SDL_OPENGLES)
  1737. set(SDL_VIDEO_OPENGL_EGL 1)
  1738. set(SDL_VIDEO_OPENGL_ES2 1)
  1739. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  1740. set(HAVE_OPENGLES TRUE)
  1741. endif()
  1742. if(SDL_VULKAN)
  1743. set(SDL_VIDEO_VULKAN 1)
  1744. set(HAVE_VULKAN TRUE)
  1745. endif()
  1746. endif()
  1747. if(SDL_HIDAPI)
  1748. CheckHIDAPI()
  1749. endif()
  1750. if(SDL_JOYSTICK)
  1751. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/windows/*.c)
  1752. list(APPEND SOURCE_FILES ${JOYSTICK_SOURCES})
  1753. if(NOT WINDOWS_STORE)
  1754. set(SDL_JOYSTICK_RAWINPUT 1)
  1755. endif()
  1756. if(HAVE_DINPUT_H)
  1757. set(SDL_JOYSTICK_DINPUT 1)
  1758. list(APPEND EXTRA_LIBS dinput8)
  1759. endif()
  1760. if(HAVE_XINPUT_H)
  1761. if(NOT WINDOWS_STORE)
  1762. set(SDL_JOYSTICK_XINPUT 1)
  1763. set(HAVE_XINPUT TRUE)
  1764. endif()
  1765. if(HAVE_WINDOWS_GAMING_INPUT_H)
  1766. set(SDL_JOYSTICK_WGI 1)
  1767. endif()
  1768. endif()
  1769. set(HAVE_SDL_JOYSTICK TRUE)
  1770. if(SDL_HAPTIC)
  1771. if((HAVE_DINPUT_H OR HAVE_XINPUT_H) AND NOT WINDOWS_STORE)
  1772. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/windows/*.c)
  1773. if(HAVE_DINPUT_H)
  1774. set(SDL_HAPTIC_DINPUT 1)
  1775. endif()
  1776. if(HAVE_XINPUT_H)
  1777. set(SDL_HAPTIC_XINPUT 1)
  1778. endif()
  1779. else()
  1780. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  1781. set(SDL_HAPTIC_DUMMY 1)
  1782. endif()
  1783. list(APPEND SOURCE_FILES ${HAPTIC_SOURCES})
  1784. set(HAVE_SDL_HAPTIC TRUE)
  1785. endif()
  1786. endif()
  1787. file(GLOB VERSION_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.rc)
  1788. file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.c)
  1789. if(MINGW OR CYGWIN)
  1790. if(NOT SDL2_DISABLE_SDL2MAIN)
  1791. list(APPEND SDL_CFLAGS "-Dmain=SDL_main")
  1792. list(INSERT SDL_LIBS 0 "-lSDL2main")
  1793. endif(NOT SDL2_DISABLE_SDL2MAIN)
  1794. list(INSERT SDL_LIBS 0 "-lmingw32" "-mwindows")
  1795. endif()
  1796. elseif(APPLE)
  1797. # TODO: rework this all for proper MacOS X, iOS and Darwin support
  1798. # We always need these libs on macOS at the moment.
  1799. # !!! FIXME: we need Carbon for some very old API calls in
  1800. # !!! FIXME: src/video/cocoa/SDL_cocoakeyboard.c, but we should figure out
  1801. # !!! FIXME: how to dump those.
  1802. if(DARWIN OR MACOSX)
  1803. set(SDL_FRAMEWORK_COCOA 1)
  1804. set(SDL_FRAMEWORK_CARBON 1)
  1805. endif()
  1806. set(SDL_FRAMEWORK_FOUNDATION 1)
  1807. set(SDL_FRAMEWORK_COREVIDEO 1)
  1808. # Requires the darwin file implementation
  1809. if(SDL_FILE)
  1810. file(GLOB EXTRA_SOURCES ${SDL2_SOURCE_DIR}/src/file/cocoa/*.m)
  1811. list(APPEND SOURCE_FILES ${EXTRA_SOURCES})
  1812. set(HAVE_SDL_FILE TRUE)
  1813. endif()
  1814. if(IOS OR TVOS)
  1815. file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/uikit/*.c)
  1816. endif()
  1817. if(SDL_MISC)
  1818. if(IOS OR TVOS)
  1819. file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/ios/*.m)
  1820. else()
  1821. file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/macosx/*.m)
  1822. endif()
  1823. list(APPEND SOURCE_FILES ${MISC_SOURCES})
  1824. set(HAVE_SDL_MISC TRUE)
  1825. endif()
  1826. if(SDL_AUDIO)
  1827. set(SDL_AUDIO_DRIVER_COREAUDIO 1)
  1828. file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.m)
  1829. list(APPEND SOURCE_FILES ${AUDIO_SOURCES})
  1830. set(HAVE_SDL_AUDIO TRUE)
  1831. set(SDL_FRAMEWORK_COREAUDIO 1)
  1832. set(SDL_FRAMEWORK_AUDIOTOOLBOX 1)
  1833. set(SDL_FRAMEWORK_AVFOUNDATION 1)
  1834. endif()
  1835. if(SDL_HIDAPI)
  1836. CheckHIDAPI()
  1837. endif()
  1838. if(SDL_JOYSTICK)
  1839. file(GLOB MFI_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m)
  1840. if(IOS OR TVOS)
  1841. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
  1842. set(SDL_JOYSTICK_MFI 1)
  1843. if(IOS)
  1844. set(SDL_FRAMEWORK_COREMOTION 1)
  1845. endif()
  1846. set(SDL_FRAMEWORK_GAMECONTROLLER 1)
  1847. set(SDL_FRAMEWORK_COREHAPTICS 1)
  1848. else()
  1849. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
  1850. set_property(SOURCE ${MFI_JOYSTICK_SOURCES} APPEND_STRING PROPERTY COMPILE_FLAGS " -fobjc-weak")
  1851. check_objc_source_compiles("
  1852. #include <AvailabilityMacros.h>
  1853. #include <TargetConditionals.h>
  1854. #import <Foundation/Foundation.h>
  1855. #import <GameController/GameController.h>
  1856. #if MAC_OS_X_VERSION_MIN_REQUIRED < 1080
  1857. #error GameController framework doesn't work on this configuration
  1858. #endif
  1859. #if TARGET_CPU_X86
  1860. #error GameController framework doesn't work on this configuration
  1861. #endif
  1862. int main() { return 0; }" HAVE_FRAMEWORK_GAMECONTROLLER)
  1863. check_objc_source_compiles("
  1864. #include <AvailabilityMacros.h>
  1865. #include <TargetConditionals.h>
  1866. #import <Foundation/Foundation.h>
  1867. #import <CoreHaptics/CoreHaptics.h>
  1868. int main() { return 0; }" HAVE_FRAMEWORK_COREHAPTICS)
  1869. if(HAVE_FRAMEWORK_GAMECONTROLLER AND HAVE_FRAMEWORK_COREHAPTICS)
  1870. # Only enable MFI if we also have CoreHaptics to ensure rumble works
  1871. set(SDL_JOYSTICK_MFI 1)
  1872. set(SDL_FRAMEWORK_GAMECONTROLLER 1)
  1873. set(SDL_FRAMEWORK_COREHAPTICS 1)
  1874. endif()
  1875. set(SDL_JOYSTICK_IOKIT 1)
  1876. set(SDL_FRAMEWORK_IOKIT 1)
  1877. set(SDL_FRAMEWORK_FF 1)
  1878. endif()
  1879. list(APPEND SOURCE_FILES ${JOYSTICK_SOURCES} ${MFI_JOYSTICK_SOURCES})
  1880. set(HAVE_SDL_JOYSTICK TRUE)
  1881. endif()
  1882. if(SDL_HAPTIC)
  1883. if (IOS OR TVOS)
  1884. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  1885. set(SDL_HAPTIC_DUMMY 1)
  1886. else()
  1887. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/darwin/*.c)
  1888. set(SDL_HAPTIC_IOKIT 1)
  1889. set(SDL_FRAMEWORK_IOKIT 1)
  1890. set(SDL_FRAMEWORK_FF 1)
  1891. endif()
  1892. list(APPEND SOURCE_FILES ${HAPTIC_SOURCES})
  1893. set(HAVE_SDL_HAPTIC TRUE)
  1894. endif()
  1895. if(SDL_POWER)
  1896. if (IOS OR TVOS)
  1897. file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/uikit/*.m)
  1898. set(SDL_POWER_UIKIT 1)
  1899. else()
  1900. file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/macosx/*.c)
  1901. set(SDL_POWER_MACOSX 1)
  1902. set(SDL_FRAMEWORK_IOKIT 1)
  1903. endif()
  1904. list(APPEND SOURCE_FILES ${POWER_SOURCES})
  1905. set(HAVE_SDL_POWER TRUE)
  1906. endif()
  1907. if(SDL_LOCALE)
  1908. file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/macosx/*.m)
  1909. list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
  1910. set(HAVE_SDL_LOCALE TRUE)
  1911. endif()
  1912. if(SDL_TIMERS)
  1913. set(SDL_TIMER_UNIX 1)
  1914. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
  1915. list(APPEND SOURCE_FILES ${TIMER_SOURCES})
  1916. set(HAVE_SDL_TIMERS TRUE)
  1917. endif(SDL_TIMERS)
  1918. if(SDL_FILESYSTEM)
  1919. set(SDL_FILESYSTEM_COCOA 1)
  1920. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
  1921. list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES})
  1922. set(HAVE_SDL_FILESYSTEM TRUE)
  1923. endif()
  1924. if(SDL_SENSOR)
  1925. if(IOS)
  1926. set(SDL_SENSOR_COREMOTION 1)
  1927. set(HAVE_SDL_SENSORS TRUE)
  1928. file(GLOB SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/coremotion/*.m)
  1929. list(APPEND SOURCE_FILES ${SENSOR_SOURCES})
  1930. endif()
  1931. endif()
  1932. # iOS hack needed - http://code.google.com/p/ios-cmake/ ?
  1933. if(SDL_VIDEO)
  1934. if (IOS OR TVOS)
  1935. set(SDL_VIDEO_DRIVER_UIKIT 1)
  1936. set(SDL_FRAMEWORK_COREGRAPHICS 1)
  1937. set(SDL_FRAMEWORK_QUARTZCORE 1)
  1938. set(SDL_FRAMEWORK_UIKIT 1)
  1939. set(SDL_IPHONE_KEYBOARD 1)
  1940. set(SDL_IPHONE_LAUNCHSCREEN 1)
  1941. file(GLOB UIKITVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/uikit/*.m)
  1942. list(APPEND SOURCE_FILES ${UIKITVIDEO_SOURCES})
  1943. set(HAVE_SDL_VIDEO TRUE)
  1944. else()
  1945. CheckCOCOA()
  1946. if(SDL_OPENGL)
  1947. set(SDL_VIDEO_OPENGL 1)
  1948. set(SDL_VIDEO_OPENGL_CGL 1)
  1949. set(SDL_VIDEO_RENDER_OGL 1)
  1950. set(HAVE_OPENGL TRUE)
  1951. endif()
  1952. endif()
  1953. if(SDL_OPENGLES)
  1954. if(IOS OR TVOS)
  1955. set(SDL_FRAMEWORK_OPENGLES 1)
  1956. set(SDL_VIDEO_OPENGL_ES 1)
  1957. set(SDL_VIDEO_RENDER_OGL_ES 1)
  1958. else()
  1959. set(SDL_VIDEO_OPENGL_EGL 1)
  1960. endif()
  1961. set(SDL_VIDEO_OPENGL_ES2 1)
  1962. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  1963. set(HAVE_OPENGLES TRUE)
  1964. endif()
  1965. if(SDL_VULKAN OR SDL_METAL OR SDL_RENDER_METAL)
  1966. check_objc_source_compiles("
  1967. #include <AvailabilityMacros.h>
  1968. #import <Metal/Metal.h>
  1969. #import <QuartzCore/CAMetalLayer.h>
  1970. #if (!TARGET_CPU_X86_64 && !TARGET_CPU_ARM64)
  1971. #error Metal doesn't work on this configuration
  1972. #endif
  1973. int main(int argc, char **argv) { return 0; }" HAVE_FRAMEWORK_METAL)
  1974. if(HAVE_FRAMEWORK_METAL)
  1975. set(SDL_FRAMEWORK_METAL 1)
  1976. set(SDL_FRAMEWORK_QUARTZCORE 1)
  1977. if(SDL_VULKAN)
  1978. set(SDL_VIDEO_VULKAN 1)
  1979. set(HAVE_VULKAN TRUE)
  1980. endif()
  1981. if(SDL_METAL)
  1982. set(SDL_VIDEO_METAL 1)
  1983. set(HAVE_METAL TRUE)
  1984. endif()
  1985. if(SDL_RENDER_METAL)
  1986. file(GLOB RENDER_METAL_SOURCES ${SDL2_SOURCE_DIR}/src/render/metal/*.m)
  1987. list(APPEND SOURCE_FILES ${RENDER_METAL_SOURCES})
  1988. set(SDL_VIDEO_RENDER_METAL 1)
  1989. set(HAVE_RENDER_METAL TRUE)
  1990. endif()
  1991. endif()
  1992. endif()
  1993. endif()
  1994. # Actually load the frameworks at the end so we don't duplicate include.
  1995. if(SDL_FRAMEWORK_COREVIDEO)
  1996. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,CoreVideo")
  1997. endif()
  1998. if(SDL_FRAMEWORK_COCOA)
  1999. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,Cocoa")
  2000. endif()
  2001. if(SDL_FRAMEWORK_IOKIT)
  2002. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,IOKit")
  2003. endif()
  2004. if(SDL_FRAMEWORK_FF)
  2005. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,ForceFeedback")
  2006. endif()
  2007. if(SDL_FRAMEWORK_CARBON)
  2008. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,Carbon")
  2009. endif()
  2010. if(SDL_FRAMEWORK_COREAUDIO)
  2011. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,CoreAudio")
  2012. endif()
  2013. if(SDL_FRAMEWORK_AUDIOTOOLBOX)
  2014. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,AudioToolbox")
  2015. endif()
  2016. if(SDL_FRAMEWORK_AVFOUNDATION)
  2017. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,AVFoundation")
  2018. endif()
  2019. if(SDL_FRAMEWORK_COREBLUETOOTH)
  2020. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,CoreBluetooth")
  2021. endif()
  2022. if(SDL_FRAMEWORK_COREGRAPHICS)
  2023. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,CoreGraphics")
  2024. endif()
  2025. if(SDL_FRAMEWORK_COREMOTION)
  2026. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,CoreMotion")
  2027. endif()
  2028. if(SDL_FRAMEWORK_FOUNDATION)
  2029. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,Foundation")
  2030. endif()
  2031. if(SDL_FRAMEWORK_GAMECONTROLLER)
  2032. find_library(GAMECONTROLLER GameController)
  2033. if(GAMECONTROLLER)
  2034. list(APPEND EXTRA_LDFLAGS "-Wl,-weak_framework,GameController")
  2035. endif()
  2036. endif()
  2037. if(SDL_FRAMEWORK_METAL)
  2038. if(IOS OR TVOS)
  2039. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,Metal")
  2040. else()
  2041. list(APPEND EXTRA_LDFLAGS "-Wl,-weak_framework,Metal")
  2042. endif()
  2043. endif()
  2044. if(SDL_FRAMEWORK_OPENGLES)
  2045. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,OpenGLES")
  2046. endif()
  2047. if(SDL_FRAMEWORK_QUARTZCORE)
  2048. if(IOS OR TVOS)
  2049. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,QuartzCore")
  2050. else()
  2051. list(APPEND EXTRA_LDFLAGS "-Wl,-weak_framework,QuartzCore")
  2052. endif()
  2053. endif()
  2054. if(SDL_FRAMEWORK_UIKIT)
  2055. list(APPEND EXTRA_LDFLAGS "-Wl,-framework,UIKit")
  2056. endif()
  2057. if(SDL_FRAMEWORK_COREHAPTICS)
  2058. find_library(COREHAPTICS CoreHaptics)
  2059. if(COREHAPTICS)
  2060. list(APPEND EXTRA_LDFLAGS "-Wl,-weak_framework,CoreHaptics")
  2061. endif()
  2062. endif()
  2063. CheckPTHREAD()
  2064. elseif(HAIKU)
  2065. if(SDL_AUDIO)
  2066. set(SDL_AUDIO_DRIVER_HAIKU 1)
  2067. file(GLOB HAIKU_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/haiku/*.cc)
  2068. list(APPEND SOURCE_FILES ${HAIKU_AUDIO_SOURCES})
  2069. set(HAVE_SDL_AUDIO TRUE)
  2070. endif()
  2071. if(SDL_JOYSTICK)
  2072. set(SDL_JOYSTICK_HAIKU 1)
  2073. file(GLOB HAIKU_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/haiku/*.cc)
  2074. list(APPEND SOURCE_FILES ${HAIKU_JOYSTICK_SOURCES})
  2075. set(HAVE_SDL_JOYSTICK TRUE)
  2076. endif()
  2077. if(SDL_MISC)
  2078. file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/haiku/*.cc)
  2079. list(APPEND SOURCE_FILES ${MISC_SOURCES})
  2080. set(HAVE_SDL_MISC TRUE)
  2081. endif()
  2082. if(SDL_VIDEO)
  2083. set(SDL_VIDEO_DRIVER_HAIKU 1)
  2084. file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.cc)
  2085. list(APPEND SOURCE_FILES ${HAIKUVIDEO_SOURCES})
  2086. set(HAVE_SDL_VIDEO TRUE)
  2087. if(SDL_OPENGL)
  2088. # TODO: Use FIND_PACKAGE(OpenGL) instead
  2089. set(SDL_VIDEO_OPENGL 1)
  2090. set(SDL_VIDEO_OPENGL_HAIKU 1)
  2091. set(SDL_VIDEO_RENDER_OGL 1)
  2092. list(APPEND EXTRA_LIBS GL)
  2093. set(HAVE_OPENGL TRUE)
  2094. endif()
  2095. endif()
  2096. if(SDL_FILESYSTEM)
  2097. set(SDL_FILESYSTEM_HAIKU 1)
  2098. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/haiku/*.cc)
  2099. list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES})
  2100. set(HAVE_SDL_FILESYSTEM TRUE)
  2101. endif()
  2102. if(SDL_TIMERS)
  2103. set(SDL_TIMER_HAIKU 1)
  2104. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/haiku/*.c)
  2105. list(APPEND SOURCE_FILES ${TIMER_SOURCES})
  2106. set(HAVE_SDL_TIMERS TRUE)
  2107. endif()
  2108. if(SDL_POWER)
  2109. set(SDL_POWER_HAIKU 1)
  2110. file(GLOB HAIKU_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/haiku/*.c)
  2111. list(APPEND SOURCE_FILES ${HAIKU_POWER_SOURCES})
  2112. set(HAVE_SDL_POWER TRUE)
  2113. endif()
  2114. if(SDL_LOCALE)
  2115. file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/haiku/*.cc)
  2116. list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
  2117. set(HAVE_SDL_LOCALE TRUE)
  2118. endif()
  2119. file(GLOB MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/haiku/*.cc)
  2120. list(APPEND SOURCE_FILES ${MAIN_SOURCES})
  2121. CheckPTHREAD()
  2122. list(APPEND EXTRA_LIBS root be media game device textencoding)
  2123. elseif(RISCOS)
  2124. if(SDL_MISC)
  2125. file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/riscos/*.c)
  2126. list(APPEND SOURCE_FILES ${MISC_SOURCES})
  2127. set(HAVE_SDL_MISC TRUE)
  2128. endif()
  2129. if(SDL_VIDEO)
  2130. set(SDL_VIDEO_DRIVER_RISCOS 1)
  2131. file(GLOB RISCOSVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/riscos/*.c)
  2132. list(APPEND SOURCE_FILES ${RISCOSVIDEO_SOURCES})
  2133. set(HAVE_SDL_VIDEO TRUE)
  2134. endif()
  2135. if(SDL_FILESYSTEM)
  2136. set(SDL_FILESYSTEM_RISCOS 1)
  2137. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/riscos/*.c)
  2138. list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES})
  2139. set(HAVE_SDL_FILESYSTEM TRUE)
  2140. endif()
  2141. if(SDL_TIMERS)
  2142. set(SDL_TIMER_UNIX 1)
  2143. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
  2144. list(APPEND SOURCE_FILES ${TIMER_SOURCES})
  2145. set(HAVE_SDL_TIMERS TRUE)
  2146. if(SDL_CLOCK_GETTIME)
  2147. set(HAVE_CLOCK_GETTIME 1)
  2148. endif()
  2149. endif()
  2150. CheckPTHREAD()
  2151. if(SDL_AUDIO)
  2152. CheckOSS()
  2153. endif()
  2154. elseif(VITA)
  2155. # SDL_spinlock.c Needs to be compiled in ARM mode.
  2156. cmake_push_check_state(RESET)
  2157. set(CMAKE_REQUIRED_FLAGS "-Werror=unused-command-line-argument")
  2158. check_c_compiler_flag(-marm HAVE_ARM_MODE)
  2159. if(HAVE_ARM_MODE)
  2160. set_property(SOURCE "${SDL2_SOURCE_DIR}/src/atomic/SDL_spinlock.c" APPEND_STRING PROPERTY COMPILE_FLAGS " -marm")
  2161. endif()
  2162. cmake_pop_check_state()
  2163. if(SDL_MISC)
  2164. file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/vita/*.c)
  2165. list(APPEND SOURCE_FILES ${MISC_SOURCES})
  2166. set(HAVE_SDL_MISC TRUE)
  2167. endif()
  2168. if(SDL_AUDIO)
  2169. set(SDL_AUDIO_DRIVER_VITA 1)
  2170. file(GLOB VITA_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/vita/*.c)
  2171. list(APPEND SOURCE_FILES ${VITA_AUDIO_SOURCES})
  2172. set(HAVE_SDL_AUDIO TRUE)
  2173. endif()
  2174. if(SDL_FILESYSTEM)
  2175. set(SDL_FILESYSTEM_VITA 1)
  2176. file(GLOB VITA_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/vita/*.c)
  2177. list(APPEND SOURCE_FILES ${VITA_FILESYSTEM_SOURCES})
  2178. set(HAVE_SDL_FILESYSTEM TRUE)
  2179. endif()
  2180. if(SDL_JOYSTICK)
  2181. set(SDL_JOYSTICK_VITA 1)
  2182. file(GLOB VITA_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/vita/*.c)
  2183. list(APPEND SOURCE_FILES ${VITA_JOYSTICK_SOURCES})
  2184. set(HAVE_SDL_JOYSTICK TRUE)
  2185. endif()
  2186. if(SDL_POWER)
  2187. set(SDL_POWER_VITA 1)
  2188. file(GLOB VITA_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/vita/*.c)
  2189. list(APPEND SOURCE_FILES ${VITA_POWER_SOURCES})
  2190. set(HAVE_SDL_POWER TRUE)
  2191. endif()
  2192. if(SDL_THREADS)
  2193. set(SDL_THREAD_VITA 1)
  2194. list(APPEND SOURCE_FILES
  2195. ${SDL2_SOURCE_DIR}/src/thread/vita/SDL_sysmutex.c
  2196. ${SDL2_SOURCE_DIR}/src/thread/vita/SDL_syssem.c
  2197. ${SDL2_SOURCE_DIR}/src/thread/vita/SDL_systhread.c
  2198. ${SDL2_SOURCE_DIR}/src/thread/vita/SDL_syscond.c
  2199. ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_systls.c)
  2200. set(HAVE_SDL_THREADS TRUE)
  2201. endif()
  2202. if(SDL_LOCALE)
  2203. file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/vita/*.c)
  2204. list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
  2205. set(HAVE_SDL_LOCALE TRUE)
  2206. endif()
  2207. if(SDL_TIMERS)
  2208. set(SDL_TIMER_VITA 1)
  2209. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/vita/*.c)
  2210. list(APPEND SOURCE_FILES ${TIMER_SOURCES})
  2211. set(HAVE_SDL_TIMERS TRUE)
  2212. endif()
  2213. if(SDL_SENSOR)
  2214. set(SDL_SENSOR_VITA 1)
  2215. set(HAVE_SDL_SENSORS TRUE)
  2216. file(GLOB VITA_SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/vita/*.c)
  2217. list(APPEND SOURCE_FILES ${VITA_SENSOR_SOURCES})
  2218. endif()
  2219. if(SDL_VIDEO)
  2220. set(SDL_VIDEO_DRIVER_VITA 1)
  2221. file(GLOB VITA_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/vita/*.c)
  2222. list(APPEND SOURCE_FILES ${VITA_VIDEO_SOURCES})
  2223. set(HAVE_SDL_VIDEO TRUE)
  2224. if(VIDEO_VITA_PIB)
  2225. check_include_file(pib.h HAVE_PIGS_IN_BLANKET_H)
  2226. if(HAVE_PIGS_IN_BLANKET_H)
  2227. set(SDL_VIDEO_OPENGL_ES2 1)
  2228. list(APPEND EXTRA_LIBS
  2229. pib
  2230. )
  2231. set(HAVE_VIDEO_VITA_PIB ON)
  2232. set(SDL_VIDEO_VITA_PIB 1)
  2233. else()
  2234. set(HAVE_VIDEO_VITA_PIB OFF)
  2235. endif()
  2236. endif()
  2237. if(VIDEO_VITA_PVR)
  2238. check_include_file(gpu_es4/psp2_pvr_hint.h HAVE_PVR_H)
  2239. if(HAVE_PVR_H)
  2240. target_compile_definitions(sdl-build-options INTERFACE "-D__psp2__")
  2241. check_include_file(gl4esinit.h HAVE_GL4ES_H)
  2242. set(SDL_VIDEO_OPENGL_EGL 1)
  2243. set(HAVE_OPENGLES TRUE)
  2244. set(SDL_VIDEO_OPENGL_ES 1)
  2245. set(SDL_VIDEO_RENDER_OGL_ES 1)
  2246. set(SDL_VIDEO_OPENGL_ES2 1)
  2247. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  2248. list(APPEND EXTRA_LIBS
  2249. libgpu_es4_ext_stub_weak
  2250. libIMGEGL_stub_weak
  2251. )
  2252. set(HAVE_VIDEO_VITA_PVR ON)
  2253. set(SDL_VIDEO_VITA_PVR 1)
  2254. if(HAVE_GL4ES_H)
  2255. set(HAVE_OPENGL TRUE)
  2256. set(SDL_VIDEO_OPENGL 1)
  2257. set(SDL_VIDEO_RENDER_OGL 1)
  2258. list(APPEND EXTRA_LIBS libGL_stub)
  2259. set(SDL_VIDEO_VITA_PVR_OGL 1)
  2260. endif()
  2261. else()
  2262. set(HAVE_VIDEO_VITA_PVR OFF)
  2263. endif()
  2264. endif()
  2265. set(SDL_VIDEO_RENDER_VITA_GXM 1)
  2266. list(APPEND EXTRA_LIBS
  2267. SceGxm_stub
  2268. SceDisplay_stub
  2269. SceCtrl_stub
  2270. SceAppMgr_stub
  2271. SceAppUtil_stub
  2272. SceAudio_stub
  2273. SceAudioIn_stub
  2274. SceSysmodule_stub
  2275. SceDisplay_stub
  2276. SceCtrl_stub
  2277. SceIofilemgr_stub
  2278. SceCommonDialog_stub
  2279. SceTouch_stub
  2280. SceHid_stub
  2281. SceMotion_stub
  2282. ScePower_stub
  2283. SceProcessmgr_stub
  2284. m
  2285. )
  2286. if(HAVE_VITA_PIB)
  2287. list(PREPEND EXTRA_LIBS
  2288. pib
  2289. libScePiglet_stub
  2290. SceShaccCg_stub
  2291. taihen_stub
  2292. )
  2293. endif()
  2294. if(HAVE_VITA_PVR)
  2295. list(PREPEND EXTRA_LIBS
  2296. SceIme_stub
  2297. )
  2298. endif()
  2299. endif()
  2300. set(HAVE_ARMSIMD TRUE)
  2301. # set(SDL_ARM_SIMD_BLITTERS 1)
  2302. # file(GLOB ARMSIMD_SOURCES ${SDL2_SOURCE_DIR}/src/video/arm/pixman-arm-simd*.S)
  2303. # list(APPEND SOURCE_FILES ${ARMSIMD_SOURCES})
  2304. set(HAVE_ARMNEON TRUE)
  2305. # set(SDL_ARM_NEON_BLITTERS 1)
  2306. # file(GLOB ARMNEON_SOURCES ${SDL2_SOURCE_DIR}/src/video/arm/pixman-arm-neon*.S)
  2307. # list(APPEND SOURCE_FILES ${ARMNEON_SOURCES})
  2308. # set_property(SOURCE ${SDL2_SOURCE_DIR}/src/video/arm/pixman-arm-simd-asm.S PROPERTY LANGUAGE C)
  2309. # set_property(SOURCE ${SDL2_SOURCE_DIR}/src/video/arm/pixman-arm-neon-asm.S PROPERTY LANGUAGE C)
  2310. target_compile_definitions(sdl-build-options INTERFACE "-D__VITA__")
  2311. # CheckPTHREAD()
  2312. elseif(PSP)
  2313. file(GLOB PSP_MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/psp/*.c)
  2314. list(APPEND SDLMAIN_SOURCES ${PSP_MAIN_SOURCES})
  2315. if(SDL_AUDIO)
  2316. set(SDL_AUDIO_DRIVER_PSP 1)
  2317. file(GLOB PSP_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/psp/*.c)
  2318. list(APPEND SOURCE_FILES ${PSP_AUDIO_SOURCES})
  2319. set(HAVE_SDL_AUDIO TRUE)
  2320. endif()
  2321. if(SDL_FILESYSTEM)
  2322. set(SDL_FILESYSTEM_PSP 1)
  2323. file(GLOB PSP_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/psp/*.c)
  2324. list(APPEND SOURCE_FILES ${PSP_FILESYSTEM_SOURCES})
  2325. set(HAVE_SDL_FILESYSTEM TRUE)
  2326. endif()
  2327. if(SDL_JOYSTICK)
  2328. set(SDL_JOYSTICK_PSP 1)
  2329. file(GLOB PSP_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/psp/*.c)
  2330. list(APPEND SOURCE_FILES ${PSP_JOYSTICK_SOURCES})
  2331. set(HAVE_SDL_JOYSTICK TRUE)
  2332. endif()
  2333. if(SDL_POWER)
  2334. set(SDL_POWER_PSP 1)
  2335. file(GLOB PSP_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/psp/*.c)
  2336. list(APPEND SOURCE_FILES ${PSP_POWER_SOURCES})
  2337. set(HAVE_SDL_POWER TRUE)
  2338. endif()
  2339. if(SDL_THREADS)
  2340. set(SDL_THREAD_PSP 1)
  2341. file(GLOB PSP_THREAD_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_systls.c ${SDL2_SOURCE_DIR}/src/thread/psp/*.c)
  2342. list(APPEND SOURCE_FILES ${PSP_THREAD_SOURCES})
  2343. set(HAVE_SDL_THREADS TRUE)
  2344. endif()
  2345. if(SDL_TIMERS)
  2346. set(SDL_TIMER_PSP 1)
  2347. file(GLOB PSP_TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/psp/*.c)
  2348. list(APPEND SOURCE_FILES ${PSP_TIMER_SOURCES})
  2349. set(HAVE_SDL_TIMERS TRUE)
  2350. endif()
  2351. if(SDL_VIDEO)
  2352. set(SDL_VIDEO_DRIVER_PSP 1)
  2353. set(SDL_VIDEO_RENDER_PSP 1)
  2354. file(GLOB PSP_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/psp/*.c)
  2355. list(APPEND SOURCE_FILES ${PSP_VIDEO_SOURCES})
  2356. set(SDL_VIDEO_OPENGL 1)
  2357. set(HAVE_SDL_VIDEO TRUE)
  2358. endif()
  2359. list(APPEND EXTRA_LIBS
  2360. GL
  2361. pspvram
  2362. pspaudio
  2363. pspvfpu
  2364. pspdisplay
  2365. pspgu
  2366. pspge
  2367. psphprm
  2368. pspctrl
  2369. psppower
  2370. )
  2371. if(NOT SDL2_DISABLE_SDL2MAIN)
  2372. list(INSERT SDL_LIBS 0 "-lSDL2main")
  2373. endif(NOT SDL2_DISABLE_SDL2MAIN)
  2374. elseif(PS2)
  2375. list(APPEND EXTRA_CFLAGS "-DPS2" "-D__PS2__" "-I$ENV{PS2SDK}/ports/include" "-I$ENV{PS2DEV}/gsKit/include")
  2376. file(GLOB PS2_MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/ps2/*.c)
  2377. set(SDLMAIN_SOURCES ${SDLMAIN_SOURCES} ${PS2_MAIN_SOURCES})
  2378. if(SDL_AUDIO)
  2379. set(SDL_AUDIO_DRIVER_PS2 1)
  2380. file(GLOB PS2_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/ps2/*.c)
  2381. set(SOURCE_FILES ${SOURCE_FILES} ${PS2_AUDIO_SOURCES})
  2382. set(HAVE_SDL_AUDIO TRUE)
  2383. endif()
  2384. if(SDL_FILESYSTEM)
  2385. set(SDL_FILESYSTEM_PS2 1)
  2386. file(GLOB PS2_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/ps2/*.c)
  2387. list(APPEND SOURCE_FILES ${PS2_FILESYSTEM_SOURCES})
  2388. set(HAVE_SDL_FILESYSTEM TRUE)
  2389. endif()
  2390. if(SDL_JOYSTICK)
  2391. set(SDL_JOYSTICK_PS2 1)
  2392. file(GLOB PS2_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/ps2/*.c)
  2393. list(APPEND SOURCE_FILES ${PS2_JOYSTICK_SOURCES})
  2394. set(HAVE_SDL_JOYSTICK TRUE)
  2395. endif()
  2396. if(SDL_THREADS)
  2397. set(SDL_THREAD_PS2 1)
  2398. file(GLOB PS2_THREAD_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_systls.c ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_sysmutex.c ${SDL2_SOURCE_DIR}/src/thread/ps2/*.c)
  2399. list(APPEND SOURCE_FILES ${PS2_THREAD_SOURCES})
  2400. set(HAVE_SDL_THREADS TRUE)
  2401. endif()
  2402. if(SDL_TIMERS)
  2403. set(SDL_TIMER_PS2 1)
  2404. file(GLOB PS2_TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/ps2/*.c)
  2405. list(APPEND SOURCE_FILES ${PS2_TIMER_SOURCES})
  2406. set(HAVE_SDL_TIMERS TRUE)
  2407. endif()
  2408. if(SDL_VIDEO)
  2409. set(SDL_VIDEO_DRIVER_PS2 1)
  2410. set(SDL_VIDEO_RENDER_PS2 1)
  2411. file(GLOB PS2_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/ps2/*.c ${SDL2_SOURCE_DIR}/src/render/ps2/*.c)
  2412. list(APPEND SOURCE_FILES ${PS2_VIDEO_SOURCES})
  2413. set(SDL_VIDEO_OPENGL 0)
  2414. set(HAVE_SDL_VIDEO TRUE)
  2415. endif()
  2416. list(APPEND EXTRA_LIBS
  2417. patches
  2418. gskit
  2419. dmakit
  2420. ps2_drivers
  2421. )
  2422. elseif(OS2)
  2423. list(APPEND EXTRA_CFLAGS "-DOS2EMX_PLAIN_CHAR")
  2424. file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/os2/*.c)
  2425. list(APPEND SOURCE_FILES ${CORE_SOURCES})
  2426. if(NOT (HAVE_ICONV AND HAVE_ICONV_H))
  2427. file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/os2/geniconv/*.c)
  2428. list(APPEND SOURCE_FILES ${CORE_SOURCES})
  2429. endif()
  2430. if(SDL_THREADS)
  2431. set(SDL_THREAD_OS2 1)
  2432. file(GLOB OS2_THREAD_SOURCES ${SDL2_SOURCE_DIR}/src/thread/os2/*.c)
  2433. list(APPEND SOURCE_FILES ${OS2_THREAD_SOURCES})
  2434. set(HAVE_SDL_THREADS TRUE)
  2435. endif()
  2436. if(SDL_TIMERS)
  2437. set(SDL_TIMER_UNIX 1)
  2438. file(GLOB OS2_TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/os2/*.c)
  2439. list(APPEND SOURCE_FILES ${OS2_TIMER_SOURCES})
  2440. set(HAVE_SDL_TIMERS TRUE)
  2441. endif()
  2442. if(SDL_LOADSO)
  2443. set(SDL_LOADSO_OS2 1)
  2444. file(GLOB OS2_LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/os2/*.c)
  2445. list(APPEND SOURCE_FILES ${OS2_LOADSO_SOURCES})
  2446. set(HAVE_SDL_LOADSO TRUE)
  2447. endif()
  2448. if(SDL_FILESYSTEM)
  2449. set(SDL_FILESYSTEM_OS2 1)
  2450. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/os2/*.c)
  2451. list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES})
  2452. set(HAVE_SDL_FILESYSTEM TRUE)
  2453. endif()
  2454. if(SDL_LOCALE)
  2455. file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/unix/*.c)
  2456. list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
  2457. set(HAVE_SDL_LOCALE TRUE)
  2458. endif()
  2459. if(SDL_VIDEO)
  2460. set(SDL_VIDEO_DRIVER_OS2 1)
  2461. file(GLOB OS2_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/os2/*.c)
  2462. list(APPEND SOURCE_FILES ${OS2_VIDEO_SOURCES})
  2463. set(HAVE_SDL_VIDEO TRUE)
  2464. endif()
  2465. if(SDL_AUDIO)
  2466. set(SDL_AUDIO_DRIVER_OS2 1)
  2467. file(GLOB OS2_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/os2/*.c)
  2468. list(APPEND SOURCE_FILES ${OS2_AUDIO_SOURCES})
  2469. set(HAVE_SDL_AUDIO TRUE)
  2470. list(APPEND EXTRA_LIBS mmpm2)
  2471. endif()
  2472. if(SDL_JOYSTICK)
  2473. set(SDL_JOYSTICK_OS2 1)
  2474. file(GLOB OS2_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/os2/*.c)
  2475. list(APPEND SOURCE_FILES ${OS2_JOYSTICK_SOURCES})
  2476. set(HAVE_SDL_JOYSTICK TRUE)
  2477. endif()
  2478. if(SDL_HIDAPI)
  2479. CheckHIDAPI()
  2480. endif()
  2481. elseif(N3DS)
  2482. file(GLOB N3DS_MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/n3ds/*.c)
  2483. set(SDLMAIN_SOURCES ${SDLMAIN_SOURCES} ${N3DS_MAIN_SOURCES})
  2484. if(SDL_AUDIO)
  2485. set(SDL_AUDIO_DRIVER_N3DS 1)
  2486. file(GLOB N3DS_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/n3ds/*.c)
  2487. list(APPEND SOURCE_FILES ${N3DS_AUDIO_SOURCES})
  2488. set(HAVE_SDL_AUDIO TRUE)
  2489. endif()
  2490. if(SDL_FILESYSTEM)
  2491. set(SDL_FILESYSTEM_N3DS 1)
  2492. file(GLOB N3DS_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/n3ds/*.c)
  2493. list(APPEND SOURCE_FILES ${N3DS_FILESYSTEM_SOURCES})
  2494. set(HAVE_SDL_FILESYSTEM TRUE)
  2495. endif()
  2496. if(SDL_JOYSTICK)
  2497. set(SDL_JOYSTICK_N3DS 1)
  2498. file(GLOB N3DS_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/n3ds/*.c)
  2499. list(APPEND SOURCE_FILES ${N3DS_JOYSTICK_SOURCES})
  2500. set(HAVE_SDL_JOYSTICK TRUE)
  2501. endif()
  2502. if(SDL_POWER)
  2503. set(SDL_POWER_N3DS 1)
  2504. file(GLOB N3DS_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/n3ds/*.c)
  2505. list(APPEND SOURCE_FILES ${N3DS_POWER_SOURCES})
  2506. set(HAVE_SDL_POWER TRUE)
  2507. endif()
  2508. if(SDL_THREADS)
  2509. set(SDL_THREAD_N3DS 1)
  2510. file(GLOB N3DS_THREAD_SOURCES ${SDL2_SOURCE_DIR}/src/thread/n3ds/*.c)
  2511. list(APPEND SOURCE_FILES ${N3DS_THREAD_SOURCES} ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_systls.c)
  2512. set(HAVE_SDL_THREADS TRUE)
  2513. endif()
  2514. if(SDL_TIMERS)
  2515. set(SDL_TIMER_N3DS 1)
  2516. file(GLOB N3DS_TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/n3ds/*.c)
  2517. list(APPEND SOURCE_FILES ${N3DS_TIMER_SOURCES})
  2518. set(HAVE_SDL_TIMERS TRUE)
  2519. endif()
  2520. if(SDL_SENSOR)
  2521. set(SDL_SENSOR_N3DS 1)
  2522. file(GLOB N3DS_SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/n3ds/*.c)
  2523. list(APPEND SOURCE_FILES ${N3DS_SENSOR_SOURCES})
  2524. set(HAVE_SDL_SENSORS TRUE)
  2525. endif()
  2526. if(SDL_VIDEO)
  2527. set(SDL_VIDEO_DRIVER_N3DS 1)
  2528. file(GLOB N3DS_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/n3ds/*.c)
  2529. list(APPEND SOURCE_FILES ${N3DS_VIDEO_SOURCES})
  2530. set(HAVE_SDL_VIDEO TRUE)
  2531. endif()
  2532. if(SDL_LOCALE)
  2533. file(GLOB N3DS_LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/n3ds/*.c)
  2534. list(APPEND SOURCE_FILES ${N3DS_LOCALE_SOURCES})
  2535. set(HAVE_SDL_LOCALE TRUE)
  2536. endif()
  2537. # Requires the n3ds file implementation
  2538. if(SDL_FILE)
  2539. file(GLOB N3DS_FILE_SOURCES ${SDL2_SOURCE_DIR}/src/file/n3ds/*.c)
  2540. list(APPEND SOURCE_FILES ${N3DS_FILE_SOURCES})
  2541. set(HAVE_SDL_FILE TRUE)
  2542. else()
  2543. message_error("SDL_FILE must be enabled to build on N3DS")
  2544. endif()
  2545. endif()
  2546. if(HAVE_VULKAN AND NOT SDL_LOADSO)
  2547. message(STATUS "Vulkan support is available, but disabled because there's no loadso.")
  2548. set(HAVE_VULKAN FALSE)
  2549. set(SDL_VIDEO_VULKAN 0)
  2550. endif()
  2551. # Platform-independent options
  2552. CheckLibSampleRate()
  2553. # Dummies
  2554. # configure.ac does it differently:
  2555. # if not have X
  2556. # if enable_X { SDL_X_DISABLED = 1 }
  2557. # [add dummy sources]
  2558. # so it always adds a dummy, without checking, if it was actually requested.
  2559. # This leads to missing internal references on building, since the
  2560. # src/X/*.c does not get included.
  2561. if(NOT HAVE_SDL_AUDIO)
  2562. set(SDL_AUDIO_DRIVER_DUMMY 1)
  2563. file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dummy/*.c)
  2564. list(APPEND SOURCE_FILES ${AUDIO_SOURCES})
  2565. endif()
  2566. if(NOT HAVE_SDL_VIDEO)
  2567. set(SDL_VIDEO_DRIVER_DUMMY 1)
  2568. file(GLOB VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/dummy/*.c)
  2569. list(APPEND SOURCE_FILES ${VIDEO_SOURCES})
  2570. endif()
  2571. if(NOT HAVE_SDL_JOYSTICK)
  2572. set(SDL_JOYSTICK_DUMMY 1)
  2573. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dummy/*.c)
  2574. list(APPEND SOURCE_FILES ${JOYSTICK_SOURCES})
  2575. endif()
  2576. if(NOT HAVE_SDL_HAPTIC)
  2577. set(SDL_HAPTIC_DUMMY 1)
  2578. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  2579. list(APPEND SOURCE_FILES ${HAPTIC_SOURCES})
  2580. endif()
  2581. if(NOT HAVE_SDL_SENSORS)
  2582. set(SDL_SENSOR_DUMMY 1)
  2583. file(GLOB SENSORS_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/dummy/*.c)
  2584. list(APPEND SOURCE_FILES ${SENSORS_SOURCES})
  2585. endif()
  2586. if(NOT HAVE_SDL_LOADSO)
  2587. set(SDL_LOADSO_DUMMY 1)
  2588. file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
  2589. list(APPEND SOURCE_FILES ${LOADSO_SOURCES})
  2590. endif()
  2591. if(NOT HAVE_SDL_FILESYSTEM)
  2592. set(SDL_FILESYSTEM_DUMMY 1)
  2593. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c)
  2594. list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES})
  2595. endif()
  2596. if(NOT HAVE_SDL_LOCALE)
  2597. set(SDL_LOCALE_DUMMY 1)
  2598. file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/dummy/*.c)
  2599. list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
  2600. endif()
  2601. if(NOT HAVE_SDL_MISC)
  2602. set(SDL_MISC_DUMMY 1)
  2603. file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/dummy/*.c)
  2604. list(APPEND SOURCE_FILES ${MISC_SOURCES})
  2605. endif()
  2606. # We always need to have threads and timers around
  2607. if(NOT HAVE_SDL_THREADS)
  2608. # The emscripten platform has been carefully vetted to work without threads
  2609. if (EMSCRIPTEN)
  2610. set(SDL_THREADS_DISABLED 1)
  2611. file(GLOB THREADS_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/*.c)
  2612. list(APPEND SOURCE_FILES ${THREADS_SOURCES})
  2613. else()
  2614. message_error("Threads are needed by many SDL subsystems and may not be disabled")
  2615. endif()
  2616. endif()
  2617. if(NOT HAVE_SDL_TIMERS)
  2618. set(SDL_TIMER_DUMMY 1)
  2619. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/dummy/*.c)
  2620. list(APPEND SOURCE_FILES ${TIMER_SOURCES})
  2621. endif()
  2622. if(NOT SDLMAIN_SOURCES)
  2623. file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/dummy/*.c)
  2624. endif()
  2625. if(SDL_WERROR)
  2626. if(MSVC)
  2627. cmake_push_check_state(RESET)
  2628. check_c_compiler_flag(/WX HAVE_WX)
  2629. if(HAVE_WX)
  2630. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
  2631. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
  2632. endif()
  2633. elseif(USE_GCC OR USE_CLANG)
  2634. cmake_push_check_state(RESET)
  2635. check_c_compiler_flag(-Werror HAVE_WERROR)
  2636. if(HAVE_WERROR)
  2637. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
  2638. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
  2639. set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} -Werror")
  2640. endif()
  2641. cmake_pop_check_state()
  2642. endif()
  2643. endif()
  2644. # Append the -MMD -MT flags
  2645. # if(DEPENDENCY_TRACKING)
  2646. # if(COMPILER_IS_GNUCC)
  2647. # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MMD -MT \$@")
  2648. # endif()
  2649. # endif()
  2650. # config variables may contain generator expression, so we need to generate SDL_config.h in 2 steps:
  2651. # 1. replace all `#cmakedefine`'s and `@abc@`
  2652. configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
  2653. "${SDL2_BINARY_DIR}/SDL_config.h.intermediate")
  2654. # 2. Create the "include-config-${CMAKE_BUILD_TYPE}" folder (fails on older CMake versions when it does not exist)
  2655. string(TOLOWER "${CMAKE_BUILD_TYPE}" lower_build_type)
  2656. execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/include-config-${lower_build_type}")
  2657. # 3. generate SDL_config in an build_type-dependent folder (which should be first in the include search path)
  2658. file(GENERATE
  2659. OUTPUT "${SDL2_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>/SDL_config.h"
  2660. INPUT "${SDL2_BINARY_DIR}/SDL_config.h.intermediate")
  2661. # Prepare the flags and remove duplicates
  2662. if(EXTRA_LDFLAGS)
  2663. list(REMOVE_DUPLICATES EXTRA_LDFLAGS)
  2664. endif()
  2665. if(EXTRA_LIBS)
  2666. list(REMOVE_DUPLICATES EXTRA_LIBS)
  2667. endif()
  2668. if(EXTRA_CFLAGS)
  2669. list(REMOVE_DUPLICATES EXTRA_CFLAGS)
  2670. endif()
  2671. listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
  2672. set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
  2673. # Compat helpers for the configuration files
  2674. if(EXISTS "${PROJECT_SOURCE_DIR}/VERSION.txt")
  2675. file(READ "${PROJECT_SOURCE_DIR}/VERSION.txt" SDL_SOURCE_VERSION)
  2676. string(STRIP "${SDL_SOURCE_VERSION}" SDL_SOURCE_VERSION)
  2677. endif()
  2678. find_package(Git)
  2679. if(Git_FOUND)
  2680. execute_process(COMMAND
  2681. "${GIT_EXECUTABLE}" describe --always --tags --long
  2682. WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
  2683. RESULT_VARIABLE GIT_REVISION_STATUS
  2684. OUTPUT_VARIABLE GIT_REVISION
  2685. ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  2686. else()
  2687. set(GIT_REVISION_STATUS 1)
  2688. set(GIT_REVISION "")
  2689. endif()
  2690. if(SDL_SOURCE_VERSION)
  2691. set(SDL_REVISION "SDL-${SDL_SOURCE_VERSION}")
  2692. elseif(GIT_REVISION_STATUS EQUAL 0)
  2693. if(GIT_REVISION MATCHES "^[0-9a-f]+$")
  2694. # Just a truncated sha1, so prefix it with the version number
  2695. set(SDL_REVISION "SDL-${SDL_VERSION}-g${GIT_REVISION}")
  2696. else()
  2697. # e.g. release-2.24.0-542-g96361fc47
  2698. set(SDL_REVISION "SDL-${GIT_REVISION}")
  2699. endif()
  2700. else()
  2701. set(SDL_REVISION "SDL-${SDL_VERSION}-no-vcs")
  2702. endif()
  2703. configure_file("${SDL2_SOURCE_DIR}/include/SDL_revision.h.cmake"
  2704. "${SDL2_BINARY_DIR}/include/SDL_revision.h")
  2705. # Copy all non-generated headers to "${SDL2_BINARY_DIR}/include"
  2706. # This is done to avoid the inclusion of a pre-generated SDL_config.h
  2707. file(GLOB SDL2_INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/*.h)
  2708. set(SDL2_COPIED_INCLUDE_FILES)
  2709. foreach(_hdr IN LISTS SDL2_INCLUDE_FILES)
  2710. if(_hdr MATCHES ".*(SDL_config|SDL_revision).*")
  2711. list(REMOVE_ITEM SDL2_INCLUDE_FILES "${_hdr}")
  2712. else()
  2713. get_filename_component(_name "${_hdr}" NAME)
  2714. set(_bin_hdr "${SDL2_BINARY_DIR}/include/${_name}")
  2715. list(APPEND SDL2_COPIED_INCLUDE_FILES "${_bin_hdr}")
  2716. add_custom_command(OUTPUT "${_bin_hdr}"
  2717. COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_hdr}" "${_bin_hdr}"
  2718. DEPENDS "${_hdr}")
  2719. endif()
  2720. endforeach()
  2721. list(APPEND SDL_GENERATED_HEADERS ${SDL2_COPIED_INCLUDE_FILES})
  2722. if(CMAKE_STATIC_LIBRARY_PREFIX STREQUAL "" AND CMAKE_STATIC_LIBRARY_SUFFIX STREQUAL ".lib")
  2723. # Avoid conflict between the dll import library and the static library
  2724. set(sdl_static_libname "SDL2-static")
  2725. else()
  2726. set(sdl_static_libname "SDL2")
  2727. endif()
  2728. set(prefix ${CMAKE_INSTALL_PREFIX})
  2729. file(RELATIVE_PATH bin_prefix_relpath "${CMAKE_INSTALL_FULL_BINDIR}" "${CMAKE_INSTALL_PREFIX}")
  2730. set(exec_prefix "\${prefix}")
  2731. set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
  2732. set(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
  2733. set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
  2734. if(SDL_STATIC)
  2735. set(ENABLE_STATIC_TRUE "")
  2736. set(ENABLE_STATIC_FALSE "#")
  2737. else()
  2738. set(ENABLE_STATIC_TRUE "#")
  2739. set(ENABLE_STATIC_FALSE "")
  2740. endif()
  2741. if(SDL_SHARED)
  2742. set(PKGCONFIG_LIBS_PRIV "
  2743. Libs.private:")
  2744. set(ENABLE_SHARED_TRUE "")
  2745. set(ENABLE_SHARED_FALSE "#")
  2746. else()
  2747. set(PKGCONFIG_LIBS_PRIV "")
  2748. set(ENABLE_SHARED_TRUE "#")
  2749. set(ENABLE_SHARED_FALSE "")
  2750. endif()
  2751. # Clean up the different lists
  2752. listtostr(EXTRA_LIBS _EXTRA_LIBS "-l")
  2753. set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
  2754. list(REMOVE_DUPLICATES SDL_STATIC_LIBS)
  2755. listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS)
  2756. set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS})
  2757. listtostr(SDL_LIBS _SDL_LIBS)
  2758. set(SDL_LIBS ${_SDL_LIBS})
  2759. listtostr(SDL_CFLAGS _SDL_CFLAGS "")
  2760. set(SDL_CFLAGS ${_SDL_CFLAGS})
  2761. string(REGEX REPLACE "-lSDL2( |$)" "-l${sdl_static_libname} " SDL_STATIC_LIBS "${SDL_STATIC_LIBS}")
  2762. if(NOT SDL_SHARED)
  2763. string(REGEX REPLACE "-lSDL2( |$)" "-l${sdl_static_libname} " SDL_LIBS "${SDL_LIBS}")
  2764. endif()
  2765. if(SDL_STATIC AND SDL_SHARED AND NOT sdl_static_libname STREQUAL "SDL2")
  2766. message(STATUS "\"pkg-config --static --libs sdl2\" will return invalid information")
  2767. endif()
  2768. # MESSAGE(STATUS "SDL_LIBS: ${SDL_LIBS}")
  2769. # MESSAGE(STATUS "SDL_STATIC_LIBS: ${SDL_STATIC_LIBS}")
  2770. configure_file("${SDL2_SOURCE_DIR}/sdl2.pc.in"
  2771. "${SDL2_BINARY_DIR}/sdl2.pc" @ONLY)
  2772. configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  2773. "${SDL2_BINARY_DIR}/sdl2-config" @ONLY)
  2774. configure_file("${SDL2_SOURCE_DIR}/SDL2.spec.in"
  2775. "${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
  2776. macro(check_add_debug_flag FLAG SUFFIX)
  2777. check_c_compiler_flag(${FLAG} HAS_C_FLAG_${SUFFIX})
  2778. if (HAS_C_FLAG_${SUFFIX})
  2779. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
  2780. endif()
  2781. check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX})
  2782. if (HAS_CXX_${SUFFIX})
  2783. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
  2784. endif()
  2785. endmacro()
  2786. macro(asan_check_add_debug_flag ASAN_FLAG)
  2787. check_add_debug_flag("-fsanitize=${ASAN_FLAG}" "${ASAN_FLAG}")
  2788. if(HAS_C_${ASAN_FLAG} OR HAS_CXX_${ASAN_FLAG})
  2789. set(HAVE_ASAN ON)
  2790. endif()
  2791. endmacro()
  2792. macro(asan_check_add_debug_flag2 ASAN_FLAG)
  2793. # for some sanitize flags we have to manipulate the CMAKE_REQUIRED_LIBRARIES:
  2794. # http://cmake.3232098.n2.nabble.com/CHECK-CXX-COMPILER-FLAG-doesn-t-give-correct-result-for-fsanitize-address-tp7600216p7600217.html
  2795. set(FLAG "-fsanitize=${ASAN_FLAG}")
  2796. set (STORED_REQLIBS ${CMAKE_REQUIRED_LIBRARIES})
  2797. set (CMAKE_REQUIRED_LIBRARIES "${FLAG};asan")
  2798. check_c_compiler_flag (${FLAG} HAS_C_FLAG_${ASAN_FLAG})
  2799. check_cxx_compiler_flag (${FLAG} HAS_CXX_FLAG_${ASAN_FLAG})
  2800. set (CMAKE_REQUIRED_LIBRARIES ${STORED_REQLIBS})
  2801. if (HAS_C_FLAG_${ASAN_FLAG})
  2802. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
  2803. endif()
  2804. if (HAS_CXX_${ASAN_FLAG})
  2805. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
  2806. endif()
  2807. if(HAS_C_${ASAN_FLAG} OR HAS_CXX_${ASAN_FLAG})
  2808. set(HAVE_ASAN ON)
  2809. endif()
  2810. endmacro()
  2811. # enable AddressSanitizer if supported
  2812. if (SDL_ASAN)
  2813. asan_check_add_debug_flag2("address")
  2814. asan_check_add_debug_flag("bool")
  2815. asan_check_add_debug_flag("bounds")
  2816. asan_check_add_debug_flag("enum")
  2817. asan_check_add_debug_flag("float-cast-overflow")
  2818. asan_check_add_debug_flag("float-divide-by-zero")
  2819. asan_check_add_debug_flag("nonnull-attribute")
  2820. asan_check_add_debug_flag("returns-nonnull-attribute")
  2821. asan_check_add_debug_flag("signed-integer-overflow")
  2822. asan_check_add_debug_flag("undefined")
  2823. asan_check_add_debug_flag("vla-bound")
  2824. asan_check_add_debug_flag("leak")
  2825. # The object size sanitizer has no effect on unoptimized builds on Clang,
  2826. # but causes warnings.
  2827. if((NOT USE_CLANG) OR ("${CMAKE_BUILD_TYPE}" STREQUAL ""))
  2828. asan_check_add_debug_flag("object-size")
  2829. endif()
  2830. endif()
  2831. if(SDL_CCACHE)
  2832. cmake_minimum_required(VERSION 3.4)
  2833. find_program(CCACHE_BINARY ccache)
  2834. if(CCACHE_BINARY)
  2835. set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_BINARY})
  2836. set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_BINARY})
  2837. set(CMAKE_OBJC_COMPILER_LAUNCHER ${CCACHE_BINARY})
  2838. set(HAVE_CCACHE ON)
  2839. else()
  2840. set(HAVE_CCACHE OFF)
  2841. endif()
  2842. endif()
  2843. if(SDL_TESTS)
  2844. set(HAVE_TESTS ON)
  2845. endif()
  2846. # Create target that collects all all generated include files.
  2847. add_custom_target(sdl_headers_copy
  2848. DEPENDS ${SDL_GENERATED_HEADERS})
  2849. ##### Info output #####
  2850. message(STATUS "")
  2851. message(STATUS "SDL2 was configured with the following options:")
  2852. message(STATUS "")
  2853. message(STATUS "Platform: ${CMAKE_SYSTEM}")
  2854. message(STATUS "64-bit: ${ARCH_64}")
  2855. message(STATUS "Compiler: ${CMAKE_C_COMPILER}")
  2856. message(STATUS "Revision: ${SDL_REVISION}")
  2857. message(STATUS "")
  2858. message(STATUS "Subsystems:")
  2859. foreach(_SUB ${SDL_SUBSYSTEMS})
  2860. string(TOUPPER ${_SUB} _OPT)
  2861. message_bool_option(${_SUB} SDL_${_OPT})
  2862. endforeach()
  2863. message(STATUS "")
  2864. message(STATUS "Options:")
  2865. list(SORT ALLOPTIONS)
  2866. foreach(_OPT ${ALLOPTIONS})
  2867. # Get the padding
  2868. string(LENGTH ${_OPT} _OPTLEN)
  2869. math(EXPR _PADLEN "(${LONGESTOPTIONNAME} + 1) - ${_OPTLEN}")
  2870. string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
  2871. message_tested_option(${_OPT} ${_PADDING})
  2872. endforeach()
  2873. if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  2874. message(STATUS "")
  2875. message(STATUS " CMAKE_C_FLAGS_DEBUG: ${CMAKE_C_FLAGS_DEBUG}")
  2876. message(STATUS " CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
  2877. endif()
  2878. message(STATUS "")
  2879. message(STATUS " CFLAGS: ${CMAKE_C_FLAGS}")
  2880. message(STATUS " EXTRA_CFLAGS: ${EXTRA_CFLAGS}")
  2881. message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS} ${EXTRA_LDFLAGS_BUILD}")
  2882. message(STATUS " EXTRA_LIBS: ${EXTRA_LIBS}")
  2883. message(STATUS "")
  2884. message(STATUS " Build Shared Library: ${SDL_SHARED}")
  2885. message(STATUS " Build Static Library: ${SDL_STATIC}")
  2886. if(SDL_STATIC)
  2887. message(STATUS " Build Static Library with Position Independent Code: ${SDL_STATIC_PIC}")
  2888. endif()
  2889. message(STATUS "")
  2890. if(UNIX)
  2891. message(STATUS "If something was not detected, although the libraries")
  2892. message(STATUS "were installed, then make sure you have set the")
  2893. message(STATUS "CFLAGS and LDFLAGS environment variables correctly.")
  2894. message(STATUS "")
  2895. endif()
  2896. if(WARN_ABOUT_ARM_SIMD_ASM_MIT)
  2897. message(STATUS "")
  2898. message(STATUS "SDL is being built with ARM SIMD optimizations, which")
  2899. message(STATUS "uses code licensed under the MIT license. If this is a")
  2900. message(STATUS "problem, please disable that code by rerunning CMake with:")
  2901. message(STATUS "")
  2902. message(STATUS " -DSDL_ARMSIMD=OFF")
  2903. endif()
  2904. if(WARN_ABOUT_ARM_NEON_ASM_MIT)
  2905. message(STATUS "")
  2906. message(STATUS "SDL is being built with ARM NEON optimizations, which")
  2907. message(STATUS "uses code licensed under the MIT license. If this is a")
  2908. message(STATUS "problem, please disable that code by rerunning CMake with:")
  2909. message(STATUS "")
  2910. message(STATUS " -DSDL_ARMNEON=OFF")
  2911. endif()
  2912. # Ensure that the extra cflags are used at compile time
  2913. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${EXTRA_CFLAGS_BUILD}")
  2914. if(NOT WINDOWS_STORE AND NOT SDL2_DISABLE_SDL2MAIN)
  2915. # Build SDLmain
  2916. add_library(SDL2main STATIC ${SDLMAIN_SOURCES})
  2917. add_dependencies(SDL2main sdl_headers_copy)
  2918. # alias target for in-tree builds
  2919. add_library(SDL2::SDL2main ALIAS SDL2main)
  2920. target_include_directories(SDL2main BEFORE PRIVATE "${SDL2_BINARY_DIR}/include" PRIVATE "${SDL2_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>")
  2921. target_include_directories(SDL2main PUBLIC "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include>" $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>)
  2922. if (WIN32)
  2923. target_link_libraries(SDL2main PRIVATE shell32)
  2924. endif()
  2925. if(MINGW OR CYGWIN)
  2926. if(CMAKE_SIZEOF_VOID_P EQUAL 4)
  2927. target_link_libraries(SDL2main PUBLIC "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:-Wl,--undefined=_WinMain@16>")
  2928. else()
  2929. target_link_libraries(SDL2main PUBLIC "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:-Wl,--undefined=WinMain>")
  2930. endif()
  2931. endif()
  2932. if (NOT ANDROID)
  2933. set_target_properties(SDL2main PROPERTIES DEBUG_POSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
  2934. endif()
  2935. endif()
  2936. if(ANDROID)
  2937. target_include_directories(sdl-build-options INTERFACE "${ANDROID_NDK}/sources/android/cpufeatures")
  2938. endif()
  2939. if(APPLE)
  2940. target_compile_options(sdl-build-options INTERFACE "-fobjc-arc")
  2941. endif()
  2942. if(PS2)
  2943. target_compile_options(sdl-build-options INTERFACE "-Wno-error=declaration-after-statement")
  2944. endif()
  2945. if(APPLE)
  2946. foreach(SOURCE_FILE ${SOURCE_FILES})
  2947. get_filename_component(FILE_EXTENSION ${SOURCE_FILE} EXT)
  2948. if(FILE_EXTENSION STREQUAL "m")
  2949. set_property(SOURCE ${SOURCE_FILE} APPEND_STRING PROPERTY COMPILE_FLAGS " -x objective-c")
  2950. endif()
  2951. endforeach()
  2952. endif()
  2953. if(SDL_SHARED)
  2954. add_library(SDL2 SHARED ${SOURCE_FILES} ${VERSION_SOURCES})
  2955. add_dependencies(SDL2 sdl_headers_copy)
  2956. # alias target for in-tree builds
  2957. add_library(SDL2::SDL2 ALIAS SDL2)
  2958. set_target_properties(SDL2 PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
  2959. if(NOT SDL_LIBC)
  2960. check_cpu_architecture(x86 HAS_X86)
  2961. if(HAS_X86)
  2962. # FIXME: should be added for all architectures (missing symbols for ARM)
  2963. target_link_libraries(SDL2 PRIVATE "-nodefaultlib:MSVCRT")
  2964. endif()
  2965. endif()
  2966. if(APPLE)
  2967. # FIXME: Remove SOVERSION in SDL3
  2968. set_target_properties(SDL2 PROPERTIES
  2969. MACOSX_RPATH 1
  2970. SOVERSION 0
  2971. OUTPUT_NAME "SDL2-${LT_RELEASE}")
  2972. elseif(UNIX AND NOT ANDROID)
  2973. set_target_properties(SDL2 PROPERTIES
  2974. VERSION ${LT_VERSION}
  2975. SOVERSION ${LT_MAJOR}
  2976. OUTPUT_NAME "SDL2-${LT_RELEASE}")
  2977. else()
  2978. if(WINDOWS OR CYGWIN)
  2979. set_target_properties(SDL2 PROPERTIES
  2980. DEFINE_SYMBOL DLL_EXPORT)
  2981. elseif(OS2)
  2982. set_target_properties(SDL2 PROPERTIES
  2983. DEFINE_SYMBOL BUILD_SDL)
  2984. endif()
  2985. set_target_properties(SDL2 PROPERTIES
  2986. VERSION ${SDL_VERSION}
  2987. SOVERSION ${LT_REVISION}
  2988. OUTPUT_NAME "SDL2")
  2989. endif()
  2990. # Note: The clang toolset for Visual Studio does not support /NODEFAULTLIB.
  2991. if(MSVC AND NOT SDL_LIBC AND NOT MSVC_CLANG AND NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM")
  2992. # Don't try to link with the default set of libraries.
  2993. if(NOT WINDOWS_STORE)
  2994. set_target_properties(SDL2 PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
  2995. set_target_properties(SDL2 PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
  2996. endif()
  2997. set_target_properties(SDL2 PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
  2998. endif()
  2999. # FIXME: if CMAKE_VERSION >= 3.13, use target_link_options for EXTRA_LDFLAGS
  3000. target_link_libraries(SDL2 PRIVATE ${EXTRA_LIBS} ${EXTRA_LDFLAGS} ${EXTRA_LDFLAGS_BUILD})
  3001. target_include_directories(SDL2 PUBLIC
  3002. "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include>"
  3003. "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>>"
  3004. "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
  3005. "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>")
  3006. # This picks up all the compiler options and such we've accumulated up to here.
  3007. target_link_libraries(SDL2 PRIVATE $<BUILD_INTERFACE:sdl-build-options>)
  3008. if(MINGW OR CYGWIN)
  3009. if(NOT CMAKE_VERSION VERSION_LESS "3.13")
  3010. target_link_options(SDL2 PRIVATE -static-libgcc)
  3011. endif()
  3012. endif()
  3013. if(NOT ANDROID)
  3014. set_target_properties(SDL2 PROPERTIES DEBUG_POSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
  3015. endif()
  3016. # Use `Compatible Interface Properties` to allow consumers to enforce a shared/static library
  3017. set_property(TARGET SDL2 PROPERTY INTERFACE_SDL2_SHARED TRUE)
  3018. set_property(TARGET SDL2 APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SDL2_SHARED)
  3019. endif()
  3020. if(SDL_STATIC)
  3021. add_library(SDL2-static STATIC ${SOURCE_FILES})
  3022. add_dependencies(SDL2-static sdl_headers_copy)
  3023. # alias target for in-tree builds
  3024. add_library(SDL2::SDL2-static ALIAS SDL2-static)
  3025. set_target_properties(SDL2-static PROPERTIES
  3026. OUTPUT_NAME "${sdl_static_libname}"
  3027. POSITION_INDEPENDENT_CODE "${SDL_STATIC_PIC}")
  3028. target_compile_definitions(SDL2-static PRIVATE SDL_STATIC_LIB)
  3029. # TODO: Win32 platforms keep the same suffix .lib for import and static
  3030. # libraries - do we need to consider this?
  3031. target_link_libraries(SDL2-static PRIVATE ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  3032. target_include_directories(SDL2-static PUBLIC
  3033. "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include>"
  3034. "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>>"
  3035. "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
  3036. "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>")
  3037. # This picks up all the compiler options and such we've accumulated up to here.
  3038. target_link_libraries(SDL2-static PRIVATE $<BUILD_INTERFACE:sdl-build-options>)
  3039. if(NOT ANDROID)
  3040. set_target_properties(SDL2-static PROPERTIES DEBUG_POSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
  3041. endif()
  3042. # Use `Compatible Interface Properties` to allow consumers to enforce a shared/static library
  3043. set_property(TARGET SDL2-static PROPERTY INTERFACE_SDL2_SHARED FALSE)
  3044. set_property(TARGET SDL2-static APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SDL2_SHARED)
  3045. endif()
  3046. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDL_BUILD_MAJOR_VERSION=${SDL_MAJOR_VERSION}")
  3047. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDL_BUILD_MINOR_VERSION=${SDL_MINOR_VERSION}")
  3048. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDL_BUILD_MICRO_VERSION=${SDL_MICRO_VERSION}")
  3049. ##### Tests #####
  3050. if(SDL_TEST)
  3051. file(GLOB TEST_SOURCES ${SDL2_SOURCE_DIR}/src/test/*.c)
  3052. add_library(SDL2_test STATIC ${TEST_SOURCES})
  3053. add_dependencies(SDL2_test sdl_headers_copy)
  3054. add_library(SDL2::SDL2test ALIAS SDL2_test)
  3055. set_target_properties(SDL2_test PROPERTIES
  3056. EXPORT_NAME SDL2test)
  3057. target_include_directories(SDL2_test PUBLIC
  3058. "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include>"
  3059. "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>>"
  3060. "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
  3061. "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>")
  3062. target_link_libraries(SDL2_test PRIVATE ${EXTRA_TEST_LIBS})
  3063. endif()
  3064. ##### Installation targets #####
  3065. if(NOT SDL2_DISABLE_INSTALL)
  3066. if(SDL_SHARED)
  3067. install(TARGETS SDL2 EXPORT SDL2Targets
  3068. LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  3069. ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  3070. RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
  3071. endif()
  3072. if(NOT WINDOWS_STORE AND NOT SDL2_DISABLE_SDL2MAIN)
  3073. install(TARGETS SDL2main EXPORT SDL2mainTargets
  3074. LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  3075. ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  3076. RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
  3077. endif()
  3078. if(SDL_STATIC)
  3079. install(TARGETS SDL2-static EXPORT SDL2staticTargets
  3080. LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  3081. ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  3082. RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
  3083. endif()
  3084. if(SDL_TEST)
  3085. install(TARGETS SDL2_test EXPORT SDL2testTargets
  3086. LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  3087. ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  3088. RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
  3089. endif()
  3090. ##### Export files #####
  3091. if (WINDOWS AND NOT MINGW)
  3092. set(SDL_INSTALL_CMAKEDIR_DEFAULT "cmake")
  3093. set(LICENSES_PREFIX "licenses/SDL2")
  3094. else ()
  3095. set(SDL_INSTALL_CMAKEDIR_DEFAULT "${CMAKE_INSTALL_LIBDIR}/cmake/SDL2")
  3096. set(LICENSES_PREFIX "${CMAKE_INSTALL_DATAROOTDIR}/licenses/${PROJECT_NAME}")
  3097. endif ()
  3098. set(SDL_INSTALL_CMAKEDIR "${SDL_INSTALL_CMAKEDIR_DEFAULT}" CACHE STRING "Location where to install SDL2Config.cmake")
  3099. include(CMakePackageConfigHelpers)
  3100. configure_package_config_file(SDL2Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/SDL2Config.cmake"
  3101. PATH_VARS CMAKE_INSTALL_PREFIX CMAKE_INSTALL_FULL_BINDIR CMAKE_INSTALL_FULL_INCLUDEDIR CMAKE_INSTALL_FULL_LIBDIR
  3102. INSTALL_DESTINATION "${SDL_INSTALL_CMAKEDIR}"
  3103. )
  3104. write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/SDL2ConfigVersion.cmake"
  3105. VERSION ${SDL_VERSION}
  3106. COMPATIBILITY AnyNewerVersion
  3107. )
  3108. if(SDL_SHARED)
  3109. install(EXPORT SDL2Targets
  3110. FILE SDL2Targets.cmake
  3111. NAMESPACE SDL2::
  3112. DESTINATION "${SDL_INSTALL_CMAKEDIR}"
  3113. )
  3114. if(ANDROID AND NOT CMAKE_VERSION VERSION_LESS 3.7)
  3115. install(EXPORT_ANDROID_MK SDL2Targets
  3116. DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/ndk-modules/SDL2")
  3117. endif()
  3118. endif()
  3119. if(NOT WINDOWS_STORE AND NOT SDL2_DISABLE_SDL2MAIN)
  3120. install(EXPORT SDL2mainTargets
  3121. FILE SDL2mainTargets.cmake
  3122. NAMESPACE SDL2::
  3123. DESTINATION "${SDL_INSTALL_CMAKEDIR}"
  3124. )
  3125. if(ANDROID AND NOT CMAKE_VERSION VERSION_LESS 3.7)
  3126. install(EXPORT_ANDROID_MK SDL2mainTargets
  3127. DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/ndk-modules/SDL2main")
  3128. endif()
  3129. endif()
  3130. if(SDL_STATIC)
  3131. install(EXPORT SDL2staticTargets
  3132. FILE SDL2staticTargets.cmake
  3133. NAMESPACE SDL2::
  3134. DESTINATION "${SDL_INSTALL_CMAKEDIR}"
  3135. )
  3136. if(ANDROID AND NOT CMAKE_VERSION VERSION_LESS 3.7)
  3137. install(EXPORT_ANDROID_MK SDL2staticTargets
  3138. DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/ndk-modules/SDL2-static")
  3139. endif()
  3140. endif()
  3141. if(SDL_TEST)
  3142. install(EXPORT SDL2testTargets
  3143. FILE SDL2testTargets.cmake
  3144. NAMESPACE SDL2::
  3145. DESTINATION "${SDL_INSTALL_CMAKEDIR}"
  3146. )
  3147. if(ANDROID AND NOT CMAKE_VERSION VERSION_LESS 3.7)
  3148. install(EXPORT_ANDROID_MK SDL2testTargets
  3149. DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/ndk-modules/SDL2test")
  3150. endif()
  3151. endif()
  3152. install(
  3153. FILES
  3154. ${CMAKE_CURRENT_BINARY_DIR}/SDL2Config.cmake
  3155. ${CMAKE_CURRENT_BINARY_DIR}/SDL2ConfigVersion.cmake
  3156. DESTINATION "${SDL_INSTALL_CMAKEDIR}"
  3157. COMPONENT Devel
  3158. )
  3159. install(
  3160. FILES
  3161. ${SDL2_INCLUDE_FILES}
  3162. "${SDL2_BINARY_DIR}/include/SDL_revision.h"
  3163. "${SDL2_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>/SDL_config.h"
  3164. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SDL2)
  3165. string(TOUPPER "${CMAKE_BUILD_TYPE}" UPPER_BUILD_TYPE)
  3166. if (UPPER_BUILD_TYPE MATCHES DEBUG)
  3167. set(SOPOSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
  3168. else()
  3169. set(SOPOSTFIX "")
  3170. endif()
  3171. install(FILES "LICENSE.txt" DESTINATION "${LICENSES_PREFIX}")
  3172. if(FREEBSD)
  3173. # FreeBSD uses ${PREFIX}/libdata/pkgconfig
  3174. install(FILES ${SDL2_BINARY_DIR}/sdl2.pc DESTINATION "libdata/pkgconfig")
  3175. else()
  3176. install(FILES ${SDL2_BINARY_DIR}/sdl2.pc
  3177. DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
  3178. endif()
  3179. if(NOT (WINDOWS OR CYGWIN) OR MINGW)
  3180. if(SDL_SHARED)
  3181. set(SOEXT ${CMAKE_SHARED_LIBRARY_SUFFIX}) # ".so", ".dylib", etc.
  3182. get_target_property(SONAME SDL2 OUTPUT_NAME)
  3183. if(NOT ANDROID AND NOT MINGW AND NOT OS2)
  3184. install(CODE "
  3185. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
  3186. \"lib${SONAME}${SOPOSTFIX}${SOEXT}\" \"libSDL2${SOPOSTFIX}${SOEXT}\"
  3187. WORKING_DIRECTORY \"${SDL2_BINARY_DIR}\")")
  3188. install(FILES ${SDL2_BINARY_DIR}/libSDL2${SOPOSTFIX}${SOEXT} DESTINATION "${CMAKE_INSTALL_LIBDIR}")
  3189. endif()
  3190. endif()
  3191. install(PROGRAMS ${SDL2_BINARY_DIR}/sdl2-config DESTINATION "${CMAKE_INSTALL_BINDIR}")
  3192. # TODO: what about the .spec file? Is it only needed for RPM creation?
  3193. install(FILES "${SDL2_SOURCE_DIR}/sdl2.m4" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/aclocal")
  3194. endif()
  3195. endif()
  3196. ##### Uninstall target #####
  3197. if(NOT SDL2_DISABLE_UNINSTALL)
  3198. if(NOT TARGET uninstall)
  3199. configure_file(
  3200. "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  3201. "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  3202. IMMEDIATE @ONLY)
  3203. add_custom_target(uninstall
  3204. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
  3205. endif()
  3206. endif()
  3207. ##### Tests subproject (must appear after the install/uninstall targets) #####
  3208. if(SDL_TESTS)
  3209. set(HAVE_TESTS ON)
  3210. enable_testing()
  3211. add_subdirectory(test)
  3212. endif()
  3213. ##### Fix Objective C builds #####
  3214. set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} ${CMAKE_C_FLAGS}")
  3215. # Make sure SDL2::SDL2 always exists
  3216. if(TARGET SDL2::SDL2-static AND NOT TARGET SDL2::SDL2)
  3217. add_library(SDL2::SDL2 ALIAS SDL2-static)
  3218. endif()