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

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