CMakeLists.txt 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596
  1. #
  2. # Simple DirectMedia Layer
  3. # Copyright (C) 1997-2016 Sam Lantinga <[email protected]>
  4. #
  5. # This software is provided 'as-is', without any express or implied
  6. # warranty. In no event will the authors be held liable for any damages
  7. # arising from the use of this software.
  8. #
  9. # Permission is granted to anyone to use this software for any purpose,
  10. # including commercial applications, and to alter it and redistribute it
  11. # freely, subject to the following restrictions:
  12. #
  13. # 1. The origin of this software must not be misrepresented; you must not
  14. # claim that you wrote the original software. If you use this software
  15. # in a product, an acknowledgment in the product documentation would be
  16. # appreciated but is not required.
  17. # 2. Altered source versions must be plainly marked as such, and must not be
  18. # misrepresented as being the original software.
  19. # 3. This notice may not be removed or altered from any source distribution.
  20. #
  21. # Modified for Urho3D, the modified portion is licensed under below license
  22. # Copyright (c) 2008-2023 the Urho3D project
  23. # License: MIT
  24. # Urho3D: This hack allows build 32-bit version on Linux Mint x64
  25. # TODO: Why is it not being detected correctly?
  26. if (CMAKE_LIBRARY_ARCHITECTURE STREQUAL "x86_64-linux-gnu" AND NOT URHO3D_64BIT)
  27. set (CMAKE_LIBRARY_ARCHITECTURE "i386-linux-gnu")
  28. endif ()
  29. # Urho3D - commented out in-source tree build prevention as Urho3D supports both out-of-source and in-source tree builds
  30. # Urho3D - commented out setting SDL2 as project name as we want SDL sub-library to remain within Urho3D "umbrella" project
  31. # instead, just enable the required language support and set the extra variables associated with project() command
  32. enable_language (C CXX)
  33. set (SDL2_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  34. set (SDL2_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
  35. # Urho3D - commented out CheckTypeSize, FindPkgConfig, and GNUInstallDirs modules as the corresponding macros are not being used in our modified version
  36. include(CheckFunctionExists)
  37. include(CheckLibraryExists)
  38. include(CheckIncludeFiles)
  39. include(CheckIncludeFile)
  40. include(CheckSymbolExists)
  41. include(CheckCSourceCompiles)
  42. include(CheckCSourceRuns)
  43. include(CheckCCompilerFlag)
  44. include(CheckStructHasMember)
  45. include(CMakeDependentOption)
  46. # Urho3D - commented out CMAKE_MODULE_PATH configuration so that it does not mess up with ours; besides below two include() use file signature instead of module signature
  47. include(${SDL2_SOURCE_DIR}/cmake/macros.cmake)
  48. include(${SDL2_SOURCE_DIR}/cmake/sdlchecks.cmake)
  49. # General settings
  50. # Edit include/SDL_version.h and change the version, then:
  51. # SDL_MICRO_VERSION += 1;
  52. # SDL_INTERFACE_AGE += 1;
  53. # SDL_BINARY_AGE += 1;
  54. # if any functions have been added, set SDL_INTERFACE_AGE to 0.
  55. # if backwards compatibility has been broken,
  56. # set SDL_BINARY_AGE and SDL_INTERFACE_AGE to 0.
  57. set(SDL_MAJOR_VERSION 2)
  58. set(SDL_MINOR_VERSION 0)
  59. set(SDL_MICRO_VERSION 10)
  60. set(SDL_INTERFACE_AGE 0)
  61. set(SDL_BINARY_AGE 10)
  62. set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}")
  63. # Urho3D - commented out DYLIB's current_version and compatibility_version variables as we always build SDL as STATIC
  64. # Urho3D - commented out SDL_CMAKE_DEBUG_POSTFIX configuration as our build system does not not expose SDL as a library
  65. # Calculate a libtool-like version number
  66. math(EXPR LT_CURRENT "${SDL_MICRO_VERSION} - ${SDL_INTERFACE_AGE}")
  67. math(EXPR LT_AGE "${SDL_BINARY_AGE} - ${SDL_INTERFACE_AGE}")
  68. math(EXPR LT_MAJOR "${LT_CURRENT}- ${LT_AGE}")
  69. set(LT_REVISION "${SDL_INTERFACE_AGE}")
  70. set(LT_RELEASE "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}")
  71. set(LT_VERSION "${LT_MAJOR}.${LT_AGE}.${LT_REVISION}")
  72. #message(STATUS "${LT_VERSION} :: ${LT_AGE} :: ${LT_REVISION} :: ${LT_CURRENT} :: ${LT_RELEASE}")
  73. # General settings & flags
  74. # Urho3D - commented out LIBRARY_OUTPUT_DIRECTORY configuration so that it does not mess up with our global configuration setup
  75. # Check for 64 or 32 bit
  76. # Urho3D - bug fix - using CMAKE_SIZEOF_VOID_P is not accurate in a situation where a multilib-capable compiler is chosen and user has opted to use non-native ABI; instead using URHO3D_64BIT build option as it also captures the user intention
  77. if(URHO3D_64BIT)
  78. set(ARCH_64 TRUE)
  79. set(PROCESSOR_ARCH "x64")
  80. else()
  81. set(ARCH_64 FALSE)
  82. set(PROCESSOR_ARCH "x86")
  83. endif()
  84. # Urho3D - commented out redundant CMake variables that do not appear to be used anywhere
  85. # Get the platform
  86. # Urho3D - rearrange the if-elseif blocks (specific case before generic case), simplify the regex, and remove unused variables
  87. if (WIN32)
  88. set(WINDOWS TRUE)
  89. elseif (HAIKU OR ANDROID OR IOS OR TVOS) # IOS/TVOS CMake variables are defined in Urho3D when targeting iOS/tvOS platforms, respectively
  90. # Do nothing here but this should prevent these platforms from entering the more generic case below, i.e.
  91. # - preventing LINUX variable being set for Android (when using older CMake)
  92. # - preventing DARWIN/MACOSX variable being set for iOS
  93. # - preventing UNIX_SYS variable being set for Haiku
  94. elseif (APPLE)
  95. if (CMAKE_SYSTEM_NAME MATCHES Darwin)
  96. set (DARWIN TRUE)
  97. elseif (CMAKE_SYSTEM_NAME MATCHES MacOS)
  98. set (MACOSX TRUE)
  99. endif ()
  100. elseif (UNIX)
  101. set (UNIX_SYS TRUE)
  102. if (CMAKE_SYSTEM_NAME MATCHES Linux)
  103. set (LINUX TRUE)
  104. elseif (CMAKE_SYSTEM_NAME MATCHES FreeBSD|DragonFly)
  105. set (FREEBSD TRUE)
  106. elseif (CMAKE_SYSTEM_NAME MATCHES NetBSD)
  107. set (NETBSD TRUE)
  108. elseif (CMAKE_SYSTEM_NAME MATCHES OpenBSD)
  109. set (OPENBSD TRUE)
  110. elseif (CMAKE_SYSTEM_NAME MATCHES GNU)
  111. set (GNU TRUE)
  112. elseif (CMAKE_SYSTEM_NAME MATCHES BSDI)
  113. set (BSDI TRUE)
  114. elseif (CMAKE_SYSTEM_NAME MATCHES SYSV5)
  115. set (SYSV5 TRUE)
  116. elseif (CMAKE_SYSTEM_NAME MATCHES Solaris)
  117. set (SOLARIS TRUE)
  118. elseif (CMAKE_SYSTEM_NAME MATCHES HP-UX)
  119. set (HPUX TRUE)
  120. elseif (CMAKE_SYSTEM_NAME MATCHES AIX)
  121. set (AIX TRUE)
  122. elseif (CMAKE_SYSTEM_NAME MATCHES Minix)
  123. set (MINIX TRUE)
  124. elseif (CMAKE_SYSTEM_NAME MATCHES BeOS)
  125. message_error ("BeOS support has been removed as of SDL 2.0.2.")
  126. endif ()
  127. endif()
  128. # Default option knobs
  129. # Urho3D - commented out OPT_DEF_SSEMATH default variable as the underlying SSEMATH build option is also being commented out by us
  130. if(UNIX OR MINGW OR MSYS)
  131. set(OPT_DEF_LIBC ON)
  132. endif()
  133. # The hidraw support doesn't catch Xbox, PS4 and Nintendo controllers,
  134. # so we'll just use libusb when it's available. Except that libusb
  135. # requires root permissions to open devices, so that's not generally
  136. # useful, and we'll disable this by default on Unix. Windows and macOS
  137. # can use it without root access, though, so enable by default there.
  138. if(WINDOWS OR APPLE OR ANDROID)
  139. set(HIDAPI_SKIP_LIBUSB TRUE)
  140. else()
  141. set(HIDAPI_SKIP_LIBUSB FALSE)
  142. endif()
  143. if (HIDAPI_SKIP_LIBUSB)
  144. set(OPT_DEF_HIDAPI ON)
  145. endif()
  146. # Compiler info
  147. if(CMAKE_COMPILER_IS_GNUCC)
  148. set(USE_GCC TRUE)
  149. set(OPT_DEF_ASM TRUE)
  150. elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
  151. set(USE_CLANG TRUE)
  152. set(OPT_DEF_ASM TRUE)
  153. elseif(MSVC_VERSION GREATER 1400) # VisualStudio 8.0+
  154. set(OPT_DEF_ASM TRUE)
  155. #set(CMAKE_C_FLAGS "/ZI /WX- /
  156. else()
  157. set(OPT_DEF_ASM FALSE)
  158. endif()
  159. # Urho3D - commented out compiler/linker flags setup as we have configured all our compiler/linker flags as we want globally
  160. # Those are used for pkg-config and friends, so that the SDL2.pc, sdl2-config, # etc. are created correctly.
  161. # Urho3D - we do not use these variables for pkg-config setup for SDL library but we may need them later for Urho3D library
  162. set (SDL_LIBS)
  163. set (SDL_CFLAGS)
  164. # Emscripten toolchain has a nonempty default value for this, and the checks
  165. # in this file need to change that, so remember the original value, and
  166. # restore back to that afterwards. For check_function_exists() to work in
  167. # Emscripten, this value must be at its default value.
  168. # Urho3D - also due to a CMake's try_compile() bug on iOS/tvOS platform, the CMAKE_REQUIRED_FLAGS contains our SmileyHack-injection on iOS/tvOS platform
  169. set (ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
  170. # Urho3D - save the original CMake global settings, do not leave them to chances
  171. set (ORIG_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
  172. set (ORIG_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
  173. if (RPI)
  174. # Urho3D - TODO - move the find_package(VideoCore REQUIRED) call from Urho3D common module to here later after we have refactored the library dependency handling
  175. # Urho3D - bug fix - adjust the header search path for subsequent pthread, EGL and OpenGLES2 checks
  176. list (APPEND CMAKE_REQUIRED_INCLUDES ${VIDEOCORE_INCLUDE_DIRS})
  177. endif ()
  178. if(CYGWIN)
  179. # We build SDL on cygwin without the UNIX emulation layer
  180. # Urho3D - bug fix - we do not support Cygwin build so this fix is untested, just for completeness sake
  181. include_directories(/usr/include/mingw)
  182. set(CMAKE_REQUIRED_FLAGS "-mno-cygwin ${ORIG_CMAKE_REQUIRED_FLAGS}")
  183. check_c_source_compiles("int main(int argc, char **argv) {}"
  184. HAVE_GCC_NO_CYGWIN)
  185. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  186. if(HAVE_GCC_NO_CYGWIN)
  187. list(APPEND EXTRA_LDFLAGS "-mno-cygwin")
  188. list(APPEND SDL_LIBS "-mno-cygwin")
  189. endif()
  190. set(SDL_CFLAGS "${SDL_CFLAGS} -I/usr/include/mingw")
  191. endif()
  192. add_definitions(-DUSING_GENERATED_CONFIG_H)
  193. # General includes
  194. # Urho3D - use 'generated' path suffix for generated config header file, the suffic prevents overwriting the header file with the same name in the source tree in case of non out-of-source build tree is being used
  195. set (INCLUDE_DIRS ${SDL2_BINARY_DIR}/include/generated ${SDL2_SOURCE_DIR}/include)
  196. # All these ENABLED_BY_DEFAULT vars will default to ON if not specified, so
  197. # you only need to have a platform override them if they are disabling.
  198. # Urho3D - bug fix - commented out double initialization of the OPT_DEF_ASM variable, it has been initialized properly in "Compiler info" section above
  199. if(EMSCRIPTEN)
  200. # Set up default values for the currently supported set of subsystems:
  201. # Emscripten/Javascript does not have assembly support, a dynamic library
  202. # loading architecture, low-level CPU inspection or multithreading.
  203. set(OPT_DEF_ASM FALSE)
  204. set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
  205. # Urho3D - leave all the other subsystems enable by default
  206. set(SDL_THREADS_ENABLED_BY_DEFAULT OFF)
  207. endif()
  208. # Urho3D - we always build internal sub-libraries as STATIC library type, so this build option is not applicable to us
  209. set (SDL_STATIC_ENABLED_BY_DEFAULT ON)
  210. set (SDL_SHARED_ENABLED_BY_DEFAULT OFF)
  211. # Urho3D - bug fix - add compiler defined expected by SDL.c when building STATIC librabry type
  212. if (WINDOWS)
  213. add_definitions (-DSDL_STATIC_LIB)
  214. endif ()
  215. # Urho3D - we prefer to disable 2D render subsystem by default
  216. if (NOT DEFINED SDL_RENDER_ENABLED_BY_DEFAULT)
  217. set (SDL_RENDER_ENABLED_BY_DEFAULT OFF)
  218. endif ()
  219. set(SDL_SUBSYSTEMS
  220. Atomic Audio Video Render Events Joystick Haptic Power Threads Timers
  221. File Loadso CPUinfo Filesystem Dlopen Sensor)
  222. foreach(_SUB ${SDL_SUBSYSTEMS})
  223. string(TOUPPER ${_SUB} _OPT)
  224. if (NOT DEFINED SDL_${_OPT}_ENABLED_BY_DEFAULT)
  225. set(SDL_${_OPT}_ENABLED_BY_DEFAULT ON)
  226. endif()
  227. # Urho3D - bug fix - prevent SDL_DLOPEN build option from being declared twice
  228. if (NOT _OPT MATCHES DLOPEN|HAPTIC)
  229. option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ${SDL_${_OPT}_ENABLED_BY_DEFAULT})
  230. endif ()
  231. endforeach()
  232. # Urho3D - declare SDL_HAPTIC as a dependent option to SDL_JOYSTICK as haptic requires some private functions from the joystick subsystem
  233. dep_option (SDL_HAPTIC "Enable the Haptic subsystem" ${SDL_HAPTIC_ENABLED_BY_DEFAULT} SDL_JOYSTICK OFF)
  234. # Urho3D - TODO - put all these options into SDL-specific namespace group, they are littering CMake-gui all over the place as it is now
  235. # Also there seems to be duplicate between SDL_SUBSYSTEMS above with build options below: SDL_ATOMIC vs GCC_ATOMICS, SDL_THREADS vs PTHREADS, SDL_DLOPEN (subsystem) vs SDL_DLOPEN (option)
  236. option_string(ASSERTIONS "Enable internal sanity checks (auto/disabled/release/enabled/paranoid)" "auto")
  237. #set_option(DEPENDENCY_TRACKING "Use gcc -MMD -MT dependency tracking" ON)
  238. set_option(LIBC "Use the system C library" ${OPT_DEF_LIBC})
  239. # Urho3D - bug fix - also enable GCC_ATOMICS by default for Clang (including Emscripten which is a Clang derivative)
  240. dep_option(GCC_ATOMICS "Use gcc builtin atomics" ON "USE_GCC OR USE_CLANG" OFF)
  241. set_option(ASSEMBLY "Enable assembly routines" ${OPT_DEF_ASM})
  242. # Urho3D - commented out SSEMATH, SSE, SSE2, SSE3, MMX, 3DNOW, ALTIVEC build options as they have been reclassifified as Urho3D own build options
  243. set_option(DISKAUDIO "Support the disk writer audio driver" ON)
  244. set_option(DUMMYAUDIO "Support the dummy audio driver" ON)
  245. set_option(VIDEO_DIRECTFB "Use DirectFB video driver" OFF)
  246. dep_option(DIRECTFB_SHARED "Dynamically load directfb support" ON VIDEO_DIRECTFB OFF)
  247. set_option(VIDEO_DUMMY "Use dummy video driver" ON)
  248. # Urho3D - hide OpenGL option from all non-desktop platforms
  249. dep_option(VIDEO_OPENGL "Include OpenGL support" ON "NOT ANDROID AND NOT IOS AND NOT TVOS AND NOT ARM AND NOT WEB" OFF)
  250. # Urho3D - hide OpenGLES option from all desktop platforms, although a few of them appears to have the necessary header file to build SDL OpenGLES video driver
  251. dep_option(VIDEO_OPENGLES "Include OpenGL ES support" ON "ANDROID OR IOS OR TVOS OR ARM OR WEB" OFF)
  252. # Urho3D - only make PTHREADS option available on UNIX-like platforms
  253. dep_option(PTHREADS "Use POSIX threads for multi-threading" ON UNIX OFF)
  254. dep_option(PTHREADS_SEM "Use pthread semaphores" ON PTHREADS OFF)
  255. # Urho3D - SDL_DLOPEN was originally set as option twice (one here and one in the subsystem section above), we keep the one here so that we can make the option dependent on other conditions
  256. dep_option(SDL_DLOPEN "Use dlopen for shared object loading" ON "UNIX\;NOT IOS OR NOT IPHONEOS_DEPLOYMENT_TARGET OR NOT IPHONEOS_DEPLOYMENT_TARGET VERSION_LESS 8" OFF) # No need to check for tvOS as its target version is 9 or above
  257. # Urho3D - hide Unix-specific audio driver options from Android platform
  258. dep_option(OSS "Support the OSS audio API" ON UNIX_SYS OFF)
  259. dep_option(ALSA "Support the ALSA audio API" ON UNIX_SYS OFF)
  260. dep_option(ALSA_SHARED "Dynamically load ALSA audio support" ON ALSA OFF)
  261. dep_option(JACK "Support the JACK audio API" ON UNIX_SYS OFF)
  262. dep_option(JACK_SHARED "Dynamically load JACK audio support" ON JACK OFF)
  263. dep_option(ESD "Support the Enlightened Sound Daemon" ON UNIX_SYS OFF)
  264. dep_option(ESD_SHARED "Dynamically load ESD audio support" ON ESD OFF)
  265. dep_option(PULSEAUDIO "Use PulseAudio" ON UNIX_SYS OFF)
  266. dep_option(PULSEAUDIO_SHARED "Dynamically load PulseAudio support" ON PULSEAUDIO OFF)
  267. dep_option(ARTS "Support the Analog Real Time Synthesizer" ON UNIX_SYS OFF)
  268. dep_option(ARTS_SHARED "Dynamically load aRts audio support" ON ARTS OFF)
  269. dep_option(NAS "Support the NAS audio API" ON UNIX_SYS OFF)
  270. dep_option(NAS_SHARED "Dynamically load NAS audio API" ON NAS OFF)
  271. dep_option(SNDIO "Support the Roar audio API" ON UNIX_SYS OFF)
  272. dep_option(FUSIONSOUND "Use FusionSound audio driver" ON UNIX_SYS OFF)
  273. dep_option(FUSIONSOUND_SHARED "Dynamically load fusionsound audio support" ON FUSIONSOUND OFF)
  274. dep_option(LIBSAMPLERATE "Use libsamplerate for audio rate conversion" ON UNIX_SYS OFF)
  275. dep_option(LIBSAMPLERATE_SHARED "Dynamically load libsamplerate" ON LIBSAMPLERATE OFF)
  276. # Urho3D - commented out RPATH as an option because Urho3D is configured to always use RPATH, so init the variable to always TRUE
  277. set (RPATH TRUE)
  278. # Urho3D - prefer clock_gettime() when it is available
  279. dep_option(CLOCK_GETTIME "Use clock_gettime() instead of gettimeofday()" ON "NOT WINDOWS" OFF)
  280. set_option(INPUT_TSLIB "Use the Touchscreen library for input" ${UNIX_SYS})
  281. dep_option(VIDEO_WAYLAND "Use Wayland video driver" ON UNIX_SYS OFF)
  282. dep_option(WAYLAND_SHARED "Dynamically load Wayland support" ON VIDEO_WAYLAND OFF)
  283. # Urho3D - change the VIDEO_WAYLAND_QT_TOUCH default value to FALSE (this is only needed by Sailfish[?] but we don't know way to auto-detect that yet)
  284. dep_option(VIDEO_WAYLAND_QT_TOUCH "QtWayland server support for Wayland video driver" OFF VIDEO_WAYLAND OFF)
  285. # Urho3D - only make VIDEO_RPI option available on Raspberry-Pi platform
  286. dep_option(VIDEO_RPI "Use Raspberry Pi video driver" ON "RPI AND NOT RPI_ABI STREQUAL RPI4" OFF)
  287. # Urho3D - bug fix - make VIDEO_X11 build option available for desktop UNIX (including OSX) only
  288. dep_option(VIDEO_X11 "Use X11 video driver" ON "UNIX_SYS OR APPLE\;NOT RPI AND NOT IOS AND NOT TVOS" OFF)
  289. dep_option(X11_SHARED "Dynamically load X11 support" ON VIDEO_X11 OFF)
  290. foreach(_SUB Xcursor Xinerama XInput Xrandr Xscrnsaver XShape Xvm)
  291. string(TOUPPER "VIDEO_X11_${_SUB}" _OPT)
  292. dep_option(${_OPT} "Enable ${_SUB} support" ON VIDEO_X11 OFF)
  293. endforeach()
  294. # Urho3D - bug fix - only make the COCOA option available on OSX platform but not iOS/tvOS; it does not make too much sense now for user to disable it because SDL/Apple has dropped support for XQuartz (X11 on Mac), so Cocoa is the only video driver available
  295. # But we still keep it as an option here because it should be possible to add back the XQuartz support
  296. dep_option(VIDEO_COCOA "Use Cocoa video driver" ON "APPLE AND NOT IOS AND NOT TVOS" OFF)
  297. # Urho3D - only make DIRECTX option available on Windows platform when URHO3D_OPENGL is enabled, i.e. DIRECTX variable must always be ON (not an option) when URHO3D_OPENGL is disabled because in this case it must depend on Direct3D which is a component of DirectX
  298. if (WINDOWS)
  299. dep_option(DIRECTX "Use DirectX for Windows audio/video" ON URHO3D_OPENGL ON)
  300. else ()
  301. set (DIRECTX OFF) # Make it off explicitly when not targeting Windows platform, just in case user passes it in accidentally via CLI
  302. endif ()
  303. dep_option(WASAPI "Use the Windows WASAPI audio driver" ON WINDOWS OFF)
  304. # Urho3D
  305. if (WINDOWS)
  306. if (URHO3D_D3D11)
  307. set (RENDER_D3D TRUE)
  308. else ()
  309. set (RENDER_D3D FALSE)
  310. endif ()
  311. endif ()
  312. dep_option(VIDEO_VIVANTE "Use Vivante EGL video driver" ON UNIX_SYS OFF)
  313. dep_option(VIDEO_VULKAN "Enable Vulkan support" ON "ANDROID OR APPLE OR LINUX OR WINDOWS" OFF)
  314. dep_option(VIDEO_KMSDRM "Use KMS DRM video driver" ON UNIX_SYS OFF)
  315. dep_option(KMSDRM_SHARED "Dynamically load KMS DRM support" ON VIDEO_KMSDRM OFF)
  316. option_string(BACKGROUNDING_SIGNAL "number to use for magic backgrounding signal or 'OFF'" OFF)
  317. option_string(FOREGROUNDING_SIGNAL "number to use for magic foregrounding signal or 'OFF'" OFF)
  318. set_option(HIDAPI "Use HIDAPI for low level joystick drivers" ${OPT_DEF_HIDAPI})
  319. set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared version of the library")
  320. set(SDL_STATIC ${SDL_STATIC_ENABLED_BY_DEFAULT} CACHE BOOL "Build a static version of the library")
  321. dep_option(SDL_STATIC_PIC "Static version of the library should be built with Position Independent Code" OFF "SDL_STATIC" OFF)
  322. # Urho3D - remove option to build the test directory
  323. # General source files
  324. set (SOURCE_FILE_PATTERNS
  325. ${SDL2_SOURCE_DIR}/src/*.c
  326. ${SDL2_SOURCE_DIR}/src/atomic/*.c
  327. # Urho3D - we always disable dynamic API, so commented out ${SDL2_SOURCE_DIR}/src/dynapi/*.c
  328. ${SDL2_SOURCE_DIR}/src/libm/*.c
  329. ${SDL2_SOURCE_DIR}/src/stdlib/*.c
  330. ${SDL2_SOURCE_DIR}/src/thread/*.c
  331. ${SDL2_SOURCE_DIR}/src/timer/*.c)
  332. # Urho3D - exclude source files from disabled subsystems, except SDL_ATOMIC, SDL_THREADS and SDL_TIMERS as SDL always needs them even when they may be just generic or dummy implementations
  333. foreach (_SUB AUDIO CPUINFO EVENTS FILE HAPTIC JOYSTICK POWER RENDER SENSOR VIDEO)
  334. string (TOLOWER ${_SUB} _DIR)
  335. if (${SDL_${_SUB}})
  336. list (APPEND SOURCE_FILE_PATTERNS ${SDL2_SOURCE_DIR}/src/${_DIR}/*.c)
  337. endif ()
  338. endforeach ()
  339. if (SDL_RENDER)
  340. list (APPEND SOURCE_FILE_PATTERNS ${SDL2_SOURCE_DIR}/src/render/*/*.c) # Recurse one more level
  341. endif ()
  342. if (SDL_VIDEO)
  343. list (APPEND SOURCE_FILE_PATTERNS ${SDL2_SOURCE_DIR}/src/video/yuv2rgb/*.c)
  344. endif ()
  345. file (GLOB SOURCE_FILES ${SOURCE_FILE_PATTERNS})
  346. if(ASSERTIONS STREQUAL "auto")
  347. # Do nada - use optimization settings to determine the assertion level
  348. elseif(ASSERTIONS STREQUAL "disabled")
  349. set(SDL_DEFAULT_ASSERT_LEVEL 0)
  350. elseif(ASSERTIONS STREQUAL "release")
  351. set(SDL_DEFAULT_ASSERT_LEVEL 1)
  352. elseif(ASSERTIONS STREQUAL "enabled")
  353. set(SDL_DEFAULT_ASSERT_LEVEL 2)
  354. elseif(ASSERTIONS STREQUAL "paranoid")
  355. set(SDL_DEFAULT_ASSERT_LEVEL 3)
  356. else()
  357. message_error("unknown assertion level")
  358. endif()
  359. set(HAVE_ASSERTIONS ${ASSERTIONS})
  360. if(NOT BACKGROUNDING_SIGNAL STREQUAL "OFF")
  361. add_definitions("-DSDL_BACKGROUNDING_SIGNAL=${BACKGROUNDING_SIGNAL}")
  362. endif()
  363. if(NOT FOREGROUNDING_SIGNAL STREQUAL "OFF")
  364. add_definitions("-DSDL_FOREGROUNDING_SIGNAL=${FOREGROUNDING_SIGNAL}")
  365. endif()
  366. # Compiler option evaluation
  367. if(USE_GCC OR USE_CLANG)
  368. # Check for -Wall first, so later things can override pieces of it.
  369. check_c_compiler_flag(-Wall HAVE_GCC_WALL)
  370. if(HAVE_GCC_WALL)
  371. list(APPEND EXTRA_CFLAGS "-Wall")
  372. if(HAIKU)
  373. # Urho3D - TODO - since we do not support HAIKU for now, we can leave the cflags configuration here
  374. # However, when we do then it must be moved to our common module and/or just commented out
  375. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")
  376. endif()
  377. endif()
  378. check_c_compiler_flag(-fno-strict-aliasing HAVE_GCC_NO_STRICT_ALIASING)
  379. if(HAVE_GCC_NO_STRICT_ALIASING)
  380. list(APPEND EXTRA_CFLAGS "-fno-strict-aliasing")
  381. endif()
  382. check_c_compiler_flag(-Wdeclaration-after-statement HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
  383. if(HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
  384. check_c_compiler_flag(-Werror=declaration-after-statement HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
  385. # Urho3D - bug fix - SDL does not build cleanly for Android platform with this flag on, make a tweak here rather than changing on their code
  386. if(HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT AND NOT ANDROID)
  387. list(APPEND EXTRA_CFLAGS "-Werror=declaration-after-statement")
  388. endif()
  389. list(APPEND EXTRA_CFLAGS "-Wdeclaration-after-statement")
  390. endif()
  391. if(DEPENDENCY_TRACKING)
  392. check_c_source_compiles("
  393. #if !defined(__GNUC__) || __GNUC__ < 3
  394. #error Dependency tracking requires GCC 3.0 or newer
  395. #endif
  396. int main(int argc, char **argv) { }" HAVE_DEPENDENCY_TRACKING)
  397. endif()
  398. if(GCC_ATOMICS)
  399. check_c_source_compiles("int main(int argc, char **argv) {
  400. int a;
  401. void *x, *y, *z;
  402. __sync_lock_test_and_set(&a, 4);
  403. __sync_lock_test_and_set(&x, y);
  404. __sync_fetch_and_add(&a, 1);
  405. __sync_bool_compare_and_swap(&a, 5, 10);
  406. __sync_bool_compare_and_swap(&x, y, z); }" HAVE_GCC_ATOMICS)
  407. if(NOT HAVE_GCC_ATOMICS)
  408. check_c_source_compiles("int main(int argc, char **argv) {
  409. int a;
  410. __sync_lock_test_and_set(&a, 1);
  411. __sync_lock_release(&a); }" HAVE_GCC_SYNC_LOCK_TEST_AND_SET)
  412. endif()
  413. endif()
  414. set(CMAKE_REQUIRED_FLAGS "-mpreferred-stack-boundary=2 ${ORIG_CMAKE_REQUIRED_FLAGS}")
  415. check_c_source_compiles("int x = 0; int main(int argc, char **argv) {}"
  416. HAVE_GCC_PREFERRED_STACK_BOUNDARY)
  417. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  418. # Urho3D - we rely on GenerateExportHeader CMake module for configuring GCC/Clang visibility attribute support
  419. check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW)
  420. if(HAVE_GCC_WSHADOW)
  421. list(APPEND EXTRA_CFLAGS "-Wshadow")
  422. endif()
  423. # Urho3D - there is no need to use AppleClang-specific linker flags, also because we have fixed our CMAKE_REQUIRED_FLAGS to make the detection reliable
  424. set(CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined ${ORIG_CMAKE_REQUIRED_FLAGS}")
  425. check_c_compiler_flag("" HAVE_NO_UNDEFINED)
  426. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  427. if(HAVE_NO_UNDEFINED)
  428. list(APPEND EXTRA_LDFLAGS "-Wl,--no-undefined")
  429. endif()
  430. # Urho3D - Wayland quick fix
  431. list(APPEND EXTRA_CFLAGS "-fcommon")
  432. endif()
  433. if(ASSEMBLY)
  434. if(USE_GCC OR USE_CLANG)
  435. set(SDL_ASSEMBLY_ROUTINES 1)
  436. # TODO: Those all seem to be quite GCC specific - needs to be
  437. # reworked for better compiler support
  438. set(HAVE_ASSEMBLY TRUE)
  439. # Urho3D - move the altivec, mmx, 3dnow, sse, sse2, and sse3 checks to Urho3D common module which then configure the compiler flags globally
  440. # Urho3D - bug fix - do not use "-mfpmath=387" in EXTRA_CFLAGS, instead let the compiler to choose what's the best by itself (i.e. '387' for x86 and 'sse' for x86_64) and also to keep SDL library being built with the same option as Urho3D library and all the other 3rd-party sub-libraries; besides the '387' is invalid when targeting arm64
  441. # Urho3D - commented out the HAVE_SSEMATH variable as it is not being used anywhere currently; furthermore compiler already emits __SSE_MATH__ or __SSE2_MATH__ as necessary on x86_64 ABI only; so instead of using HAVE_SSEMATH variable, we should actually use the __SSE_MATH__ or __SSE2_MATH__ compiler define if that is the original intention of having this variable
  442. check_include_file("immintrin.h" HAVE_IMMINTRIN_H)
  443. if(URHO3D_ALTIVEC)
  444. set(SDL_ALTIVEC_BLITTERS 1)
  445. endif()
  446. elseif(MSVC_VERSION GREATER 1500)
  447. # TODO: SDL_cpuinfo.h needs to support the user's configuration wish
  448. # Urho3D - move the HAVE_MMX, HAVE_3DNOW, HAVE_SSE, HAVE_SSE2, and HAVE_SSE3 initialization to Urho3D common module
  449. set(SDL_ASSEMBLY_ROUTINES 1)
  450. endif()
  451. endif()
  452. # Urho3D - move from Unix platform-specific section below to here
  453. if(CLOCK_GETTIME AND (NOT IOS OR IPHONEOS_DEPLOYMENT_TARGET STREQUAL "" OR NOT IPHONEOS_DEPLOYMENT_TARGET VERSION_LESS 10.0)) # We cheat a little bit here with a hard-coded check because iOS 10.3 SDK when targeting 9.3 has strong symbol for iPhoneOS archs but weak symbol for iPhoneSimulator archs
  454. # Urho3D - bug fix - use different variables for different checks because of CMake caches the result variable; this fix the detection on Android platform
  455. check_library_exists(rt clock_gettime "" FOUND_CLOCK_GETTIME_IN_RT)
  456. if(FOUND_CLOCK_GETTIME_IN_RT)
  457. list(APPEND EXTRA_LIBS rt)
  458. set(HAVE_CLOCK_GETTIME 1)
  459. else()
  460. check_library_exists(c clock_gettime "" FOUND_CLOCK_GETTIME_IN_C)
  461. if(FOUND_CLOCK_GETTIME_IN_C)
  462. set(HAVE_CLOCK_GETTIME 1)
  463. endif()
  464. endif()
  465. endif()
  466. # TODO: Can't deactivate on FreeBSD? w/o LIBC, SDL_stdinc.h can't define
  467. # anything.
  468. if(LIBC)
  469. if(WINDOWS AND NOT MINGW)
  470. set(HAVE_LIBC TRUE)
  471. foreach(_HEADER stdio.h string.h wchar.h ctype.h math.h limits.h)
  472. string(TOUPPER "HAVE_${_HEADER}" _UPPER)
  473. string(REPLACE "." "_" _HAVE_H ${_UPPER})
  474. set(${_HAVE_H} 1)
  475. endforeach()
  476. set(HAVE_SIGNAL_H 1)
  477. foreach(_FN
  478. malloc calloc realloc free qsort abs memset memcpy memmove memcmp
  479. wcslen wcscmp
  480. strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
  481. _ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp
  482. _stricmp _strnicmp sscanf
  483. acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf
  484. copysign copysignf cos cosf exp expf fabs fabsf floor floorf fmod fmodf
  485. log logf log10 log10f pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf)
  486. string(TOUPPER ${_FN} _UPPER)
  487. set(HAVE_${_UPPER} 1)
  488. endforeach()
  489. if(NOT CYGWIN AND NOT MINGW)
  490. set(HAVE_ALLOCA 1)
  491. endif()
  492. set(HAVE_M_PI 1)
  493. add_definitions(-D_USE_MATH_DEFINES) # needed for M_PI
  494. set(STDC_HEADERS 1)
  495. else()
  496. set(HAVE_LIBC TRUE)
  497. # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" compiler flag or use CMAKE_REQUIRED_INCLUDES (e.g. on RPI) to cater for it
  498. set (CMAKE_REQUIRED_INCLUDES_SYS_TYPES_SAVED ${CMAKE_REQUIRED_INCLUDES})
  499. if (CMAKE_CROSSCOMPILING AND NOT "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}" MATCHES --sysroot)
  500. find_path (SYS_TYPES_H_INCLUDE_DIRS NAMES sys/types.h)
  501. if (SYS_TYPES_H_INCLUDE_DIRS)
  502. # Assume the header search path has not been adjusted elsewhere yet, there is no harm anyway when a same entry is added twice into the list
  503. list (APPEND CMAKE_REQUIRED_INCLUDES ${SYS_TYPES_H_INCLUDE_DIRS})
  504. endif ()
  505. endif ()
  506. check_include_file(sys/types.h HAVE_SYS_TYPES_H)
  507. set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SYS_TYPES_SAVED})
  508. # Urho3D - no fix required - it seems all the compiler toolchains (native and X-compiling) that have been tested are able to find these headers correctly
  509. # Android NDK is able to find these headers with the help of "--sysroot" compiler flags, while others like MinGW and Linaro GCC for RPI work out of box
  510. # However, AppleClang when targeting iOS/tvOS platform can only find these headers correctly AFTER applying a CMake hack from our common module to workaround a CMake bug so that try_compile() command works well on iOS/tvOS platform
  511. foreach(_HEADER
  512. stdio.h stdlib.h stddef.h stdarg.h malloc.h memory.h string.h limits.h
  513. strings.h wchar.h inttypes.h stdint.h ctype.h math.h iconv.h signal.h) # Urho3D - exclude libunwind.h that is only used for testing code which we don't include
  514. string(TOUPPER "HAVE_${_HEADER}" _UPPER)
  515. string(REPLACE "." "_" _HAVE_H ${_UPPER})
  516. check_include_file("${_HEADER}" ${_HAVE_H})
  517. endforeach()
  518. # Urho3D - bug fix - MinGW has standard-C headers, except dlfcn.h
  519. set (CHECK_STDC_HEADERS stdint.h stddef.h inttypes.h stdlib.h strings.h string.h float.h)
  520. if (NOT MINGW)
  521. list (APPEND CHECK_STDC_HEADERS dlfcn.h)
  522. endif ()
  523. check_include_files("${CHECK_STDC_HEADERS}" STDC_HEADERS) # Stringify the INCLUDE list variable as this macro does not expect to receive a list
  524. # Urho3D - bug fix - commented out initialization of SIZEOF_SIZE_T as it does appear to be used anywhere in the code and it has caused problem to Emscripten build (we could have fixed the problem other way but this is cleaner)
  525. check_symbol_exists(M_PI math.h HAVE_M_PI)
  526. # Urho3D - for consistency sake use check_include_file() to check for HAVE_MPROTECT
  527. check_include_file (sys/mman.h HAVE_MPROTECT)
  528. foreach(_FN
  529. strtod malloc calloc realloc free getenv setenv putenv unsetenv
  530. qsort abs bcopy memset memcpy memmove memcmp strlen strlcpy strlcat
  531. _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
  532. _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull
  533. atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp
  534. vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp
  535. nanosleep sysconf sysctlbyname getauxval poll _Exit
  536. )
  537. string(TOUPPER ${_FN} _UPPER)
  538. set(_HAVEVAR "HAVE_${_UPPER}")
  539. check_function_exists("${_FN}" ${_HAVEVAR})
  540. endforeach()
  541. check_library_exists(m pow "" HAVE_LIBM)
  542. if(HAVE_LIBM)
  543. set(CMAKE_REQUIRED_LIBRARIES m)
  544. foreach(_FN
  545. atan atan2 ceil copysign cos cosf fabs floor log pow scalbn sin
  546. sinf sqrt sqrtf tan tanf acos asin)
  547. string(TOUPPER ${_FN} _UPPER)
  548. set(_HAVEVAR "HAVE_${_UPPER}")
  549. check_function_exists("${_FN}" ${_HAVEVAR})
  550. endforeach()
  551. set(CMAKE_REQUIRED_LIBRARIES)
  552. list(APPEND EXTRA_LIBS m)
  553. endif()
  554. check_library_exists(iconv iconv_open "" HAVE_LIBICONV)
  555. if(HAVE_LIBICONV)
  556. list(APPEND EXTRA_LIBS iconv)
  557. set(HAVE_ICONV 1)
  558. endif()
  559. # Urho3D - bug fix - cannot use check_function_exists() with alloca; with this bug fixed, the same check should work on Apple too so no more hardcoding
  560. check_include_file(alloca.h HAVE_ALLOCA_H)
  561. if (HAVE_ALLOCA_H)
  562. check_c_source_compiles ("
  563. #include <alloca.h>
  564. int main(int argc, char** argv) { alloca(0); }" HAVE_ALLOCA)
  565. endif ()
  566. check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION)
  567. endif()
  568. else()
  569. if(WINDOWS)
  570. set(HAVE_STDARG_H 1)
  571. set(HAVE_STDDEF_H 1)
  572. endif()
  573. endif()
  574. # Enable/disable various subsystems of the SDL library
  575. foreach(_SUB ${SDL_SUBSYSTEMS})
  576. string(TOUPPER ${_SUB} _OPT)
  577. if(NOT SDL_${_OPT})
  578. set(SDL_${_OPT}_DISABLED 1)
  579. endif()
  580. endforeach()
  581. # Urho3D - move the individual subsystem check to "General source files" block above
  582. # General SDL subsystem options, valid for all platforms
  583. if(SDL_AUDIO)
  584. if(DUMMYAUDIO)
  585. set(SDL_AUDIO_DRIVER_DUMMY 1)
  586. file(GLOB DUMMYAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dummy/*.c)
  587. set(SOURCE_FILES ${SOURCE_FILES} ${DUMMYAUDIO_SOURCES})
  588. set(HAVE_DUMMYAUDIO TRUE)
  589. endif()
  590. if(DISKAUDIO)
  591. set(SDL_AUDIO_DRIVER_DISK 1)
  592. file(GLOB DISKAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/disk/*.c)
  593. set(SOURCE_FILES ${SOURCE_FILES} ${DISKAUDIO_SOURCES})
  594. set(HAVE_DISKAUDIO TRUE)
  595. endif()
  596. endif()
  597. if(SDL_VIDEO)
  598. if(VIDEO_DUMMY)
  599. set(SDL_VIDEO_DRIVER_DUMMY 1)
  600. file(GLOB VIDEO_DUMMY_SOURCES ${SDL2_SOURCE_DIR}/src/video/dummy/*.c)
  601. set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_DUMMY_SOURCES})
  602. set(HAVE_VIDEO_DUMMY TRUE)
  603. set(HAVE_SDL_VIDEO TRUE)
  604. endif()
  605. endif()
  606. if(SDL_DLOPEN)
  607. # Urho3D - remove duplicate/redundant check as we have already ensure that this build option is made available for the correct platforms only
  608. CheckDLOPEN()
  609. endif()
  610. # Urho3D - move from Unix platform-specifc block to here as this timer implementation is applicable for Android and Emscripten as well
  611. if(SDL_TIMERS AND UNIX AND NOT HAIKU) # Haiku has its own timer implementation, so exclude it explicitly
  612. set(SDL_TIMER_UNIX 1)
  613. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
  614. set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  615. set(HAVE_SDL_TIMERS TRUE)
  616. endif()
  617. if (SDL_THREADS)
  618. CheckPTHREAD()
  619. endif ()
  620. # Platform-specific options and settings
  621. # Urho3D - rearrange the if-elseif blocks (specific case before generic case)
  622. if(ANDROID)
  623. file(GLOB ANDROID_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/android/*.c)
  624. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_CORE_SOURCES})
  625. # SDL_spinlock.c Needs to be compiled in ARM mode.
  626. # There seems to be no better way currently to set the ARM mode.
  627. # see: https://issuetracker.google.com/issues/62264618
  628. # Another option would be to set ARM mode to all compiled files
  629. check_c_compiler_flag(-marm HAVE_ARM_MODE)
  630. if(HAVE_ARM_MODE)
  631. set_source_files_properties(${SDL2_SOURCE_DIR}/src/atomic/SDL_spinlock.c PROPERTIES COMPILE_FLAGS -marm)
  632. endif()
  633. # Urho3D - bug fix - src/main/android/SDL_android_main.c is no longer required since release 2.0.6
  634. if(SDL_AUDIO)
  635. set(SDL_AUDIO_DRIVER_ANDROID 1)
  636. file(GLOB ANDROID_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/android/*.c)
  637. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_AUDIO_SOURCES})
  638. set(HAVE_SDL_AUDIO TRUE)
  639. endif()
  640. if(SDL_FILESYSTEM)
  641. set(SDL_FILESYSTEM_ANDROID 1)
  642. file(GLOB ANDROID_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/android/*.c)
  643. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_FILESYSTEM_SOURCES})
  644. set(HAVE_SDL_FILESYSTEM TRUE)
  645. endif()
  646. if(SDL_HAPTIC)
  647. set(SDL_HAPTIC_ANDROID 1)
  648. file(GLOB ANDROID_HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/android/*.c)
  649. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_HAPTIC_SOURCES})
  650. set(HAVE_SDL_HAPTIC TRUE)
  651. endif()
  652. if(SDL_JOYSTICK)
  653. CheckHIDAPI()
  654. # Urho3D - get the cue from how the hidapi is setup on other platforms
  655. if (HAVE_HIDAPI)
  656. list (APPEND SOURCE_FILES ${SDL2_SOURCE_DIR}/src/hidapi/android/hid.cpp)
  657. endif ()
  658. set(SDL_JOYSTICK_ANDROID 1)
  659. file(GLOB ANDROID_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/android/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
  660. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_JOYSTICK_SOURCES})
  661. set(HAVE_SDL_JOYSTICK TRUE)
  662. endif()
  663. if(SDL_POWER)
  664. set(SDL_POWER_ANDROID 1)
  665. file(GLOB ANDROID_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/android/*.c)
  666. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_POWER_SOURCES})
  667. set(HAVE_SDL_POWER TRUE)
  668. endif()
  669. if(SDL_SENSOR)
  670. set(SDL_SENSOR_ANDROID 1)
  671. set(HAVE_SDL_SENSORS TRUE)
  672. file(GLOB ANDROID_SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/android/*.c)
  673. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_SENSOR_SOURCES})
  674. endif()
  675. if(SDL_VIDEO)
  676. set(SDL_VIDEO_DRIVER_ANDROID 1)
  677. file(GLOB ANDROID_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/android/*.c)
  678. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_VIDEO_SOURCES})
  679. set(HAVE_SDL_VIDEO TRUE)
  680. # Core stuff
  681. find_library(ANDROID_DL_LIBRARY dl)
  682. find_library(ANDROID_LOG_LIBRARY log)
  683. find_library(ANDROID_LIBRARY_LIBRARY android)
  684. list(APPEND EXTRA_LIBS ${ANDROID_DL_LIBRARY} ${ANDROID_LOG_LIBRARY} ${ANDROID_LIBRARY_LIBRARY})
  685. add_definitions(-DGL_GLEXT_PROTOTYPES)
  686. #enable gles
  687. if(VIDEO_OPENGLES)
  688. CheckOpenGLES()
  689. find_library(OpenGLES1_LIBRARY GLESv1_CM)
  690. find_library(OpenGLES2_LIBRARY GLESv2)
  691. list(APPEND EXTRA_LIBS ${OpenGLES1_LIBRARY} ${OpenGLES2_LIBRARY})
  692. endif()
  693. CHECK_C_SOURCE_COMPILES("
  694. #if defined(__ARM_ARCH) && __ARM_ARCH < 7
  695. #error Vulkan doesn't work on this configuration
  696. #endif
  697. int main()
  698. {
  699. return 0;
  700. }
  701. " VULKAN_PASSED_ANDROID_CHECKS)
  702. if(NOT VULKAN_PASSED_ANDROID_CHECKS)
  703. set(VIDEO_VULKAN OFF)
  704. message(STATUS "Vulkan doesn't work on this configuration")
  705. endif()
  706. endif()
  707. # Urho3D - import 'cpufeatures' from Android NDK
  708. if (SDL_CPUINFO)
  709. # This is a hack - intentionally do not depend on the 'cpufeatures' as separate built target with android_ndk_import_module_cpufeatures macro from NDK
  710. list (APPEND INCLUDE_DIRS ${ANDROID_NDK}/sources/android/cpufeatures)
  711. list (APPEND SOURCE_FILES ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
  712. endif ()
  713. elseif(EMSCRIPTEN)
  714. # Hide noisy warnings that intend to aid mostly during initial stages of porting a new
  715. # project. Uncomment at will for verbose cross-compiling -I/../ path info.
  716. add_definitions(-Wno-warn-absolute-paths)
  717. if(SDL_AUDIO)
  718. set(SDL_AUDIO_DRIVER_EMSCRIPTEN 1)
  719. file(GLOB EM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/emscripten/*.c)
  720. set(SOURCE_FILES ${SOURCE_FILES} ${EM_AUDIO_SOURCES})
  721. set(HAVE_SDL_AUDIO TRUE)
  722. endif()
  723. if(SDL_FILESYSTEM)
  724. set(SDL_FILESYSTEM_EMSCRIPTEN 1)
  725. file(GLOB EM_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/emscripten/*.c)
  726. set(SOURCE_FILES ${SOURCE_FILES} ${EM_FILESYSTEM_SOURCES})
  727. set(HAVE_SDL_FILESYSTEM TRUE)
  728. endif()
  729. if(SDL_JOYSTICK)
  730. set(SDL_JOYSTICK_EMSCRIPTEN 1)
  731. file(GLOB EM_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/emscripten/*.c)
  732. set(SOURCE_FILES ${SOURCE_FILES} ${EM_JOYSTICK_SOURCES})
  733. set(HAVE_SDL_JOYSTICK TRUE)
  734. endif()
  735. if(SDL_POWER)
  736. set(SDL_POWER_EMSCRIPTEN 1)
  737. file(GLOB EM_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/emscripten/*.c)
  738. set(SOURCE_FILES ${SOURCE_FILES} ${EM_POWER_SOURCES})
  739. set(HAVE_SDL_POWER TRUE)
  740. endif()
  741. if(SDL_VIDEO)
  742. set(SDL_VIDEO_DRIVER_EMSCRIPTEN 1)
  743. file(GLOB EM_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/emscripten/*.c)
  744. set(SOURCE_FILES ${SOURCE_FILES} ${EM_VIDEO_SOURCES})
  745. set(HAVE_SDL_VIDEO TRUE)
  746. #enable gles
  747. if(VIDEO_OPENGLES)
  748. CheckOpenGLES()
  749. endif()
  750. endif()
  751. elseif(APPLE)
  752. # TODO: rework this all for proper MacOS X, iOS and Darwin support
  753. # We always need these libs on macOS at the moment.
  754. # !!! FIXME: we need Carbon for some very old API calls in
  755. # !!! FIXME: src/video/cocoa/SDL_cocoakeyboard.c, but we should figure out
  756. # !!! FIXME: how to dump those.
  757. if(NOT IOS AND NOT TVOS)
  758. set(SDL_FRAMEWORK_COCOA 1)
  759. set(SDL_FRAMEWORK_CARBON 1)
  760. endif()
  761. # Requires the darwin file implementation
  762. if(SDL_FILE)
  763. file(GLOB EXTRA_SOURCES ${SDL2_SOURCE_DIR}/src/file/cocoa/*.m)
  764. set(SOURCE_FILES ${EXTRA_SOURCES} ${SOURCE_FILES})
  765. set(HAVE_SDL_FILE TRUE)
  766. # !!! FIXME: why is COREVIDEO inside this if() block?
  767. set(SDL_FRAMEWORK_COREVIDEO 1)
  768. else()
  769. message_error("SDL_FILE must be enabled to build on MacOS X")
  770. endif()
  771. if(SDL_AUDIO)
  772. set(SDL_AUDIO_DRIVER_COREAUDIO 1)
  773. file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.m)
  774. set(SOURCE_FILES ${SOURCE_FILES} ${AUDIO_SOURCES})
  775. set(HAVE_SDL_AUDIO TRUE)
  776. set(SDL_FRAMEWORK_COREAUDIO 1)
  777. set(SDL_FRAMEWORK_AUDIOTOOLBOX 1)
  778. endif()
  779. if(SDL_JOYSTICK)
  780. CheckHIDAPI()
  781. # Urho3D - bug fix - make it work for iOS/tvOS platform
  782. if(HAVE_HIDAPI)
  783. if(IOS OR TVOS)
  784. set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/ios/hid.m)
  785. else()
  786. set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/mac/hid.c)
  787. endif()
  788. endif()
  789. # Urho3D - bug fix - make it work for iOS/tvOS platform
  790. if (IOS OR TVOS)
  791. set (SDL_JOYSTICK_MFI 1)
  792. file (GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
  793. else ()
  794. set(SDL_JOYSTICK_IOKIT 1)
  795. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
  796. set(SDL_FRAMEWORK_IOKIT 1)
  797. set(SDL_FRAMEWORK_FF 1)
  798. endif ()
  799. set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  800. set(HAVE_SDL_JOYSTICK TRUE)
  801. endif()
  802. if(SDL_HAPTIC)
  803. # Urho3d - bug fix - make it work for iOS/tvOS platform
  804. if (IOS OR TVOS)
  805. set (SDL_HAPTIC_DUMMY 1)
  806. file (GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  807. else ()
  808. set(SDL_HAPTIC_IOKIT 1)
  809. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/darwin/*.c)
  810. set(SDL_FRAMEWORK_IOKIT 1)
  811. set(SDL_FRAMEWORK_FF 1)
  812. endif ()
  813. set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  814. set(HAVE_SDL_HAPTIC TRUE)
  815. if(NOT SDL_JOYSTICK)
  816. message(FATAL_ERROR "SDL_HAPTIC requires SDL_JOYSTICK to be enabled")
  817. endif()
  818. endif()
  819. if(SDL_POWER)
  820. # Urho3d - bug fix - make it work for iOS/tvOS platform
  821. if (IOS OR TVOS)
  822. set (SDL_POWER_UIKIT 1)
  823. file (GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/uikit/*.m)
  824. else ()
  825. set(SDL_POWER_MACOSX 1)
  826. file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/macosx/*.c)
  827. set(SDL_FRAMEWORK_IOKIT 1)
  828. endif ()
  829. set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
  830. set_source_files_properties(${POWER_SOURCES} PROPERTIES LANGUAGE C)
  831. set(HAVE_SDL_POWER TRUE)
  832. endif()
  833. if(SDL_FILESYSTEM)
  834. set(SDL_FILESYSTEM_COCOA 1)
  835. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
  836. set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  837. set(HAVE_SDL_FILESYSTEM TRUE)
  838. endif()
  839. # Actually load the frameworks at the end so we don't duplicate include.
  840. # Urho3D - TODO - this list in complete, do this when we refactor the library dependency handling
  841. if(SDL_FRAMEWORK_COREVIDEO)
  842. find_library(COREVIDEO CoreVideo)
  843. list(APPEND EXTRA_LIBS ${COREVIDEO})
  844. endif()
  845. if(SDL_FRAMEWORK_COCOA)
  846. find_library(COCOA_LIBRARY Cocoa)
  847. list(APPEND EXTRA_LIBS ${COCOA_LIBRARY})
  848. endif()
  849. if(SDL_FRAMEWORK_IOKIT)
  850. find_library(IOKIT IOKit)
  851. list(APPEND EXTRA_LIBS ${IOKIT})
  852. endif()
  853. if(SDL_FRAMEWORK_FF)
  854. find_library(FORCEFEEDBACK ForceFeedback)
  855. list(APPEND EXTRA_LIBS ${FORCEFEEDBACK})
  856. endif()
  857. if(SDL_FRAMEWORK_CARBON)
  858. find_library(CARBON_LIBRARY Carbon)
  859. list(APPEND EXTRA_LIBS ${CARBON_LIBRARY})
  860. endif()
  861. if(SDL_FRAMEWORK_COREAUDIO)
  862. find_library(COREAUDIO CoreAudio)
  863. list(APPEND EXTRA_LIBS ${COREAUDIO})
  864. endif()
  865. if(SDL_FRAMEWORK_AUDIOTOOLBOX)
  866. find_library(AUDIOTOOLBOX AudioToolbox)
  867. list(APPEND EXTRA_LIBS ${AUDIOTOOLBOX})
  868. endif()
  869. # Urho3d - sync with SDL_config_iphoneos.h
  870. if (SDL_SENSOR)
  871. if (IOS) # Intentionally do not let tvOS to go into the block
  872. set(SDL_SENSOR_COREMOTION 1)
  873. set(HAVE_SDL_SENSORS TRUE)
  874. file(GLOB COREMOTION_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/coremotion/*.m)
  875. set(SOURCE_FILES ${SOURCE_FILES} ${COREMOTION_SOURCES})
  876. endif ()
  877. endif ()
  878. # Urho3d - bug fix - make it work for iOS/tvOS platform
  879. if(SDL_VIDEO)
  880. if (VIDEO_COCOA)
  881. # Urho3D - these are moved from commented CheckCOCOA macro
  882. set(SDL_VIDEO_DRIVER_COCOA 1)
  883. file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
  884. set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
  885. set(HAVE_SDL_VIDEO TRUE)
  886. elseif (IOS OR TVOS)
  887. set (SDL_VIDEO_DRIVER_UIKIT 1)
  888. file (GLOB UIKIT_SOURCES ${SDL2_SOURCE_DIR}/src/video/uikit/*.m)
  889. set (SOURCE_FILES ${SOURCE_FILES} ${UIKIT_SOURCES})
  890. set (HAVE_SDL_VIDEO TRUE)
  891. endif ()
  892. if (IOS OR TVOS)
  893. set (SDL_VIDEO_OPENGL_ES 1)
  894. set (SDL_VIDEO_OPENGL_ES2 1)
  895. set (SDL_VIDEO_RENDER_OGL_ES 1)
  896. set (SDL_VIDEO_RENDER_OGL_ES2 1)
  897. set (HAVE_VIDEO_OPENGLES TRUE)
  898. # Urho3D - Metal supported on 64-bit devices running iOS 8.0 and tvOS 9.0 and newer
  899. CHECK_C_SOURCE_COMPILES ("
  900. #if (__IPHONE_OS_VERSION_MIN_REQUIRED < 80000) || (__TV_OS_VERSION_MIN_REQUIRED < 90000)
  901. #error Metal doesn't work on this target platform
  902. #endif
  903. int main()
  904. {
  905. return 0;
  906. }
  907. " PASSED_METAL_CHECKS)
  908. if (PASSED_METAL_CHECKS)
  909. set (SDL_VIDEO_RENDER_METAL 1)
  910. else ()
  911. set (VIDEO_VULKAN OFF)
  912. endif ()
  913. else ()
  914. CheckOpenGL ()
  915. CheckOpenGLES ()
  916. endif ()
  917. endif()
  918. if (IOS OR TVOS)
  919. # Enable iPhone keyboard support
  920. set (SDL_IPHONE_KEYBOARD 1)
  921. # Enable iOS extended launch screen
  922. set (SDL_IPHONE_LAUNCHSCREEN 1)
  923. # Set max recognized G-force from accelerometer, see src/joystick/uikit/SDL_sysjoystick.m for notes on why this is needed
  924. set (SDL_IPHONE_MAX_GFORCE 5.0)
  925. endif ()
  926. elseif(HAIKU)
  927. if(SDL_VIDEO)
  928. set(SDL_VIDEO_DRIVER_HAIKU 1)
  929. file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.c)
  930. set(SOURCE_FILES ${SOURCE_FILES} ${HAIKUVIDEO_SOURCES})
  931. set(HAVE_SDL_VIDEO TRUE)
  932. set(SDL_FILESYSTEM_HAIKU 1)
  933. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/haiku/*.cc)
  934. set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  935. set(HAVE_SDL_FILESYSTEM TRUE)
  936. if(SDL_TIMERS)
  937. set(SDL_TIMER_HAIKU 1)
  938. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/haiku/*.c)
  939. set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  940. set(HAVE_SDL_TIMERS TRUE)
  941. endif(SDL_TIMERS)
  942. if(VIDEO_OPENGL)
  943. # TODO: Use FIND_PACKAGE(OpenGL) instead
  944. set(SDL_VIDEO_OPENGL 1)
  945. set(SDL_VIDEO_OPENGL_BGL 1)
  946. set(SDL_VIDEO_RENDER_OGL 1)
  947. list(APPEND EXTRA_LIBS GL)
  948. set(HAVE_VIDEO_OPENGL TRUE)
  949. endif()
  950. endif()
  951. elseif(UNIX) # Urho3D - at this point both UNIX and UNIX_SYS should be equivalent
  952. if(SDL_AUDIO)
  953. if(SYSV5 OR SOLARIS OR HPUX)
  954. set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
  955. file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
  956. set(SOURCE_FILES ${SOURCE_FILES} ${SUN_AUDIO_SOURCES})
  957. set(HAVE_SDL_AUDIO TRUE)
  958. elseif(NETBSD)
  959. set(SDL_AUDIO_DRIVER_NETBSD 1)
  960. file(GLOB NETBSD_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/netbsd/*.c)
  961. set(SOURCE_FILES ${SOURCE_FILES} ${NETBSD_AUDIO_SOURCES})
  962. set(HAVE_SDL_AUDIO TRUE)
  963. elseif(AIX)
  964. set(SDL_AUDIO_DRIVER_PAUDIO 1)
  965. file(GLOB AIX_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/paudio/*.c)
  966. set(SOURCE_FILES ${SOURCE_FILES} ${AIX_AUDIO_SOURCES})
  967. set(HAVE_SDL_AUDIO TRUE)
  968. endif()
  969. CheckOSS()
  970. CheckALSA()
  971. CheckJACK()
  972. CheckPulseAudio()
  973. CheckESD()
  974. CheckARTS()
  975. CheckNAS()
  976. CheckSNDIO()
  977. CheckFusionSound()
  978. CheckLibSampleRate()
  979. endif()
  980. if(SDL_VIDEO)
  981. # Need to check for Raspberry PI first and add platform specific compiler flags, otherwise the test for GLES fails!
  982. CheckRPI()
  983. CheckX11()
  984. CheckDirectFB()
  985. # Urho3D - rename macros
  986. CheckOpenGL()
  987. CheckOpenGLES()
  988. CheckWayland()
  989. CheckVivante()
  990. CheckKMSDRM()
  991. endif()
  992. file(GLOB CORE_UNIX_SOURCES ${SDL2_SOURCE_DIR}/src/core/unix/*.c)
  993. set(SOURCE_FILES ${SOURCE_FILES} ${CORE_UNIX_SOURCES})
  994. if(LINUX)
  995. check_c_source_compiles("
  996. #include <linux/input.h>
  997. #ifndef EVIOCGNAME
  998. #error EVIOCGNAME() ioctl not available
  999. #endif
  1000. int main(int argc, char** argv) {}" HAVE_INPUT_EVENTS)
  1001. check_c_source_compiles("
  1002. #include <linux/kd.h>
  1003. #include <linux/keyboard.h>
  1004. int main(int argc, char **argv)
  1005. {
  1006. struct kbentry kbe;
  1007. kbe.kb_table = KG_CTRL;
  1008. ioctl(0, KDGKBENT, &kbe);
  1009. }" HAVE_INPUT_KD)
  1010. file(GLOB CORE_LINUX_SOURCES ${SDL2_SOURCE_DIR}/src/core/linux/*.c)
  1011. set(SOURCE_FILES ${SOURCE_FILES} ${CORE_LINUX_SOURCES})
  1012. if(HAVE_INPUT_EVENTS)
  1013. set(SDL_INPUT_LINUXEV 1)
  1014. endif()
  1015. if(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
  1016. set(SDL_HAPTIC_LINUX 1)
  1017. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/linux/*.c)
  1018. set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1019. set(HAVE_SDL_HAPTIC TRUE)
  1020. endif()
  1021. if(HAVE_INPUT_KD)
  1022. set(SDL_INPUT_LINUXKD 1)
  1023. endif()
  1024. # Urho3D - bug fix - use find_path() to detect udev's header file instead of check_include_file() because the latter requires the path to header file to be known which is not the case when cross-compiling
  1025. find_path (UDEV_H_INCLUDE_DIRS libudev.h)
  1026. if (UDEV_H_INCLUDE_DIRS)
  1027. set (HAVE_LIBUDEV_H TRUE)
  1028. include_directories (SYSTEM ${UDEV_H_INCLUDE_DIRS})
  1029. # TODO: find the shared library and store the result in the SDL_UDEV_DYNAMIC variable
  1030. endif ()
  1031. # Urho3D - bug fix - dbus/dbus.h is installed under path suffix 'dbus-1.0', so the following find_path() is needed even when not cross-compiling
  1032. find_path (DBUS_H_INCLUDE_DIRS NAMES dbus/dbus.h PATH_SUFFIXES dbus-1.0)
  1033. # Cater for both multilib and multiarch, native and cross-compiling build
  1034. if (URHO3D_64BIT)
  1035. set (DBUS_INC_SEARCH_PATH /usr/lib64/dbus-1.0/include /usr/lib/x86_64-linux-gnu/dbus-1.0/include)
  1036. else ()
  1037. set (DBUS_INC_SEARCH_PATH /usr/lib/dbus-1.0/include /usr/lib/i386-linux-gnu/dbus-1.0/include)
  1038. endif ()
  1039. find_path (DBUS_ARCH_DEPS_H_INCLUDE_DIRS NAMES dbus/dbus-arch-deps.h PATHS ${DBUS_INC_SEARCH_PATH} /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/dbus-1.0/include)
  1040. if (DBUS_H_INCLUDE_DIRS AND DBUS_H_INCLUDE_DIRS AND DBUS_ARCH_DEPS_H_INCLUDE_DIRS)
  1041. set(HAVE_DBUS_DBUS_H TRUE)
  1042. include_directories (SYSTEM ${DBUS_H_INCLUDE_DIRS} ${DBUS_ARCH_DEPS_H_INCLUDE_DIRS})
  1043. list(APPEND EXTRA_LIBS dbus-1)
  1044. endif ()
  1045. # Urho3D - bug fix - ibus.h is installed under path suffix 'ibus-1.0', so the following find_path() is needed even when not cross-compiling
  1046. find_path (IBUS_H_INCLUDE_DIRS NAMES ibus.h PATH_SUFFIXES ibus-1.0)
  1047. find_path (GLIB_H_INCLUDE_DIRS NAMES glib.h PATH_SUFFIXES glib-2.0)
  1048. if (URHO3D_64BIT)
  1049. set (GLIB_INC_SEARCH_PATH /usr/lib64/glib-2.0/include /usr/lib/x86_64-linux-gnu/glib-2.0/include)
  1050. else ()
  1051. set (GLIB_INC_SEARCH_PATH /usr/lib/glib-2.0/include /usr/lib/i386-linux-gnu/glib-2.0/include)
  1052. endif ()
  1053. find_path (GLIB_CONFIG_H_INCLUDE_DIRS NAMES glibconfig.h PATHS ${GLIB_INC_SEARCH_PATH} /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/glib-2.0/include)
  1054. if (IBUS_H_INCLUDE_DIRS AND GLIB_H_INCLUDE_DIRS AND GLIB_CONFIG_H_INCLUDE_DIRS)
  1055. set(HAVE_IBUS_IBUS_H TRUE)
  1056. include_directories(SYSTEM ${IBUS_H_INCLUDE_DIRS} ${GLIB_H_INCLUDE_DIRS} ${GLIB_CONFIG_H_INCLUDE_DIRS})
  1057. list(APPEND EXTRA_LIBS ibus-1.0)
  1058. set (SDL_USE_IME 1)
  1059. endif ()
  1060. # Urho3D - comment out HAVE_LIBUNWIND_H check as it is always false in our case
  1061. # Urho3D - bug fix - use find_path() to detect fcitx's header file so it works for both native and cross-compiling builds
  1062. find_path (FCITX_H_INCLUDE_DIRS fcitx/frontend.h)
  1063. if (FCITX_H_INCLUDE_DIRS)
  1064. set (HAVE_FCITX_FRONTEND_H TRUE)
  1065. include_directories (SYSTEM ${FCITX_H_INCLUDE_DIRS})
  1066. set (SDL_USE_IME 1)
  1067. endif ()
  1068. # Urho3D - bug fix - moved below logic from generic Unix block to Linux-specific block
  1069. if(SDL_POWER)
  1070. set(SDL_POWER_LINUX 1)
  1071. file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/linux/*.c)
  1072. set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
  1073. set(HAVE_SDL_POWER TRUE)
  1074. endif()
  1075. endif()
  1076. if(INPUT_TSLIB)
  1077. # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" compiler flag or use CMAKE_REQUIRED_INCLUDES (e.g. on RPI) to cater for it
  1078. set (CMAKE_REQUIRED_INCLUDES_TSLIB_SAVED ${CMAKE_REQUIRED_INCLUDES})
  1079. if (CMAKE_CROSSCOMPILING AND NOT "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}" MATCHES --sysroot)
  1080. find_path (TSLIB_H_INCLUDE_DIRS NAMES tslib.h)
  1081. if (TSLIB_H_INCLUDE_DIRS)
  1082. # Assume the header search path has not been adjusted elsewhere yet, there is no harm anyway when a same entry is added twice into the list
  1083. list (APPEND CMAKE_REQUIRED_INCLUDES ${TSLIB_H_INCLUDE_DIRS})
  1084. endif ()
  1085. endif ()
  1086. check_include_file (tslib.h HAVE_INPUT_TSLIB)
  1087. if(HAVE_INPUT_TSLIB)
  1088. set(SDL_INPUT_TSLIB 1)
  1089. list(APPEND EXTRA_LIBS ts)
  1090. endif()
  1091. set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_TSLIB_SAVED})
  1092. endif()
  1093. if(SDL_JOYSTICK)
  1094. CheckUSBHID() # seems to be BSD specific - limit the test to BSD only?
  1095. CheckHIDAPI()
  1096. if(LINUX)
  1097. # Urho3D - get the cue from how the hidapi is setup on other platforms
  1098. if (HAVE_HIDAPI)
  1099. list (APPEND SOURCE_FILES ${SDL2_SOURCE_DIR}/src/hidapi/linux/hid.c ${SDL2_SOURCE_DIR}/src/hidapi/linux/hid.cpp ${SDL2_SOURCE_DIR}/src/hidapi/linux/hidraw.cpp)
  1100. endif ()
  1101. set(SDL_JOYSTICK_LINUX 1)
  1102. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
  1103. set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1104. set(HAVE_SDL_JOYSTICK TRUE)
  1105. endif()
  1106. endif()
  1107. # Urho3D - move CLOCK_GETTIME detection logic to compiler option evaluation section above
  1108. # Urho3D - commented out setting of HAVE_LINUX_VERSION_H compiler define via cflags as that define is not being used at all, besides we prefer add_definitions()
  1109. # Urho3D - bug fix - do not use Unix filesystem for Android platform (Android platform should not be reaching this if-else block now)
  1110. if(SDL_FILESYSTEM)
  1111. set(SDL_FILESYSTEM_UNIX 1)
  1112. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/unix/*.c)
  1113. set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1114. set(HAVE_SDL_FILESYSTEM TRUE)
  1115. endif()
  1116. # Urho3D - move Unix timer to general section above as it can be used for a number of Unix-like platforms
  1117. if(RPATH)
  1118. set(SDL_RLD_FLAGS "")
  1119. if(BSDI OR FREEBSD OR LINUX OR NETBSD)
  1120. set(CMAKE_REQUIRED_FLAGS "-Wl,--enable-new-dtags ${ORIG_CMAKE_REQUIRED_FLAGS}")
  1121. check_c_compiler_flag("" HAVE_ENABLE_NEW_DTAGS)
  1122. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  1123. if(HAVE_ENABLE_NEW_DTAGS)
  1124. set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir} -Wl,--enable-new-dtags")
  1125. else()
  1126. set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir}")
  1127. endif()
  1128. elseif(SOLARIS)
  1129. set(SDL_RLD_FLAGS "-R\${libdir}")
  1130. endif()
  1131. # Urho3D - commented out RPATH setup as we have configured ours globally
  1132. set(HAVE_RPATH TRUE)
  1133. endif()
  1134. elseif(WINDOWS)
  1135. # Urho3D - bug fix - when using MinGW in cross-compiling build, the windres tool is being prefixed as other GCC cross-compiling tools
  1136. if (MINGW)
  1137. if (CMAKE_CROSSCOMPILING)
  1138. set (WINDRES ${CMAKE_RC_COMPILER}) # The CMAKE_RC_COMPILER variable is already initialized in our CMake/MinGW toolchain file
  1139. else ()
  1140. find_program(WINDRES windres)
  1141. endif ()
  1142. endif ()
  1143. # Urho3D - replace the windows.h check by using check_include_file() instead of check_c_source_files()
  1144. check_include_file (windows.h HAVE_WIN32_CC)
  1145. file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
  1146. set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
  1147. # Urho3D - commented out MSVC-specific compiler flags setup as we have configured MSVC compiler flags globally in Urho3D common module
  1148. # Check for DirectX
  1149. if(DIRECTX)
  1150. # Urho3D - bug fix - use our own FindDirectX.cmake module which does not rely on DXSDK_DIR environment variable directly when DirectX SDK is being used
  1151. # Urho3D - TODO - move the find_package(DirectX) call from Urho3D common module to here later after we have refactored the library dependency handling
  1152. endif()
  1153. # headers needed elsewhere ...
  1154. check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
  1155. check_include_file(audioclient.h HAVE_AUDIOCLIENT_H)
  1156. check_include_file(endpointvolume.h HAVE_ENDPOINTVOLUME_H)
  1157. if(SDL_AUDIO)
  1158. set(SDL_AUDIO_DRIVER_WINMM 1)
  1159. file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c)
  1160. set(SOURCE_FILES ${SOURCE_FILES} ${WINMM_AUDIO_SOURCES})
  1161. set(HAVE_SDL_AUDIO TRUE)
  1162. if(HAVE_DSOUND_H)
  1163. set(SDL_AUDIO_DRIVER_DSOUND 1)
  1164. file(GLOB DSOUND_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/directsound/*.c)
  1165. set(SOURCE_FILES ${SOURCE_FILES} ${DSOUND_AUDIO_SOURCES})
  1166. endif()
  1167. if(WASAPI AND HAVE_AUDIOCLIENT_H AND HAVE_MMDEVICEAPI_H)
  1168. set(SDL_AUDIO_DRIVER_WASAPI 1)
  1169. file(GLOB WASAPI_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/wasapi/*.c)
  1170. set(SOURCE_FILES ${SOURCE_FILES} ${WASAPI_AUDIO_SOURCES})
  1171. endif()
  1172. endif()
  1173. if(SDL_VIDEO)
  1174. # requires SDL_LOADSO on Windows (IME, DX, etc.)
  1175. if(NOT SDL_LOADSO)
  1176. message_error("SDL_VIDEO requires SDL_LOADSO, which is not enabled")
  1177. endif()
  1178. set(SDL_VIDEO_DRIVER_WINDOWS 1)
  1179. file(GLOB WIN_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/windows/*.c)
  1180. set(SOURCE_FILES ${SOURCE_FILES} ${WIN_VIDEO_SOURCES})
  1181. if(RENDER_D3D AND HAVE_D3D_H)
  1182. set(SDL_VIDEO_RENDER_D3D 1)
  1183. set(HAVE_RENDER_D3D TRUE)
  1184. endif()
  1185. if(RENDER_D3D AND HAVE_D3D11_H)
  1186. set(SDL_VIDEO_RENDER_D3D11 1)
  1187. set(HAVE_RENDER_D3D TRUE)
  1188. endif()
  1189. set(HAVE_SDL_VIDEO TRUE)
  1190. # Urho3D - bug fix - we are going to need this later when we refactor the library dependency handling
  1191. list (APPEND EXTRA_LIBS ${DIRECT3D_LIBRARIES}) # Empty when none of the D3D components is used
  1192. endif()
  1193. if(SDL_THREADS)
  1194. set(SDL_THREAD_WINDOWS 1)
  1195. set(SOURCE_FILES ${SOURCE_FILES}
  1196. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_sysmutex.c
  1197. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_syssem.c
  1198. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systhread.c
  1199. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systls.c
  1200. ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c)
  1201. set(HAVE_SDL_THREADS TRUE)
  1202. endif()
  1203. if(SDL_POWER)
  1204. set(SDL_POWER_WINDOWS 1)
  1205. set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/power/windows/SDL_syspower.c)
  1206. set(HAVE_SDL_POWER TRUE)
  1207. endif()
  1208. if(SDL_FILESYSTEM)
  1209. set(SDL_FILESYSTEM_WINDOWS 1)
  1210. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/windows/*.c)
  1211. set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1212. set(HAVE_SDL_FILESYSTEM TRUE)
  1213. endif()
  1214. # Libraries for Win32 native and MinGW
  1215. list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 setupapi shell32)
  1216. # TODO: in configure.ac the check for timers is set on
  1217. # cygwin | mingw32* - does this include mingw32CE?
  1218. if(SDL_TIMERS)
  1219. set(SDL_TIMER_WINDOWS 1)
  1220. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/windows/*.c)
  1221. set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1222. set(HAVE_SDL_TIMERS TRUE)
  1223. endif()
  1224. if(SDL_LOADSO)
  1225. set(SDL_LOADSO_WINDOWS 1)
  1226. file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/windows/*.c)
  1227. set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
  1228. set(HAVE_SDL_LOADSO TRUE)
  1229. endif()
  1230. file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
  1231. set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
  1232. if(SDL_VIDEO)
  1233. if(VIDEO_OPENGL)
  1234. set(SDL_VIDEO_OPENGL 1)
  1235. set(SDL_VIDEO_OPENGL_WGL 1)
  1236. set(SDL_VIDEO_RENDER_OGL 1)
  1237. set(HAVE_VIDEO_OPENGL TRUE)
  1238. endif()
  1239. if(VIDEO_OPENGLES)
  1240. set(SDL_VIDEO_OPENGL_EGL 1)
  1241. set(SDL_VIDEO_OPENGL_ES2 1)
  1242. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  1243. set(HAVE_VIDEO_OPENGLES TRUE)
  1244. endif()
  1245. endif()
  1246. if(SDL_JOYSTICK)
  1247. CheckHIDAPI()
  1248. if(HAVE_HIDAPI)
  1249. set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/windows/hid.c)
  1250. endif()
  1251. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/windows/*.c)
  1252. set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1253. if(HAVE_DINPUT_H)
  1254. set(SDL_JOYSTICK_DINPUT 1)
  1255. list(APPEND EXTRA_LIBS dinput8)
  1256. if(MINGW)
  1257. list(APPEND EXTRA_LIBS dxerr8)
  1258. elseif (NOT USE_WINSDK_DIRECTX)
  1259. list(APPEND EXTRA_LIBS dxerr)
  1260. endif()
  1261. endif()
  1262. if(HAVE_XINPUT_H)
  1263. set(SDL_JOYSTICK_XINPUT 1)
  1264. endif()
  1265. if(NOT HAVE_DINPUT_H AND NOT HAVE_XINPUT_H)
  1266. set(SDL_JOYSTICK_WINMM 1)
  1267. endif()
  1268. set(HAVE_SDL_JOYSTICK TRUE)
  1269. if(SDL_HAPTIC)
  1270. if(HAVE_DINPUT_H OR HAVE_XINPUT_H)
  1271. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/windows/*.c)
  1272. if(HAVE_DINPUT_H)
  1273. set(SDL_HAPTIC_DINPUT 1)
  1274. endif()
  1275. if(HAVE_XINPUT_H)
  1276. set(SDL_HAPTIC_XINPUT 1)
  1277. endif()
  1278. else()
  1279. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  1280. set(SDL_HAPTIC_DUMMY 1)
  1281. endif()
  1282. set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1283. set(HAVE_SDL_HAPTIC TRUE)
  1284. endif()
  1285. endif()
  1286. # Urho3D - commented out adding main entry point for Windows platform
  1287. # Urho3D - commented out '-mwindows' linker flags setup as it appears to be automatically added by CMake; also commented out 'mingw32' library dependency as it does not appear to be needed, at least that the case for MinGW
  1288. endif()
  1289. if(VIDEO_VULKAN)
  1290. set(SDL_VIDEO_VULKAN 1)
  1291. set(HAVE_VIDEO_VULKAN TRUE)
  1292. endif()
  1293. # Dummies
  1294. # configure.ac does it differently:
  1295. # if not have X
  1296. # if enable_X { SDL_X_DISABLED = 1 }
  1297. # [add dummy sources]
  1298. # so it always adds a dummy, without checking, if it was actually requested.
  1299. # This leads to missing internal references on building, since the
  1300. # src/X/*.c does not get included.
  1301. if(NOT HAVE_SDL_JOYSTICK)
  1302. set(SDL_JOYSTICK_DUMMY 1)
  1303. if(SDL_JOYSTICK AND NOT APPLE) # results in unresolved symbols on OSX
  1304. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dummy/*.c)
  1305. set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1306. endif()
  1307. endif()
  1308. if(NOT HAVE_SDL_HAPTIC)
  1309. set(SDL_HAPTIC_DUMMY 1)
  1310. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  1311. set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1312. endif()
  1313. if(NOT HAVE_SDL_SENSORS)
  1314. set(SDL_SENSOR_DUMMY 1)
  1315. file(GLOB SENSORS_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/dummy/*.c)
  1316. set(SOURCE_FILES ${SOURCE_FILES} ${SENSORS_SOURCES})
  1317. endif()
  1318. if(NOT HAVE_SDL_LOADSO)
  1319. set(SDL_LOADSO_DISABLED 1)
  1320. file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
  1321. set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
  1322. endif()
  1323. if(NOT HAVE_SDL_FILESYSTEM)
  1324. set(SDL_FILESYSTEM_DISABLED 1)
  1325. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c)
  1326. set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1327. endif()
  1328. # We always need to have threads and timers around
  1329. if(NOT HAVE_SDL_THREADS)
  1330. set(SDL_THREADS_DISABLED 1)
  1331. file(GLOB THREADS_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/*.c)
  1332. set(SOURCE_FILES ${SOURCE_FILES} ${THREADS_SOURCES})
  1333. endif()
  1334. if(NOT HAVE_SDL_TIMERS)
  1335. set(SDL_TIMERS_DISABLED 1)
  1336. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/dummy/*.c)
  1337. set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1338. endif()
  1339. # Urho3D - commented out inclusion of dummy main
  1340. # Append the -MMD -MT flags
  1341. # if(DEPENDENCY_TRACKING)
  1342. # if(COMPILER_IS_GNUCC)
  1343. # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MMD -MT \$@")
  1344. # endif()
  1345. # endif()
  1346. # Urho3D - use 'generated' path suffix for generated config header file (need the suffix as we support both out-of-source and non out-of-source build tree)
  1347. configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
  1348. "${SDL2_BINARY_DIR}/include/generated/SDL_config.h")
  1349. # Prepare the flags and remove duplicates
  1350. if(EXTRA_LDFLAGS)
  1351. list(REMOVE_DUPLICATES EXTRA_LDFLAGS)
  1352. endif()
  1353. if(EXTRA_LIBS)
  1354. list(REMOVE_DUPLICATES EXTRA_LIBS)
  1355. endif()
  1356. if(EXTRA_CFLAGS)
  1357. list(REMOVE_DUPLICATES EXTRA_CFLAGS)
  1358. endif()
  1359. listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
  1360. set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
  1361. # Compat helpers for the configuration files
  1362. if(NOT WINDOWS OR CYGWIN)
  1363. # Urho3D - commeted out the call to updaterev.sh script as it won't work on any platform as it assumes hg to be the version source control which is not true in our case
  1364. set(prefix ${CMAKE_INSTALL_PREFIX})
  1365. set(exec_prefix "\${prefix}")
  1366. set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
  1367. set(bindir "\${exec_prefix}/bin")
  1368. set(includedir "\${prefix}/include")
  1369. if(SDL_STATIC)
  1370. set(ENABLE_STATIC_TRUE "")
  1371. set(ENABLE_STATIC_FALSE "#")
  1372. else()
  1373. set(ENABLE_STATIC_TRUE "#")
  1374. set(ENABLE_STATIC_FALSE "")
  1375. endif()
  1376. if(SDL_SHARED)
  1377. set(ENABLE_SHARED_TRUE "")
  1378. set(ENABLE_SHARED_FALSE "#")
  1379. else()
  1380. set(ENABLE_SHARED_TRUE "#")
  1381. set(ENABLE_SHARED_FALSE "")
  1382. endif()
  1383. # Clean up the different lists
  1384. listtostr(EXTRA_LIBS _EXTRA_LIBS "-l")
  1385. set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
  1386. list(REMOVE_DUPLICATES SDL_STATIC_LIBS)
  1387. listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS)
  1388. set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS})
  1389. listtostr(SDL_LIBS _SDL_LIBS)
  1390. set(SDL_LIBS ${_SDL_LIBS})
  1391. # Urho3D - commented out pkg-config configuration file generation
  1392. # Urho3D - TODO - utilize the populated variables for pkg-config configuration file generation for Urho3D.pc
  1393. endif()
  1394. # Urho3D - restore the original CMake global settings
  1395. set (CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  1396. set (CMAKE_REQUIRED_INCLUDES ${ORIG_CMAKE_REQUIRED_INCLUDES})
  1397. set (CMAKE_REQUIRED_LIBRARIES ${ORIG_CMAKE_REQUIRED_LIBRARIES})
  1398. # Urho3D - only echo the status once during initial configuration
  1399. if (NOT SDL_INFO_ECHOED_STATUS)
  1400. set (SDL_INFO_ECHOED_STATUS TRUE CACHE INTERNAL "SDL info echoed status")
  1401. ##### Info output #####
  1402. message(STATUS "")
  1403. message(STATUS "SDL2 was configured with the following options:")
  1404. message(STATUS "")
  1405. message(STATUS "Platform: ${CMAKE_SYSTEM}")
  1406. message(STATUS "64-bit: ${ARCH_64}")
  1407. message(STATUS "Compiler: ${CMAKE_C_COMPILER}")
  1408. message(STATUS "")
  1409. message(STATUS "Subsystems:")
  1410. foreach(_SUB ${SDL_SUBSYSTEMS})
  1411. string(TOUPPER ${_SUB} _OPT)
  1412. # Urho3D - use the same amount of spaces for padding
  1413. string(LENGTH ${_SUB} _SUBLEN)
  1414. math(EXPR _PADLEN "11 - ${_SUBLEN}")
  1415. string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
  1416. message_bool_option(${_SUB} SDL_${_OPT} ${_PADDING})
  1417. endforeach()
  1418. message(STATUS "")
  1419. message(STATUS "Options:")
  1420. list(SORT ALLOPTIONS)
  1421. foreach(_OPT ${ALLOPTIONS})
  1422. # Longest option is VIDEO_X11_XSCREENSAVER = 22 characters
  1423. # Get the padding
  1424. string(LENGTH ${_OPT} _OPTLEN)
  1425. math(EXPR _PADLEN "23 - ${_OPTLEN}")
  1426. string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
  1427. message_tested_option(${_OPT} ${_PADDING})
  1428. endforeach()
  1429. message(STATUS "")
  1430. message(STATUS " CFLAGS: ${CMAKE_C_FLAGS}")
  1431. message(STATUS " EXTRA_CFLAGS: ${EXTRA_CFLAGS}")
  1432. message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS}")
  1433. message(STATUS " EXTRA_LIBS: ${EXTRA_LIBS}")
  1434. message(STATUS "")
  1435. # Urho3D - commented out messages informing user to set the CFLAGS and LDFLAGS environment variables to workaround detection problems, our modified version does not support that
  1436. endif (NOT SDL_INFO_ECHOED_STATUS)
  1437. # Ensure that the extra cflags are used at compile time
  1438. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
  1439. # Urho3D - commented out targets defined by original CMakeLists.txt, instead we setup our own target that meets our own needs
  1440. # Urho3D - anything below this line is Urho3D specific
  1441. # Define target name
  1442. set (TARGET_NAME SDL)
  1443. # Define source files
  1444. file (GLOB H_FILES include/*.h) # Adding the headers into source files list is just for easier file browsing in the IDE
  1445. list (APPEND SOURCE_FILES ${H_FILES})
  1446. # Setup target as STATIC library (as the result we never use EXTRA_LDFLAGS linker flags)
  1447. setup_library ()
  1448. # Install headers for building and using the Urho3D library (install dependency for InputEvents.h)
  1449. install_header_files (DIRECTORY include/ DESTINATION ${DEST_INCLUDE_DIR}/ThirdParty/SDL FILES_MATCHING PATTERN *.h USE_FILE_SYMLINK) # Note: the trailing slash is significant
  1450. install_header_files (FILES ${SDL2_BINARY_DIR}/include/generated/SDL_config.h DESTINATION ${DEST_INCLUDE_DIR}/ThirdParty/SDL)