CMakeLists.txt 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  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 by Yao Wei Tjong for Urho3D, the modified portion is licensed under below license
  22. #
  23. # Copyright (c) 2008-2017 the Urho3D project.
  24. #
  25. # Permission is hereby granted, free of charge, to any person obtaining a copy
  26. # of this software and associated documentation files (the "Software"), to deal
  27. # in the Software without restriction, including without limitation the rights
  28. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  29. # copies of the Software, and to permit persons to whom the Software is
  30. # furnished to do so, subject to the following conditions:
  31. #
  32. # The above copyright notice and this permission notice shall be included in
  33. # all copies or substantial portions of the Software.
  34. #
  35. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  36. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  37. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  38. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  39. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  40. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  41. # THE SOFTWARE.
  42. #
  43. # Urho3D - commented out in-source tree build prevention as Urho3D supports both out-of-source and in-source tree builds
  44. # Urho3D - commented out setting SDL2 as project name as we want SDL sub-library to remain within Urho3D "umbrella" project
  45. # instead, just enable the required language support and set the extra variables associated with project() command
  46. enable_language (C)
  47. set (SDL2_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  48. set (SDL2_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
  49. # Urho3D - commented out CheckTypeSize, FindPkgConfig, and GNUInstallDirs modules as the corresponding macros are not being used in our modified version
  50. include(CheckFunctionExists)
  51. include(CheckLibraryExists)
  52. include(CheckIncludeFiles)
  53. include(CheckIncludeFile)
  54. include(CheckSymbolExists)
  55. include(CheckCSourceRuns)
  56. include(CheckCCompilerFlag)
  57. include(CheckStructHasMember)
  58. include(CMakeDependentOption)
  59. # 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
  60. include(${SDL2_SOURCE_DIR}/cmake/macros.cmake)
  61. include(${SDL2_SOURCE_DIR}/cmake/sdlchecks.cmake)
  62. # General settings
  63. # Edit include/SDL_version.h and change the version, then:
  64. # SDL_MICRO_VERSION += 1;
  65. # SDL_INTERFACE_AGE += 1;
  66. # SDL_BINARY_AGE += 1;
  67. # if any functions have been added, set SDL_INTERFACE_AGE to 0.
  68. # if backwards compatibility has been broken,
  69. # set SDL_BINARY_AGE and SDL_INTERFACE_AGE to 0.
  70. set(SDL_MAJOR_VERSION 2)
  71. set(SDL_MINOR_VERSION 0)
  72. set(SDL_MICRO_VERSION 5)
  73. set(SDL_INTERFACE_AGE 1)
  74. set(SDL_BINARY_AGE 5)
  75. set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}")
  76. # Calculate a libtool-like version number
  77. math(EXPR LT_CURRENT "${SDL_MICRO_VERSION} - ${SDL_INTERFACE_AGE}")
  78. math(EXPR LT_AGE "${SDL_BINARY_AGE} - ${SDL_INTERFACE_AGE}")
  79. math(EXPR LT_MAJOR "${LT_CURRENT}- ${LT_AGE}")
  80. set(LT_REVISION "${SDL_INTERFACE_AGE}")
  81. set(LT_RELEASE "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}")
  82. set(LT_VERSION "${LT_MAJOR}.${LT_AGE}.${LT_REVISION}")
  83. # Urho3D - commented out debug print
  84. # General settings & flags
  85. # Urho3D - commented out LIBRARY_OUTPUT_DIRECTORY configuration so that it does not mess up with our global configuration setup
  86. # Check for 64 or 32 bit
  87. # 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 ATOMIC_64BIT build option as it also captures the user intention
  88. if(ATOMIC_64BIT)
  89. set(ARCH_64 TRUE)
  90. set(PROCESSOR_ARCH "x64")
  91. else()
  92. set(ARCH_64 FALSE)
  93. set(PROCESSOR_ARCH "x86")
  94. endif()
  95. # Urho3D - commented out redundant CMake variables that do not appear to be used anywhere
  96. # Get the platform
  97. # Urho3D - rearrange the if-elseif blocks (specific case before generic case), simplify the regex, and remove unused variables
  98. if (WIN32)
  99. set(WINDOWS TRUE)
  100. elseif (HAIKU OR ANDROID OR IOS OR TVOS) # IOS/TVOS CMake variables are defined in Urho3D when targeting iOS/tvOS platforms, respectively
  101. # Do nothing here but this should prevent these platforms from entering the more generic case below, i.e.
  102. # - preventing LINUX variable being set for Android (when using older CMake)
  103. # - preventing DARWIN/MACOSX variabe being set for iOS
  104. # - preventing UNIX_SYS variable being set for Haiku
  105. elseif (APPLE)
  106. if (CMAKE_SYSTEM_NAME MATCHES Darwin)
  107. set (DARWIN TRUE)
  108. elseif (CMAKE_SYSTEM_NAME MATCHES MacOS)
  109. set (MACOSX TRUE)
  110. endif ()
  111. elseif (UNIX)
  112. set (UNIX_SYS TRUE)
  113. if (CMAKE_SYSTEM_NAME MATCHES Linux)
  114. set (LINUX TRUE)
  115. elseif (CMAKE_SYSTEM_NAME MATCHES FreeBSD|DragonFly)
  116. set (FREEBSD TRUE)
  117. elseif (CMAKE_SYSTEM_NAME MATCHES NetBSD)
  118. set (NETBSD TRUE)
  119. elseif (CMAKE_SYSTEM_NAME MATCHES OpenBSD)
  120. set (OPENBSD TRUE)
  121. elseif (CMAKE_SYSTEM_NAME MATCHES GNU)
  122. set (GNU TRUE)
  123. elseif (CMAKE_SYSTEM_NAME MATCHES BSDI)
  124. set (BSDI TRUE)
  125. elseif (CMAKE_SYSTEM_NAME MATCHES SYSV5)
  126. set (SYSV5 TRUE)
  127. elseif (CMAKE_SYSTEM_NAME MATCHES Solaris)
  128. set (SOLARIS TRUE)
  129. elseif (CMAKE_SYSTEM_NAME MATCHES HP-UX)
  130. set (HPUX TRUE)
  131. elseif (CMAKE_SYSTEM_NAME MATCHES AIX)
  132. set (AIX TRUE)
  133. elseif (CMAKE_SYSTEM_NAME MATCHES Minix)
  134. set (MINIX TRUE)
  135. elseif (CMAKE_SYSTEM_NAME MATCHES BeOS)
  136. message_error ("BeOS support has been removed as of SDL 2.0.2.")
  137. endif ()
  138. endif()
  139. # Default option knobs
  140. # Urho3D - commented out OPT_DEF_SSEMATH default variable as the underyling SSEMATH build option is also being commented out by us
  141. if(UNIX OR MINGW OR MSYS)
  142. set(OPT_DEF_LIBC ON)
  143. endif()
  144. # Compiler info
  145. if(CMAKE_COMPILER_IS_GNUCC)
  146. set(USE_GCC TRUE)
  147. set(OPT_DEF_ASM TRUE)
  148. elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
  149. set(USE_CLANG TRUE)
  150. set(OPT_DEF_ASM TRUE)
  151. elseif(MSVC_VERSION GREATER 1400) # VisualStudio 8.0+
  152. set(OPT_DEF_ASM TRUE)
  153. #set(CMAKE_C_FLAGS "/ZI /WX- /
  154. else()
  155. set(OPT_DEF_ASM FALSE)
  156. endif()
  157. # Urho3D - commented out compiler/linker flags setup as we have configured all our compiler/linker flags as we want globally
  158. # Those are used for pkg-config and friends, so that the SDL2.pc, sdl2-config, # etc. are created correctly.
  159. # Urho3D - we do not use these variables for pkg-config setup for SDL library but we may need them later for Urho3D library
  160. set (SDL_LIBS)
  161. set (SDL_CFLAGS)
  162. # Emscripten toolchain has a nonempty default value for this, and the checks
  163. # in this file need to change that, so remember the original value, and
  164. # restore back to that afterwards. For check_function_exists() to work in
  165. # Emscripten, this value must be at its default value.
  166. # 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
  167. set (ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
  168. # Urho3D - save the original CMake global settings, do not leave them to chances
  169. set (ORIG_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
  170. set (ORIG_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
  171. if (RPI)
  172. # Urho3D - TODO - move the find_package(VideoCore REQUIRED) call from Urho3D common module to here later after we have refactored the library dependency handling
  173. # Urho3D - bug fix - adjust the header search path for subsequent pthread, EGL and OpenGLES2 checks
  174. list (APPEND CMAKE_REQUIRED_INCLUDES ${VIDEOCORE_INCLUDE_DIRS})
  175. endif ()
  176. if(CYGWIN)
  177. # We build SDL on cygwin without the UNIX emulation layer
  178. # Urho3D - bug fix - we do not support Cygwin build so this fix is untested, just for completeness sake
  179. include_directories(/usr/include/mingw)
  180. set(CMAKE_REQUIRED_FLAGS "-mno-cygwin ${ORIG_CMAKE_REQUIRED_FLAGS}")
  181. check_c_source_compiles("int main(int argc, char **argv) {}"
  182. HAVE_GCC_NO_CYGWIN)
  183. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  184. if(HAVE_GCC_NO_CYGWIN)
  185. list(APPEND EXTRA_LDFLAGS "-mno-cygwin")
  186. list(APPEND SDL_LIBS "-mno-cygwin")
  187. endif()
  188. set(SDL_CFLAGS "${SDL_CFLAGS} -I/usr/include/mingw")
  189. endif()
  190. add_definitions(-DUSING_GENERATED_CONFIG_H)
  191. # General includes
  192. # 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
  193. set (INCLUDE_DIRS ${SDL2_BINARY_DIR}/include/generated ${SDL2_SOURCE_DIR}/include)
  194. # ATOMIC BEGIN
  195. # Install dependency for SDL_android_main.c
  196. if (ANDROID)
  197. list (APPEND INCLUDE_DIRS src/main/android src src/dynapi)
  198. endif ()
  199. # ATOMIC END
  200. # All these ENABLED_BY_DEFAULT vars will default to ON if not specified, so
  201. # you only need to have a platform override them if they are disabling.
  202. # Urho3D - bug fix - commented out double initialization of the OPT_DEF_ASM variable, it has been initialized properly in "Compiler info" section above
  203. if(EMSCRIPTEN)
  204. # Set up default values for the currently supported set of subsystems:
  205. # Emscripten/Javascript does not have assembly support, a dynamic library
  206. # loading architecture, low-level CPU inspection or multithreading.
  207. set(OPT_DEF_ASM FALSE)
  208. set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
  209. # Urho3D - leave SDL_ATOMIC and SDL_LOADSO enable for Emscripten
  210. set(SDL_THREADS_ENABLED_BY_DEFAULT OFF)
  211. set(SDL_CPUINFO_ENABLED_BY_DEFAULT OFF)
  212. endif()
  213. # Urho3D - we always build internal sub-libraries as STATIC library type, so this build option is not applicable to us
  214. set (SDL_SHARED_ENABLED_BY_DEFAULT OFF)
  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)
  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, 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(FUSIONSOUND "Use FusionSound audio driver" OFF)
  248. dep_option(FUSIONSOUND_SHARED "Dynamically load fusionsound audio support" ON FUSIONSOUND OFF)
  249. set_option(VIDEO_DUMMY "Use dummy video driver" ON)
  250. set_option(VIDEO_OPENGL "Include OpenGL support" ON)
  251. # Urho3D - hide OpenGLES option from MinGW platform because it does not have the necessary header file to build OpenGLES video driver
  252. dep_option(VIDEO_OPENGLES "Include OpenGL ES support" ON "NOT MINGW" OFF)
  253. # Urho3D - only make PTHREADS option available on UNIX-like platforms
  254. dep_option(PTHREADS "Use POSIX threads for multi-threading" ON UNIX OFF)
  255. dep_option(PTHREADS_SEM "Use pthread semaphores" ON PTHREADS OFF)
  256. # 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
  257. 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
  258. # Urho3D - hide Unix-specific audio driver options from Android platform
  259. dep_option(OSS "Support the OSS audio API" ON UNIX_SYS OFF)
  260. dep_option(ALSA "Support the ALSA audio API" ON UNIX_SYS OFF)
  261. dep_option(ALSA_SHARED "Dynamically load ALSA audio support" ON ALSA OFF)
  262. dep_option(ESD "Support the Enlightened Sound Daemon" ON UNIX_SYS OFF)
  263. dep_option(ESD_SHARED "Dynamically load ESD audio support" ON ESD OFF)
  264. dep_option(PULSEAUDIO "Use PulseAudio" ON UNIX_SYS OFF)
  265. dep_option(PULSEAUDIO_SHARED "Dynamically load PulseAudio support" ON PULSEAUDIO OFF)
  266. dep_option(ARTS "Support the Analog Real Time Synthesizer" ON UNIX_SYS OFF)
  267. dep_option(ARTS_SHARED "Dynamically load aRts audio support" ON ARTS OFF)
  268. dep_option(NAS "Support the NAS audio API" ON UNIX_SYS OFF)
  269. dep_option(NAS_SHARED "Dynamically load NAS audio API" ON NAS OFF)
  270. dep_option(SNDIO "Support the Roar audio API" ON UNIX_SYS OFF)
  271. # Urho3D - commented out RPATH as an option because Urho3D is configured to always use RPATH, so init the variable to always TRUE
  272. set (RPATH TRUE)
  273. # Urho3D - prefer clock_gettime() when it is available
  274. dep_option(CLOCK_GETTIME "Use clock_gettime() instead of gettimeofday()" ON "NOT WINDOWS" OFF)
  275. set_option(INPUT_TSLIB "Use the Touchscreen library for input" ${UNIX_SYS})
  276. dep_option(VIDEO_WAYLAND "Use Wayland video driver" ON UNIX_SYS OFF)
  277. dep_option(WAYLAND_SHARED "Dynamically load Wayland support" ON VIDEO_WAYLAND OFF)
  278. # 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)
  279. dep_option(VIDEO_WAYLAND_QT_TOUCH "QtWayland server support for Wayland video driver" OFF VIDEO_WAYLAND OFF)
  280. # Urho3D - change the VIDEO_MIR default value to FALSE (SDL requires the bleeding edge of MIR version which normal Linux distros do not provide)
  281. dep_option(VIDEO_MIR "Use Mir video driver" OFF UNIX_SYS OFF)
  282. dep_option(MIR_SHARED "Dynamically load Mir support" ON VIDEO_MIR OFF)
  283. # Urho3D - only make VIDEO_RPI option available on Raspberry-Pi platform
  284. dep_option(VIDEO_RPI "Use Raspberry Pi video driver" ON RPI OFF)
  285. # Urho3D - bug fix - make VIDEO_X11 build option available for desktop UNIX (including OSX) only
  286. dep_option(VIDEO_X11 "Use X11 video driver" ON "UNIX_SYS OR APPLE\;NOT RPI AND NOT IOS AND NOT TVOS" OFF)
  287. dep_option(X11_SHARED "Dynamically load X11 support" ON VIDEO_X11 OFF)
  288. foreach(_SUB Xcursor Xinerama XInput Xrandr Xscrnsaver XShape Xvm)
  289. string(TOUPPER "VIDEO_X11_${_SUB}" _OPT)
  290. dep_option(${_OPT} "Enable ${_SUB} support" ON VIDEO_X11 OFF)
  291. endforeach()
  292. # 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
  293. # But we still keep it as an option here because it should be possible to add back the XQuartz support
  294. dep_option(VIDEO_COCOA "Use Cocoa video driver" ON "APPLE AND NOT IOS AND NOT TVOS" OFF)
  295. # Urho3D - only make DIRECTX option available on Windows platform when ATOMIC_OPENGL is enabled, i.e. DIRECTX variable must always be ON (not an option) when ATOMIC_OPENGL is disabled because in this case it must depend on Direct3D which is a component of DirectX
  296. if (WINDOWS)
  297. dep_option(DIRECTX "Use DirectX for Windows audio/video" ON ATOMIC_OPENGL ON)
  298. else ()
  299. set (DIRECTX OFF) # Make it off explicitly when not targeting Windows platform, just in case user passes it in accidentally via CLI
  300. endif ()
  301. # Urho3D - commented out RENDER_D3D as an option to avoid potential conflict with our ATOMIC_OPENGL and ATOMIC_D3D11 build options on Windows platform
  302. # Instead just initialize the variable according to our build options; Urho3D also by default disables the SDL renderer subsystem
  303. if (WINDOWS)
  304. if (ATOMIC_OPENGL)
  305. set (RENDER_D3D FALSE)
  306. else ()
  307. set (RENDER_D3D TRUE)
  308. endif ()
  309. endif ()
  310. set_option(VIDEO_VIVANTE "Use Vivante EGL video driver" ${UNIX_SYS})
  311. # TODO: We should (should we?) respect cmake's ${BUILD_SHARED_LIBS} flag here
  312. # The options below are for compatibility to configure's default behaviour.
  313. set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared version of the library")
  314. set(SDL_STATIC ON CACHE BOOL "Build a static version of the library")
  315. dep_option(SDL_STATIC_PIC "Static version of the library should be built with Position Independent Code" OFF "SDL_STATIC" OFF)
  316. # General source files
  317. set (SOURCE_FILE_PATTERNS
  318. ${SDL2_SOURCE_DIR}/src/*.c
  319. ${SDL2_SOURCE_DIR}/src/atomic/*.c
  320. # Urho3D - we always disable dynamic API, so commented out ${SDL2_SOURCE_DIR}/src/dynapi/*.c
  321. ${SDL2_SOURCE_DIR}/src/libm/*.c
  322. ${SDL2_SOURCE_DIR}/src/stdlib/*.c
  323. ${SDL2_SOURCE_DIR}/src/thread/*.c
  324. ${SDL2_SOURCE_DIR}/src/timer/*.c)
  325. # 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
  326. foreach (_SUB AUDIO CPUINFO EVENTS FILE HAPTIC JOYSTICK POWER RENDER VIDEO)
  327. string (TOLOWER ${_SUB} _DIR)
  328. if (${SDL_${_SUB}})
  329. list (APPEND SOURCE_FILE_PATTERNS ${SDL2_SOURCE_DIR}/src/${_DIR}/*.c)
  330. endif ()
  331. endforeach ()
  332. if (SDL_RENDER)
  333. list (APPEND SOURCE_FILE_PATTERNS ${SDL2_SOURCE_DIR}/src/render/*/*.c) # Recurse one more level
  334. endif ()
  335. file(GLOB SOURCE_FILES ${SOURCE_FILE_PATTERNS})
  336. if(ASSERTIONS STREQUAL "auto")
  337. # Do nada - use optimization settings to determine the assertion level
  338. elseif(ASSERTIONS STREQUAL "disabled")
  339. set(SDL_DEFAULT_ASSERT_LEVEL 0)
  340. elseif(ASSERTIONS STREQUAL "release")
  341. set(SDL_DEFAULT_ASSERT_LEVEL 1)
  342. elseif(ASSERTIONS STREQUAL "enabled")
  343. set(SDL_DEFAULT_ASSERT_LEVEL 2)
  344. elseif(ASSERTIONS STREQUAL "paranoid")
  345. set(SDL_DEFAULT_ASSERT_LEVEL 3)
  346. else()
  347. message_error("unknown assertion level")
  348. endif()
  349. set(HAVE_ASSERTIONS ${ASSERTIONS})
  350. # Compiler option evaluation
  351. if(USE_GCC OR USE_CLANG)
  352. # Check for -Wall first, so later things can override pieces of it.
  353. check_c_compiler_flag(-Wall HAVE_GCC_WALL)
  354. if(HAVE_GCC_WALL)
  355. list(APPEND EXTRA_CFLAGS "-Wall")
  356. if(HAIKU)
  357. # Urho3D - TODO - since we do not support HAIKU for now, we can leave the cflags configuration here
  358. # However, when we do then it must be moved to our common module and/or just commented out
  359. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")
  360. endif()
  361. endif()
  362. check_c_compiler_flag(-Wdeclaration-after-statement HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
  363. if(HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
  364. check_c_compiler_flag(-Werror=declaration-after-statement HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
  365. # 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
  366. if(HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT AND NOT ANDROID)
  367. list(APPEND EXTRA_CFLAGS "-Werror=declaration-after-statement")
  368. endif()
  369. list(APPEND EXTRA_CFLAGS "-Wdeclaration-after-statement")
  370. endif()
  371. if(DEPENDENCY_TRACKING)
  372. check_c_source_compiles("
  373. #if !defined(__GNUC__) || __GNUC__ < 3
  374. #error Dependency tracking requires GCC 3.0 or newer
  375. #endif
  376. int main(int argc, char **argv) { }" HAVE_DEPENDENCY_TRACKING)
  377. endif()
  378. if(GCC_ATOMICS)
  379. check_c_source_compiles("int main(int argc, char **argv) {
  380. int a;
  381. void *x, *y, *z;
  382. __sync_lock_test_and_set(&a, 4);
  383. __sync_lock_test_and_set(&x, y);
  384. __sync_fetch_and_add(&a, 1);
  385. __sync_bool_compare_and_swap(&a, 5, 10);
  386. __sync_bool_compare_and_swap(&x, y, z); }" HAVE_GCC_ATOMICS)
  387. if(NOT HAVE_GCC_ATOMICS)
  388. check_c_source_compiles("int main(int argc, char **argv) {
  389. int a;
  390. __sync_lock_test_and_set(&a, 1);
  391. __sync_lock_release(&a); }" HAVE_GCC_SYNC_LOCK_TEST_AND_SET)
  392. endif()
  393. endif()
  394. set(CMAKE_REQUIRED_FLAGS "-mpreferred-stack-boundary=2 ${ORIG_CMAKE_REQUIRED_FLAGS}")
  395. check_c_source_compiles("int x = 0; int main(int argc, char **argv) {}"
  396. HAVE_GCC_PREFERRED_STACK_BOUNDARY)
  397. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  398. # Urho3D - we rely on GenerateExportHeader CMake module for configuring GCC/Clang visibility attribute support
  399. check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW)
  400. if(HAVE_GCC_WSHADOW)
  401. list(APPEND EXTRA_CFLAGS "-Wshadow")
  402. endif()
  403. set(CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined ${ORIG_CMAKE_REQUIRED_FLAGS}")
  404. check_c_compiler_flag("" HAVE_NO_UNDEFINED)
  405. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  406. if(HAVE_NO_UNDEFINED)
  407. list(APPEND EXTRA_LDFLAGS "-Wl,--no-undefined")
  408. endif()
  409. endif()
  410. if(ASSEMBLY)
  411. if(USE_GCC OR USE_CLANG)
  412. set(SDL_ASSEMBLY_ROUTINES 1)
  413. # TODO: Those all seem to be quite GCC specific - needs to be
  414. # reworked for better compiler support
  415. set(HAVE_ASSEMBLY TRUE)
  416. # Urho3D - move the altivec, mmx, 3dnow, sse and sse2 checks to Urho3D common module which then configure the compiler flags globally
  417. # 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
  418. # 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
  419. if(ATOMIC_ALTIVEC)
  420. set(SDL_ALTIVEC_BLITTERS 1)
  421. endif()
  422. elseif(MSVC_VERSION GREATER 1500)
  423. # TODO: SDL_cpuinfo.h needs to support the user's configuration wish
  424. # Urho3D - move the HAVE_MMX, HAVE_3DNOW, HAVE_SSE and HAVE_SSE2 initialization to Urho3D common module
  425. set(SDL_ASSEMBLY_ROUTINES 1)
  426. endif()
  427. endif()
  428. # Urho3D - move from Unix platform-specific section below to here
  429. 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
  430. # Urho3D - bug fix - use different variables for different checks because of CMake caches the result variable; this fix the detection on Android platform
  431. check_library_exists(rt clock_gettime "" FOUND_CLOCK_GETTIME_IN_RT)
  432. if(FOUND_CLOCK_GETTIME_IN_RT)
  433. list(APPEND EXTRA_LIBS rt)
  434. set(HAVE_CLOCK_GETTIME 1)
  435. else()
  436. check_library_exists(c clock_gettime "" FOUND_CLOCK_GETTIME_IN_C)
  437. if(FOUND_CLOCK_GETTIME_IN_C)
  438. set(HAVE_CLOCK_GETTIME 1)
  439. endif()
  440. endif()
  441. endif()
  442. # TODO: Can't deactivate on FreeBSD? w/o LIBC, SDL_stdinc.h can't define
  443. # anything.
  444. if(LIBC)
  445. if(WINDOWS AND NOT MINGW)
  446. set(HAVE_LIBC TRUE)
  447. foreach(_HEADER stdio.h string.h ctype.h math.h)
  448. string(TOUPPER "HAVE_${_HEADER}" _UPPER)
  449. string(REPLACE "." "_" _HAVE_H ${_UPPER})
  450. set(${_HAVE_H} 1)
  451. endforeach()
  452. set(HAVE_SIGNAL_H 1)
  453. foreach(_FN
  454. malloc calloc realloc free qsort abs memset memcpy memmove memcmp
  455. strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
  456. _ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp
  457. _stricmp _strnicmp sscanf atan atan2 acos asin ceil copysign cos
  458. cosf fabs floor log pow scalbn sin sinf sqrt sqrtf tan tanf)
  459. string(TOUPPER ${_FN} _UPPER)
  460. set(HAVE_${_UPPER} 1)
  461. endforeach()
  462. if(NOT CYGWIN AND NOT MINGW)
  463. set(HAVE_ALLOCA 1)
  464. endif()
  465. set(HAVE_M_PI 1)
  466. add_definitions(-D_USE_MATH_DEFINES) # needed for M_PI
  467. set(STDC_HEADERS 1)
  468. else()
  469. set(HAVE_LIBC TRUE)
  470. # 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
  471. set (CMAKE_REQUIRED_INCLUDES_SYS_TYPES_SAVED ${CMAKE_REQUIRED_INCLUDES})
  472. if (CMAKE_CROSSCOMPILING AND NOT "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}" MATCHES --sysroot)
  473. find_path (SYS_TYPES_H_INCLUDE_DIRS NAMES sys/types.h)
  474. if (SYS_TYPES_H_INCLUDE_DIRS)
  475. # 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
  476. list (APPEND CMAKE_REQUIRED_INCLUDES ${SYS_TYPES_H_INCLUDE_DIRS})
  477. endif ()
  478. endif ()
  479. check_include_file(sys/types.h HAVE_SYS_TYPES_H)
  480. set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SYS_TYPES_SAVED})
  481. # 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
  482. # 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
  483. # 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
  484. foreach(_HEADER
  485. stdio.h stdlib.h stddef.h stdarg.h malloc.h memory.h string.h
  486. strings.h inttypes.h stdint.h ctype.h math.h iconv.h signal.h)
  487. string(TOUPPER "HAVE_${_HEADER}" _UPPER)
  488. string(REPLACE "." "_" _HAVE_H ${_UPPER})
  489. check_include_file("${_HEADER}" ${_HAVE_H})
  490. endforeach()
  491. # Urho3D - bug fix - MinGW has standard-C headers, except dlfcn.h
  492. set (CHECK_STDC_HEADERS stdint.h stddef.h inttypes.h stdlib.h strings.h string.h float.h)
  493. if (NOT MINGW)
  494. list (APPEND CHECK_STDC_HEADERS dlfcn.h)
  495. endif ()
  496. check_include_files("${CHECK_STDC_HEADERS}" STDC_HEADERS) # Stringify the INCLUDE list variable as this macro does not expect to receive a list
  497. # 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)
  498. check_symbol_exists(M_PI math.h HAVE_M_PI)
  499. # Urho3D - for consistency sake use check_include_file() to check for HAVE_MPROTECT
  500. check_include_file (sys/mman.h HAVE_MPROTECT)
  501. foreach(_FN
  502. strtod malloc calloc realloc free getenv setenv putenv unsetenv
  503. qsort abs bcopy memset memcpy memmove memcmp strlen strlcpy strlcat
  504. strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
  505. _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull
  506. atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp
  507. vsscanf vsnprintf fseeko fseeko64 sigaction setjmp
  508. nanosleep sysconf sysctlbyname
  509. )
  510. string(TOUPPER ${_FN} _UPPER)
  511. set(_HAVEVAR "HAVE_${_UPPER}")
  512. check_function_exists("${_FN}" ${_HAVEVAR})
  513. endforeach()
  514. check_library_exists(m pow "" HAVE_LIBM)
  515. if(HAVE_LIBM)
  516. set(CMAKE_REQUIRED_LIBRARIES m)
  517. foreach(_FN
  518. atan atan2 ceil copysign cos cosf fabs floor log pow scalbn sin
  519. sinf sqrt sqrtf tan tanf acos asin)
  520. string(TOUPPER ${_FN} _UPPER)
  521. set(_HAVEVAR "HAVE_${_UPPER}")
  522. check_function_exists("${_FN}" ${_HAVEVAR})
  523. endforeach()
  524. set(CMAKE_REQUIRED_LIBRARIES)
  525. list(APPEND EXTRA_LIBS m)
  526. endif()
  527. check_library_exists(iconv iconv_open "" HAVE_LIBICONV)
  528. if(HAVE_LIBICONV)
  529. list(APPEND EXTRA_LIBS iconv)
  530. set(HAVE_ICONV 1)
  531. endif()
  532. # 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
  533. check_include_file(alloca.h HAVE_ALLOCA_H)
  534. if (HAVE_ALLOCA_H)
  535. check_c_source_compiles ("
  536. #include <alloca.h>
  537. int main(int argc, char** argv) { alloca(0); }" HAVE_ALLOCA)
  538. endif ()
  539. check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION)
  540. endif()
  541. else()
  542. if(WINDOWS)
  543. set(HAVE_STDARG_H 1)
  544. set(HAVE_STDDEF_H 1)
  545. endif()
  546. endif()
  547. # Enable/disable various subsystems of the SDL library
  548. foreach(_SUB ${SDL_SUBSYSTEMS})
  549. string(TOUPPER ${_SUB} _OPT)
  550. if(NOT SDL_${_OPT})
  551. set(SDL_${_OPT}_DISABLED 1)
  552. endif()
  553. endforeach()
  554. # General SDL subsystem options, valid for all platforms
  555. if(SDL_AUDIO)
  556. if(DUMMYAUDIO)
  557. set(SDL_AUDIO_DRIVER_DUMMY 1)
  558. file(GLOB DUMMYAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dummy/*.c)
  559. set(SOURCE_FILES ${SOURCE_FILES} ${DUMMYAUDIO_SOURCES})
  560. set(HAVE_DUMMYAUDIO TRUE)
  561. endif()
  562. if(DISKAUDIO)
  563. set(SDL_AUDIO_DRIVER_DISK 1)
  564. file(GLOB DISKAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/disk/*.c)
  565. set(SOURCE_FILES ${SOURCE_FILES} ${DISKAUDIO_SOURCES})
  566. set(HAVE_DISKAUDIO TRUE)
  567. endif()
  568. endif()
  569. if(SDL_VIDEO)
  570. if(VIDEO_DUMMY)
  571. set(SDL_VIDEO_DRIVER_DUMMY 1)
  572. file(GLOB VIDEO_DUMMY_SOURCES ${SDL2_SOURCE_DIR}/src/video/dummy/*.c)
  573. set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_DUMMY_SOURCES})
  574. set(HAVE_VIDEO_DUMMY TRUE)
  575. set(HAVE_SDL_VIDEO TRUE)
  576. endif()
  577. endif()
  578. if(SDL_DLOPEN)
  579. # Urho3D - remove duplicate/redundant check as we have already ensure that this build option is made available for the correct platforms only
  580. CheckDLOPEN()
  581. endif()
  582. # Urho3D - move from Unix platform-specifc block to here as this timer implementation is applicable for Android and Emscripten as well
  583. if(SDL_TIMERS AND UNIX AND NOT HAIKU) # Haiku has its own timer implementation, so exclude it explicitly
  584. set(SDL_TIMER_UNIX 1)
  585. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
  586. set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  587. set(HAVE_SDL_TIMERS TRUE)
  588. endif()
  589. if (SDL_THREADS)
  590. CheckPTHREAD()
  591. endif ()
  592. # Platform-specific options and settings
  593. # Urho3D - rearrange the if-elseif blocks (specific case before generic case)
  594. if(ANDROID)
  595. file(GLOB ANDROID_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/android/*.c)
  596. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_CORE_SOURCES})
  597. # Urho3D - bug fix - SDL_android_main.c will be added later when setting up actual Android targets
  598. if(SDL_AUDIO)
  599. set(SDL_AUDIO_DRIVER_ANDROID 1)
  600. file(GLOB ANDROID_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/android/*.c)
  601. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_AUDIO_SOURCES})
  602. set(HAVE_SDL_AUDIO TRUE)
  603. endif()
  604. if(SDL_FILESYSTEM)
  605. set(SDL_FILESYSTEM_ANDROID 1)
  606. file(GLOB ANDROID_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/android/*.c)
  607. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_FILESYSTEM_SOURCES})
  608. set(HAVE_SDL_FILESYSTEM TRUE)
  609. endif()
  610. if(SDL_JOYSTICK)
  611. set(SDL_JOYSTICK_ANDROID 1)
  612. file(GLOB ANDROID_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/android/*.c)
  613. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_JOYSTICK_SOURCES})
  614. set(HAVE_SDL_JOYSTICK TRUE)
  615. endif()
  616. if(SDL_POWER)
  617. set(SDL_POWER_ANDROID 1)
  618. file(GLOB ANDROID_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/android/*.c)
  619. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_POWER_SOURCES})
  620. set(HAVE_SDL_POWER TRUE)
  621. endif()
  622. if(SDL_VIDEO)
  623. set(SDL_VIDEO_DRIVER_ANDROID 1)
  624. file(GLOB ANDROID_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/android/*.c)
  625. set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_VIDEO_SOURCES})
  626. set(HAVE_SDL_VIDEO TRUE)
  627. #enable gles
  628. if(VIDEO_OPENGLES)
  629. CheckOpenGLES()
  630. endif()
  631. endif()
  632. list(APPEND EXTRA_LDFLAGS "-Wl,--undefined=Java_org_libsdl_app_SDLActivity_nativeInit")
  633. elseif(EMSCRIPTEN)
  634. # Hide noisy warnings that intend to aid mostly during initial stages of porting a new
  635. # project. Uncomment at will for verbose cross-compiling -I/../ path info.
  636. add_definitions(-Wno-warn-absolute-paths)
  637. if(SDL_AUDIO)
  638. set(SDL_AUDIO_DRIVER_EMSCRIPTEN 1)
  639. file(GLOB EM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/emscripten/*.c)
  640. set(SOURCE_FILES ${SOURCE_FILES} ${EM_AUDIO_SOURCES})
  641. set(HAVE_SDL_AUDIO TRUE)
  642. endif()
  643. if(SDL_FILESYSTEM)
  644. set(SDL_FILESYSTEM_EMSCRIPTEN 1)
  645. file(GLOB EM_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/emscripten/*.c)
  646. set(SOURCE_FILES ${SOURCE_FILES} ${EM_FILESYSTEM_SOURCES})
  647. set(HAVE_SDL_FILESYSTEM TRUE)
  648. endif()
  649. if(SDL_JOYSTICK)
  650. set(SDL_JOYSTICK_EMSCRIPTEN 1)
  651. file(GLOB EM_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/emscripten/*.c)
  652. set(SOURCE_FILES ${SOURCE_FILES} ${EM_JOYSTICK_SOURCES})
  653. set(HAVE_SDL_JOYSTICK TRUE)
  654. endif()
  655. if(SDL_POWER)
  656. set(SDL_POWER_EMSCRIPTEN 1)
  657. file(GLOB EM_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/emscripten/*.c)
  658. set(SOURCE_FILES ${SOURCE_FILES} ${EM_POWER_SOURCES})
  659. set(HAVE_SDL_POWER TRUE)
  660. endif()
  661. if(SDL_VIDEO)
  662. set(SDL_VIDEO_DRIVER_EMSCRIPTEN 1)
  663. file(GLOB EM_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/emscripten/*.c)
  664. set(SOURCE_FILES ${SOURCE_FILES} ${EM_VIDEO_SOURCES})
  665. set(HAVE_SDL_VIDEO TRUE)
  666. #enable gles
  667. if(VIDEO_OPENGLES)
  668. CheckOpenGLES()
  669. endif()
  670. endif()
  671. elseif(APPLE)
  672. # Requires the darwin file implementation
  673. if(SDL_FILE)
  674. file(GLOB EXTRA_SOURCES ${SDL2_SOURCE_DIR}/src/file/cocoa/*.m)
  675. set(SOURCE_FILES ${EXTRA_SOURCES} ${SOURCE_FILES})
  676. set_source_files_properties(${EXTRA_SOURCES} PROPERTIES LANGUAGE C)
  677. set(HAVE_SDL_FILE TRUE)
  678. set(SDL_FRAMEWORK_COCOA 1)
  679. set(SDL_FRAMEWORK_COREVIDEO 1)
  680. else()
  681. message_error("SDL_FILE must be enabled to build on MacOS X")
  682. endif()
  683. if(SDL_AUDIO)
  684. set(SDL_AUDIO_DRIVER_COREAUDIO 1)
  685. file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.m)
  686. set(SOURCE_FILES ${SOURCE_FILES} ${AUDIO_SOURCES})
  687. set(HAVE_SDL_AUDIO TRUE)
  688. set(SDL_FRAMEWORK_COREAUDIO 1)
  689. set(SDL_FRAMEWORK_AUDIOTOOLBOX 1)
  690. endif()
  691. if(SDL_JOYSTICK)
  692. # Urho3D - bug fix - make it work for iOS/tvOS platform
  693. if (IOS OR TVOS)
  694. set (SDL_JOYSTICK_MFI 1)
  695. file (GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m)
  696. else ()
  697. set(SDL_JOYSTICK_IOKIT 1)
  698. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
  699. set(SDL_FRAMEWORK_IOKIT 1)
  700. set(SDL_FRAMEWORK_FF 1)
  701. endif ()
  702. set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  703. set_source_files_properties(${JOYSTICK_SOURCES} PROPERTIES LANGUAGE C)
  704. set(HAVE_SDL_JOYSTICK TRUE)
  705. endif()
  706. if(SDL_HAPTIC)
  707. # Urho3d - bug fix - make it work for iOS/tvOS platform
  708. if (IOS OR TVOS)
  709. set (SDL_HAPTIC_DUMMY 1)
  710. file (GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  711. else ()
  712. set(SDL_HAPTIC_IOKIT 1)
  713. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/darwin/*.c)
  714. set(SDL_FRAMEWORK_IOKIT 1)
  715. set(SDL_FRAMEWORK_FF 1)
  716. endif ()
  717. set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  718. set(HAVE_SDL_HAPTIC TRUE)
  719. if(NOT SDL_JOYSTICK)
  720. message(FATAL_ERROR "SDL_HAPTIC requires SDL_JOYSTICK to be enabled")
  721. endif()
  722. endif()
  723. if(SDL_POWER)
  724. # Urho3d - bug fix - make it work for iOS/tvOS platform
  725. if (IOS OR TVOS)
  726. set (SDL_POWER_UIKIT 1)
  727. file (GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/uikit/*.m)
  728. else ()
  729. set(SDL_POWER_MACOSX 1)
  730. file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/macosx/*.c)
  731. set(SDL_FRAMEWORK_CARBON 1)
  732. set(SDL_FRAMEWORK_IOKIT 1)
  733. endif ()
  734. set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
  735. set_source_files_properties(${POWER_SOURCES} PROPERTIES LANGUAGE C)
  736. set(HAVE_SDL_POWER TRUE)
  737. endif()
  738. if(SDL_FILESYSTEM)
  739. set(SDL_FILESYSTEM_COCOA 1)
  740. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
  741. set_source_files_properties(${FILESYSTEM_SOURCES} PROPERTIES LANGUAGE C)
  742. set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  743. set(HAVE_SDL_FILESYSTEM TRUE)
  744. endif()
  745. # Actually load the frameworks at the end so we don't duplicate include.
  746. # Urho3D - TODO - this list in complete, do this when we refactor the library dependency handling
  747. if(SDL_FRAMEWORK_COREVIDEO)
  748. find_library(COREVIDEO CoreVideo)
  749. list(APPEND EXTRA_LIBS ${COREVIDEO})
  750. endif()
  751. if(SDL_FRAMEWORK_COCOA)
  752. find_library(COCOA_LIBRARY Cocoa)
  753. list(APPEND EXTRA_LIBS ${COCOA_LIBRARY})
  754. endif()
  755. if(SDL_FRAMEWORK_IOKIT)
  756. find_library(IOKIT IOKit)
  757. list(APPEND EXTRA_LIBS ${IOKIT})
  758. endif()
  759. if(SDL_FRAMEWORK_FF)
  760. find_library(FORCEFEEDBACK ForceFeedback)
  761. list(APPEND EXTRA_LIBS ${FORCEFEEDBACK})
  762. endif()
  763. if(SDL_FRAMEWORK_CARBON)
  764. find_library(CARBON_LIBRARY Carbon)
  765. list(APPEND EXTRA_LIBS ${CARBON_LIBRARY})
  766. endif()
  767. if(SDL_FRAMEWORK_COREAUDIO)
  768. find_library(COREAUDIO CoreAudio)
  769. list(APPEND EXTRA_LIBS ${COREAUDIO})
  770. endif()
  771. if(SDL_FRAMEWORK_AUDIOTOOLBOX)
  772. find_library(AUDIOTOOLBOX AudioToolbox)
  773. list(APPEND EXTRA_LIBS ${AUDIOTOOLBOX})
  774. endif()
  775. # Urho3d - bug fix - make it work for iOS/tvOS platform
  776. if(SDL_VIDEO)
  777. if (VIDEO_COCOA)
  778. # Urho3D - these are moved from commented CheckCOCOA macro
  779. set(SDL_VIDEO_DRIVER_COCOA 1)
  780. file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
  781. set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
  782. set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
  783. set(HAVE_SDL_VIDEO TRUE)
  784. elseif (IOS OR TVOS)
  785. set (SDL_VIDEO_DRIVER_UIKIT 1)
  786. file (GLOB UIKIT_SOURCES ${SDL2_SOURCE_DIR}/src/video/uikit/*.m)
  787. set_source_files_properties (${UIKIT_SOURCES} PROPERTIES LANGUAGE C)
  788. set (SOURCE_FILES ${SOURCE_FILES} ${UIKIT_SOURCES})
  789. set (HAVE_SDL_VIDEO TRUE)
  790. endif ()
  791. if (IOS OR TVOS)
  792. set (SDL_VIDEO_OPENGL_ES 1)
  793. set (SDL_VIDEO_OPENGL_ES2 1)
  794. set (SDL_VIDEO_RENDER_OGL_ES 1)
  795. set (SDL_VIDEO_RENDER_OGL_ES2 1)
  796. set (HAVE_VIDEO_OPENGLES TRUE)
  797. else ()
  798. CheckOpenGL ()
  799. CheckOpenGLES ()
  800. endif ()
  801. endif()
  802. if (IOS OR TVOS)
  803. # Enable iPhone keyboard support
  804. set (SDL_IPHONE_KEYBOARD 1)
  805. # Enable iOS extended launch screen
  806. set (SDL_IPHONE_LAUNCHSCREEN 1)
  807. # Set max recognized G-force from accelerometer, see src/joystick/uikit/SDL_sysjoystick.m for notes on why this is needed
  808. set (SDL_IPHONE_MAX_GFORCE 5.0)
  809. endif ()
  810. elseif(HAIKU)
  811. if(SDL_VIDEO)
  812. set(SDL_VIDEO_DRIVER_HAIKU 1)
  813. file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.c)
  814. set(SOURCE_FILES ${SOURCE_FILES} ${HAIKUVIDEO_SOURCES})
  815. set(HAVE_SDL_VIDEO TRUE)
  816. set(SDL_FILESYSTEM_HAIKU 1)
  817. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/haiku/*.cc)
  818. set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  819. set(HAVE_SDL_FILESYSTEM TRUE)
  820. if(SDL_TIMERS)
  821. set(SDL_TIMER_HAIKU 1)
  822. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/haiku/*.c)
  823. set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  824. set(HAVE_SDL_TIMERS TRUE)
  825. endif(SDL_TIMERS)
  826. if(VIDEO_OPENGL)
  827. # TODO: Use FIND_PACKAGE(OpenGL) instead
  828. set(SDL_VIDEO_OPENGL 1)
  829. set(SDL_VIDEO_OPENGL_BGL 1)
  830. set(SDL_VIDEO_RENDER_OGL 1)
  831. list(APPEND EXTRA_LIBS GL)
  832. set(HAVE_VIDEO_OPENGL TRUE)
  833. endif()
  834. # Urho3D - bug fix - we do not support Haiku platform so this fix is untested, just for completeness sake
  835. if (SDL_LOADSO)
  836. set (SDL_LOADSO_HAIKU 1)
  837. file (GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/haiku/*.c)
  838. set (SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
  839. set (HAVE_SDL_LOADSO TRUE)
  840. endif ()
  841. endif()
  842. elseif(UNIX) # Urho3D - at this point both UNIX and UNIX_SYS should be equivalent
  843. if(SDL_AUDIO)
  844. if(SYSV5 OR SOLARIS OR HPUX)
  845. set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
  846. file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
  847. set(SOURCE_FILES ${SOURCE_FILES} ${SUN_AUDIO_SOURCES})
  848. set(HAVE_SDL_AUDIO TRUE)
  849. elseif(NETBSD OR OPENBSD)
  850. set(SDL_AUDIO_DRIVER_BSD 1)
  851. file(GLOB BSD_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/bsd/*.c)
  852. set(SOURCE_FILES ${SOURCE_FILES} ${BSD_AUDIO_SOURCES})
  853. set(HAVE_SDL_AUDIO TRUE)
  854. elseif(AIX)
  855. set(SDL_AUDIO_DRIVER_PAUDIO 1)
  856. file(GLOB AIX_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/paudio/*.c)
  857. set(SOURCE_FILES ${SOURCE_FILES} ${AIX_AUDIO_SOURCES})
  858. set(HAVE_SDL_AUDIO TRUE)
  859. endif()
  860. CheckOSS()
  861. CheckALSA()
  862. CheckPulseAudio()
  863. CheckESD()
  864. CheckARTS()
  865. CheckNAS()
  866. CheckSNDIO()
  867. CheckFusionSound()
  868. endif()
  869. if(SDL_VIDEO)
  870. # Need to check for Raspberry PI first and add platform specific compiler flags, otherwise the test for GLES fails!
  871. CheckRPI()
  872. CheckX11()
  873. CheckMir()
  874. CheckDirectFB()
  875. # Urho3D - raname macros
  876. CheckOpenGL()
  877. CheckOpenGLES()
  878. CheckWayland()
  879. CheckVivante()
  880. endif()
  881. if(LINUX)
  882. check_c_source_compiles("
  883. #include <linux/input.h>
  884. #ifndef EVIOCGNAME
  885. #error EVIOCGNAME() ioctl not available
  886. #endif
  887. int main(int argc, char** argv) {}" HAVE_INPUT_EVENTS)
  888. check_c_source_compiles("
  889. #include <linux/kd.h>
  890. #include <linux/keyboard.h>
  891. int main(int argc, char **argv)
  892. {
  893. struct kbentry kbe;
  894. kbe.kb_table = KG_CTRL;
  895. ioctl(0, KDGKBENT, &kbe);
  896. }" HAVE_INPUT_KD)
  897. file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/linux/*.c)
  898. set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
  899. if(HAVE_INPUT_EVENTS)
  900. set(SDL_INPUT_LINUXEV 1)
  901. endif()
  902. if(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
  903. set(SDL_HAPTIC_LINUX 1)
  904. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/linux/*.c)
  905. set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  906. set(HAVE_SDL_HAPTIC TRUE)
  907. endif()
  908. if(HAVE_INPUT_KD)
  909. set(SDL_INPUT_LINUXKD 1)
  910. endif()
  911. # 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
  912. find_path (UDEV_H_INCLUDE_DIRS libudev.h)
  913. if (UDEV_H_INCLUDE_DIRS)
  914. set (HAVE_LIBUDEV_H TRUE)
  915. include_directories (SYSTEM ${UDEV_H_INCLUDE_DIRS})
  916. # TODO: find the shared library and store the result in the SDL_UDEV_DYNAMIC variable
  917. endif ()
  918. # 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
  919. find_path (DBUS_H_INCLUDE_DIRS NAMES dbus/dbus.h PATH_SUFFIXES dbus-1.0)
  920. # Cater for both multilib and multiarch, native and cross-compiling build
  921. if (ATOMIC_64BIT)
  922. set (DBUS_INC_SEARCH_PATH /usr/lib64/dbus-1.0/include)
  923. else ()
  924. set (DBUS_INC_SEARCH_PATH /usr/lib/dbus-1.0/include)
  925. endif ()
  926. 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)
  927. if (DBUS_H_INCLUDE_DIRS AND DBUS_H_INCLUDE_DIRS AND DBUS_ARCH_DEPS_H_INCLUDE_DIRS)
  928. set(HAVE_DBUS_DBUS_H TRUE)
  929. include_directories (SYSTEM ${DBUS_H_INCLUDE_DIRS} ${DBUS_ARCH_DEPS_H_INCLUDE_DIRS})
  930. list(APPEND EXTRA_LIBS dbus-1)
  931. endif ()
  932. # 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
  933. find_path (IBUS_H_INCLUDE_DIRS NAMES ibus.h PATH_SUFFIXES ibus-1.0)
  934. find_path (GLIB_H_INCLUDE_DIRS NAMES glib.h PATH_SUFFIXES glib-2.0)
  935. if (ATOMIC_64BIT)
  936. set (GLIB_INC_SEARCH_PATH /usr/lib64/glib-2.0/include)
  937. else ()
  938. set (GLIB_INC_SEARCH_PATH /usr/lib/glib-2.0/include)
  939. endif ()
  940. find_path (GLIB_CONFIG_H_INCLUDE_DIRS NAMES glibconfig.h PATHS ${GLIB_INC_SEARCH_PATH} /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/glib-2.0/include)
  941. if (IBUS_H_INCLUDE_DIRS AND GLIB_H_INCLUDE_DIRS AND GLIB_CONFIG_H_INCLUDE_DIRS)
  942. set(HAVE_IBUS_IBUS_H TRUE)
  943. include_directories(SYSTEM ${IBUS_H_INCLUDE_DIRS} ${GLIB_H_INCLUDE_DIRS} ${GLIB_CONFIG_H_INCLUDE_DIRS})
  944. list(APPEND EXTRA_LIBS ibus-1.0)
  945. set (SDL_USE_IME 1)
  946. endif ()
  947. # Urho3D - bug fix - use find_path() to detect fcitx's header file so it works for both native and cross-compiling builds
  948. find_path (FCITX_H_INCLUDE_DIRS fcitx/frontend.h)
  949. if (FCITX_H_INCLUDE_DIRS)
  950. set (HAVE_FCITX_FRONTEND_H TRUE)
  951. include_directories (SYSTEM ${FCITX_H_INCLUDE_DIRS})
  952. set (SDL_USE_IME 1)
  953. endif ()
  954. # Urho3D - bug fix - moved below logic from generic Unix block to Linux-specific block
  955. if(SDL_POWER)
  956. set(SDL_POWER_LINUX 1)
  957. file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/linux/*.c)
  958. set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
  959. set(HAVE_SDL_POWER TRUE)
  960. endif()
  961. if(SDL_JOYSTICK)
  962. set(SDL_JOYSTICK_LINUX 1)
  963. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c)
  964. set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  965. set(HAVE_SDL_JOYSTICK TRUE)
  966. endif()
  967. else ()
  968. if(SDL_JOYSTICK)
  969. CheckUSBHID() # seems to be BSD specific - limit the test to BSD only?
  970. endif()
  971. endif()
  972. if(INPUT_TSLIB)
  973. # 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
  974. set (CMAKE_REQUIRED_INCLUDES_TSLIB_SAVED ${CMAKE_REQUIRED_INCLUDES})
  975. if (CMAKE_CROSSCOMPILING AND NOT "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}" MATCHES --sysroot)
  976. find_path (TSLIB_H_INCLUDE_DIRS NAMES tslib.h)
  977. if (TSLIB_H_INCLUDE_DIRS)
  978. # 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
  979. list (APPEND CMAKE_REQUIRED_INCLUDES ${TSLIB_H_INCLUDE_DIRS})
  980. endif ()
  981. endif ()
  982. check_include_file (tslib.h HAVE_INPUT_TSLIB)
  983. if(HAVE_INPUT_TSLIB)
  984. set(SDL_INPUT_TSLIB 1)
  985. list(APPEND EXTRA_LIBS ts)
  986. endif()
  987. set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_TSLIB_SAVED})
  988. endif()
  989. # Urho3D - move CLOCK_GETTIME detection logic to compiler option evaluation section above
  990. # 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()
  991. # Urho3D - bug fix - do not use Unix filesystem for Android platform (Android platform should not be reaching this if-else block now)
  992. if(SDL_FILESYSTEM)
  993. set(SDL_FILESYSTEM_UNIX 1)
  994. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/unix/*.c)
  995. set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  996. set(HAVE_SDL_FILESYSTEM TRUE)
  997. endif()
  998. # Urho3D - move Unix timer to general section above as it can be used for a number of Unix-like platforms
  999. if(RPATH)
  1000. set(SDL_RLD_FLAGS "")
  1001. if(BSDI OR FREEBSD OR LINUX OR NETBSD)
  1002. set(CMAKE_REQUIRED_FLAGS "-Wl,--enable-new-dtags ${ORIG_CMAKE_REQUIRED_FLAGS}")
  1003. check_c_compiler_flag("" HAVE_ENABLE_NEW_DTAGS)
  1004. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  1005. if(HAVE_ENABLE_NEW_DTAGS)
  1006. set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir} -Wl,--enable-new-dtags")
  1007. else()
  1008. set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir}")
  1009. endif()
  1010. elseif(SOLARIS)
  1011. set(SDL_RLD_FLAGS "-R\${libdir}")
  1012. endif()
  1013. # Urho3D - commented out RPATH setup as we have configured ours globally
  1014. set(HAVE_RPATH TRUE)
  1015. endif()
  1016. elseif(WINDOWS)
  1017. # Urho3D - bug fix - when using MinGW in cross-compiling build, the windres tool is being prefixed as other GCC cross-compiling tools
  1018. if (MINGW)
  1019. if (CMAKE_CROSSCOMPILING)
  1020. set (WINDRES ${CMAKE_RC_COMPILER}) # The CMAKE_RC_COMPILER variable is already initialized in our CMake/MinGW toolchain file
  1021. else ()
  1022. find_program(WINDRES windres)
  1023. endif ()
  1024. endif ()
  1025. # Urho3D - replace the windows.h check by using check_include_file() instead of check_c_source_files()
  1026. check_include_file (windows.h HAVE_WIN32_CC)
  1027. file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
  1028. set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
  1029. # Urho3D - commented out MSVC-specific compiler flags setup as we have configured MSVC compiler flags globally in Urho3D common module
  1030. # Check for DirectX
  1031. if(DIRECTX)
  1032. # 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
  1033. # Urho3D - TODO - move the find_package(DirectX) call from Urho3D common module to here later after we have refactored the library dependency handling
  1034. check_struct_has_member (XINPUT_GAMEPAD_EX wButtons xinput.h HAVE_XINPUT_GAMEPAD_EX)
  1035. check_struct_has_member (XINPUT_STATE_EX dwPacketNumber xinput.h HAVE_XINPUT_STATE_EX)
  1036. foreach (VAR HAVE_XINPUT_GAMEPAD_EX HAVE_XINPUT_STATE_EX)
  1037. if (${VAR})
  1038. add_definitions (-D${VAR})
  1039. endif ()
  1040. endforeach ()
  1041. endif()
  1042. if(SDL_AUDIO)
  1043. set(SDL_AUDIO_DRIVER_WINMM 1)
  1044. file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c)
  1045. set(SOURCE_FILES ${SOURCE_FILES} ${WINMM_AUDIO_SOURCES})
  1046. set(HAVE_SDL_AUDIO TRUE)
  1047. if(HAVE_DSOUND_H)
  1048. set(SDL_AUDIO_DRIVER_DSOUND 1)
  1049. file(GLOB DSOUND_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/directsound/*.c)
  1050. set(SOURCE_FILES ${SOURCE_FILES} ${DSOUND_AUDIO_SOURCES})
  1051. endif()
  1052. if(HAVE_XAUDIO2_H)
  1053. set(SDL_AUDIO_DRIVER_XAUDIO2 1)
  1054. file(GLOB XAUDIO2_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/xaudio2/*.c)
  1055. set(SOURCE_FILES ${SOURCE_FILES} ${XAUDIO2_AUDIO_SOURCES})
  1056. endif()
  1057. endif()
  1058. if(SDL_VIDEO)
  1059. # requires SDL_LOADSO on Windows (IME, DX, etc.)
  1060. if(NOT SDL_LOADSO)
  1061. message_error("SDL_VIDEO requires SDL_LOADSO, which is not enabled")
  1062. endif()
  1063. set(SDL_VIDEO_DRIVER_WINDOWS 1)
  1064. file(GLOB WIN_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/windows/*.c)
  1065. set(SOURCE_FILES ${SOURCE_FILES} ${WIN_VIDEO_SOURCES})
  1066. if(RENDER_D3D AND HAVE_D3D_H)
  1067. set(SDL_VIDEO_RENDER_D3D 1)
  1068. set(HAVE_RENDER_D3D TRUE)
  1069. endif()
  1070. if(RENDER_D3D AND HAVE_D3D11_H)
  1071. set(SDL_VIDEO_RENDER_D3D11 1)
  1072. set(HAVE_RENDER_D3D TRUE)
  1073. endif()
  1074. set(HAVE_SDL_VIDEO TRUE)
  1075. # Urho3D - bug fix - we are going to need this later when we refactor the library dependency handling
  1076. list (APPEND EXTRA_LIBS ${DIRECT3D_LIBRARIES}) # Empty when none of the D3D components is used
  1077. endif()
  1078. if(SDL_THREADS)
  1079. set(SDL_THREAD_WINDOWS 1)
  1080. set(SOURCE_FILES ${SOURCE_FILES}
  1081. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_sysmutex.c
  1082. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_syssem.c
  1083. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systhread.c
  1084. ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systls.c
  1085. ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c)
  1086. set(HAVE_SDL_THREADS TRUE)
  1087. endif()
  1088. if(SDL_POWER)
  1089. set(SDL_POWER_WINDOWS 1)
  1090. set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/power/windows/SDL_syspower.c)
  1091. set(HAVE_SDL_POWER TRUE)
  1092. endif()
  1093. if(SDL_FILESYSTEM)
  1094. set(SDL_FILESYSTEM_WINDOWS 1)
  1095. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/windows/*.c)
  1096. set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1097. set(HAVE_SDL_FILESYSTEM TRUE)
  1098. endif()
  1099. # Libraries for Win32 native and MinGW
  1100. list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid)
  1101. # TODO: in configure.in the check for timers is set on
  1102. # cygwin | mingw32* - does this include mingw32CE?
  1103. if(SDL_TIMERS)
  1104. set(SDL_TIMER_WINDOWS 1)
  1105. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/windows/*.c)
  1106. set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1107. set(HAVE_SDL_TIMERS TRUE)
  1108. endif()
  1109. if(SDL_LOADSO)
  1110. set(SDL_LOADSO_WINDOWS 1)
  1111. file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/windows/*.c)
  1112. set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
  1113. set(HAVE_SDL_LOADSO TRUE)
  1114. endif()
  1115. file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
  1116. set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
  1117. if(SDL_VIDEO)
  1118. if(VIDEO_OPENGL)
  1119. set(SDL_VIDEO_OPENGL 1)
  1120. set(SDL_VIDEO_OPENGL_WGL 1)
  1121. set(SDL_VIDEO_RENDER_OGL 1)
  1122. set(HAVE_VIDEO_OPENGL TRUE)
  1123. endif()
  1124. if(VIDEO_OPENGLES)
  1125. set(SDL_VIDEO_OPENGL_EGL 1)
  1126. set(SDL_VIDEO_OPENGL_ES2 1)
  1127. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  1128. set(HAVE_VIDEO_OPENGLES TRUE)
  1129. endif()
  1130. endif()
  1131. if(SDL_JOYSTICK)
  1132. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/windows/*.c)
  1133. set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1134. if(HAVE_DINPUT_H)
  1135. set(SDL_JOYSTICK_DINPUT 1)
  1136. list(APPEND EXTRA_LIBS dinput8)
  1137. if(CMAKE_COMPILER_IS_MINGW)
  1138. list(APPEND EXTRA_LIBS dxerr8)
  1139. elseif (NOT USE_WINSDK_DIRECTX)
  1140. list(APPEND EXTRA_LIBS dxerr)
  1141. endif()
  1142. endif()
  1143. if(HAVE_XINPUT_H)
  1144. set(SDL_JOYSTICK_XINPUT 1)
  1145. endif()
  1146. if(NOT HAVE_DINPUT_H AND NOT HAVE_XINPUT_H)
  1147. set(SDL_JOYSTICK_WINMM 1)
  1148. endif()
  1149. set(HAVE_SDL_JOYSTICK TRUE)
  1150. if(SDL_HAPTIC)
  1151. if(HAVE_DINPUT_H OR HAVE_XINPUT_H)
  1152. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/windows/*.c)
  1153. if(HAVE_DINPUT_H)
  1154. set(SDL_HAPTIC_DINPUT 1)
  1155. endif()
  1156. if(HAVE_XINPUT_H)
  1157. set(SDL_HAPTIC_XINPUT 1)
  1158. endif()
  1159. else()
  1160. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  1161. set(SDL_HAPTIC_DUMMY 1)
  1162. endif()
  1163. set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1164. set(HAVE_SDL_HAPTIC TRUE)
  1165. endif()
  1166. endif()
  1167. # Urho3D - commented out adding main entry point for Windows platform
  1168. # 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
  1169. endif()
  1170. # Dummies
  1171. # configure.in does it differently:
  1172. # if not have X
  1173. # if enable_X { SDL_X_DISABLED = 1 }
  1174. # [add dummy sources]
  1175. # so it always adds a dummy, without checking, if it was actually requested.
  1176. # This leads to missing internal references on building, since the
  1177. # src/X/*.c does not get included.
  1178. if(NOT HAVE_SDL_JOYSTICK)
  1179. set(SDL_JOYSTICK_DISABLED 1)
  1180. if(SDL_JOYSTICK AND NOT APPLE) # results in unresolved symbols on OSX
  1181. file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dummy/*.c)
  1182. set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1183. endif()
  1184. endif()
  1185. if(NOT HAVE_SDL_HAPTIC)
  1186. set(SDL_HAPTIC_DISABLED 1)
  1187. file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  1188. set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1189. endif()
  1190. if(NOT HAVE_SDL_LOADSO)
  1191. set(SDL_LOADSO_DISABLED 1)
  1192. file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
  1193. set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
  1194. endif()
  1195. if(NOT HAVE_SDL_FILESYSTEM)
  1196. set(SDL_FILESYSTEM_DISABLED 1)
  1197. file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c)
  1198. set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1199. endif()
  1200. # We always need to have threads and timers around
  1201. if(NOT HAVE_SDL_THREADS)
  1202. set(SDL_THREADS_DISABLED 1)
  1203. file(GLOB THREADS_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/*.c)
  1204. set(SOURCE_FILES ${SOURCE_FILES} ${THREADS_SOURCES})
  1205. endif()
  1206. if(NOT HAVE_SDL_TIMERS)
  1207. set(SDL_TIMERS_DISABLED 1)
  1208. file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/dummy/*.c)
  1209. set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1210. endif()
  1211. # Urho3D - commented out inclusion of dummy main
  1212. # Append the -MMD -MT flags
  1213. # if(DEPENDENCY_TRACKING)
  1214. # if(COMPILER_IS_GNUCC)
  1215. # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MMD -MT \$@")
  1216. # endif()
  1217. # endif()
  1218. # Urho3D - use 'generated' path suffix for generated config header file (need the suffix as we support both out-of-source in-source build tree)
  1219. configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
  1220. "${SDL2_BINARY_DIR}/include/generated/SDL_config.h")
  1221. # Prepare the flags and remove duplicates
  1222. if(EXTRA_LDFLAGS)
  1223. list(REMOVE_DUPLICATES EXTRA_LDFLAGS)
  1224. endif()
  1225. if(EXTRA_LIBS)
  1226. list(REMOVE_DUPLICATES EXTRA_LIBS)
  1227. endif()
  1228. if(EXTRA_CFLAGS)
  1229. list(REMOVE_DUPLICATES EXTRA_CFLAGS)
  1230. endif()
  1231. listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
  1232. set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
  1233. # Compat helpers for the configuration files
  1234. if(NOT WINDOWS OR CYGWIN)
  1235. # 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
  1236. set(prefix ${CMAKE_INSTALL_PREFIX})
  1237. set(exec_prefix "\${prefix}")
  1238. set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
  1239. set(bindir "\${exec_prefix}/bin")
  1240. set(includedir "\${prefix}/include")
  1241. if(SDL_STATIC)
  1242. set(ENABLE_STATIC_TRUE "")
  1243. set(ENABLE_STATIC_FALSE "#")
  1244. else()
  1245. set(ENABLE_STATIC_TRUE "#")
  1246. set(ENABLE_STATIC_FALSE "")
  1247. endif()
  1248. if(SDL_SHARED)
  1249. set(ENABLE_SHARED_TRUE "")
  1250. set(ENABLE_SHARED_FALSE "#")
  1251. else()
  1252. set(ENABLE_SHARED_TRUE "#")
  1253. set(ENABLE_SHARED_FALSE "")
  1254. endif()
  1255. # Clean up the different lists
  1256. listtostr(EXTRA_LIBS _EXTRA_LIBS "-l")
  1257. set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
  1258. list(REMOVE_DUPLICATES SDL_STATIC_LIBS)
  1259. listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS)
  1260. set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS})
  1261. listtostr(SDL_LIBS _SDL_LIBS)
  1262. set(SDL_LIBS ${_SDL_LIBS})
  1263. # Urho3D - commented out pkg-config configuration file generation
  1264. # Urho3D - TODO - utilize the populated variables for pkg-config configuration file generation for Urho3D.pc
  1265. endif()
  1266. # Urho3D - restore the original CMake global settings
  1267. set (CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  1268. set (CMAKE_REQUIRED_INCLUDES ${ORIG_CMAKE_REQUIRED_INCLUDES})
  1269. set (CMAKE_REQUIRED_LIBRARIES ${ORIG_CMAKE_REQUIRED_LIBRARIES})
  1270. # Urho3D - only echo the status once during initial configuration
  1271. if (NOT SDL_INFO_ECHOED_STATUS)
  1272. set (SDL_INFO_ECHOED_STATUS TRUE CACHE INTERNAL "SDL info echoed status")
  1273. ##### Info output #####
  1274. message(STATUS "")
  1275. message(STATUS "SDL2 was configured with the following options:")
  1276. message(STATUS "")
  1277. message(STATUS "Platform: ${CMAKE_SYSTEM}")
  1278. message(STATUS "64-bit: ${ARCH_64}")
  1279. message(STATUS "Compiler: ${CMAKE_C_COMPILER}")
  1280. message(STATUS "")
  1281. message(STATUS "Subsystems:")
  1282. foreach(_SUB ${SDL_SUBSYSTEMS})
  1283. string(TOUPPER ${_SUB} _OPT)
  1284. # Urho3D - use the same amount of spaces for padding
  1285. string(LENGTH ${_SUB} _SUBLEN)
  1286. math(EXPR _PADLEN "11 - ${_SUBLEN}")
  1287. string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
  1288. message_bool_option(${_SUB} SDL_${_OPT} ${_PADDING})
  1289. endforeach()
  1290. message(STATUS "")
  1291. message(STATUS "Options:")
  1292. list(SORT ALLOPTIONS)
  1293. foreach(_OPT ${ALLOPTIONS})
  1294. # Longest option is VIDEO_X11_XSCREENSAVER = 22 characters
  1295. # Get the padding
  1296. string(LENGTH ${_OPT} _OPTLEN)
  1297. math(EXPR _PADLEN "23 - ${_OPTLEN}")
  1298. string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
  1299. message_tested_option(${_OPT} ${_PADDING})
  1300. endforeach()
  1301. message(STATUS "")
  1302. message(STATUS " CFLAGS: ${CMAKE_C_FLAGS}")
  1303. message(STATUS " EXTRA_CFLAGS: ${EXTRA_CFLAGS}")
  1304. message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS}")
  1305. message(STATUS " EXTRA_LIBS: ${EXTRA_LIBS}")
  1306. message(STATUS "")
  1307. # 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
  1308. endif (NOT SDL_INFO_ECHOED_STATUS)
  1309. # Ensure that the extra cflags are used at compile time
  1310. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
  1311. # Urho3D - commented out targets defined by original CMakeLists.txt, instead we setup our own target that meets our own needs
  1312. # Urho3D - anything below this line is Urho3D specific
  1313. # Define target name
  1314. set (TARGET_NAME SDL)
  1315. # Define source files
  1316. file (GLOB H_FILES include/*.h) # Adding the headers into source files list is just for easier file browsing in the IDE
  1317. list (APPEND SOURCE_FILES ${H_FILES})
  1318. # Setup target as STATIC library (as the result we never use EXTRA_LDFLAGS linker flags)
  1319. setup_library ()