2
0

sdl_dependency_checkers.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. -- Copyright (C) 1997-2016 Sam Lantinga <[email protected]>
  2. --
  3. -- This software is provided 'as-is', without any express or implied
  4. -- warranty. In no event will the authors be held liable for any damages
  5. -- arising from the use of this software.
  6. --
  7. -- Permission is granted to anyone to use this software for any purpose,
  8. -- including commercial applications, and to alter it and redistribute it
  9. -- freely.
  10. --
  11. -- Meta-build system using premake created and maintained by
  12. -- Benjamin Henning <[email protected]>
  13. --[[
  14. sdl_dependency_checkers.lua
  15. This script contains a bunch of functions which determine whether certain
  16. dependencies exist on the current platform. These functions are able to use
  17. any and all available utilities for trying to determine both whether the
  18. dependency is available on this platform, and how to build to the dependency.
  19. There are a few limitations with these functions, but many of the limitations
  20. can be mitigated by using the dependency definition functions in the project
  21. definition files.
  22. Each function in this file, in order to be a valid dependency function, must
  23. return a table with the following entries:
  24. 'found' = boolean value indicating whether the dependency was found
  25. 'incDirs' = table of include directory strings, or nil if none are needed
  26. 'libDirs' = table of library directory strings, or nil if none are needed
  27. 'libs' = table of libraries to link to, or nil if none are needed
  28. All functions must be properly registered with the project definition system
  29. in order to be properly referenced by projects.
  30. ]]
  31. -- dependency functions must return the following:
  32. -- table with an element found, incDirs, libDirs, and libs
  33. function openGLDep()
  34. print("Checking OpenGL dependencies...")
  35. if SDL_getos() == "macosx" then
  36. -- mac should always have support for OpenGL...
  37. return { found = true, libs = { "OpenGL.framework" } }
  38. elseif SDL_getos() == "ios" then
  39. --...unless on iOS
  40. print("Desktop OpenGL is not supported on iOS targets.")
  41. return { found = false, libs = { "OpenGL.framework" } }
  42. elseif SDL_getos() == "cygwin" then
  43. print("OpenGL is not currently supported on Cygwin.")
  44. return { found = false, libDirs = { }, libs = { "OpenGL32" } }
  45. end
  46. local libpath = nil
  47. local libname = nil
  48. if SDL_getos() == "windows" or SDL_getos() == "mingw" then
  49. libpath = os.findlib("OpenGL32")
  50. libname = "OpenGL32"
  51. else -- *nix
  52. libpath = os.findlib("libGL")
  53. libname = "GL"
  54. end
  55. local foundLib = libpath ~= nil
  56. -- another way to possibly find the dependency on windows
  57. --if not foundLib then
  58. -- foundLib, libpath = find_dependency_dir_windows(nil, "C:/Program Files (x86);C:/Program Files", "Microsoft SDKs", "Lib")
  59. --end
  60. if not foundLib then return { found = false } end
  61. if SDL_getos() == "mingw" then
  62. libpath = libpath:gsub("\\", "/"):gsub("//", "/")
  63. end
  64. return { found = foundLib, libDirs = { }, libs = { libname } }
  65. end
  66. function directXDep()
  67. print("Checking DirectX dependencies...")
  68. -- enable this for more correct searching, but it's much slower
  69. local searchPath = nil --os.getenvpath("ProgramFiles", "ProgramFiles(x86)")
  70. local foundInc, incpath = find_dependency_dir_windows("DXSDK_DIR", searchPath, "DirectX", "Include")
  71. local foundLib, libpath = find_dependency_dir_windows("DXSDK_DIR", searchPath, "DirectX", "Lib/x86")
  72. if not foundInc or not foundLib then return { found = false } end
  73. -- XXX: hacked mingw check...
  74. if foundInc and SDL_getos() == "mingw" then
  75. incpath = incpath:gsub("%$%(DXSDK_DIR%)", os.getenv("DXSDK_DIR")):gsub("\\", "/"):gsub("//", "/")
  76. libpath = libpath:gsub("%$%(DXSDK_DIR%)", os.getenv("DXSDK_DIR")):gsub("\\", "/"):gsub("//", "/")
  77. end
  78. if SDL_getos() == "mingw" then
  79. print("DirectX is not currently supported on MinGW targets.")
  80. return { found = false, incDirs = { incpath }, libDirs = { libpath } }
  81. end
  82. if SDL_getos() == "cygwin" then
  83. print("DirectX is not currently supported on Cygwin targets.")
  84. return { found = false, incDirs = { incpath }, libDirs = { libpath } }
  85. end
  86. return { found = true, incDirs = { incpath }, libDirs = { libpath } }
  87. end
  88. function dbusDep()
  89. print("Checking for D-Bus support...")
  90. if not check_include_directories("/usr/include/dbus-1.0", "/usr/lib/x86_64-linux-gnu/dbus-1.0/include") then
  91. print("Warning: D-Bus unsupported!")
  92. return { found = false }
  93. end
  94. return { found = true, incDirs = { "/usr/include/dbus-1.0", "/usr/lib/x86_64-linux-gnu/dbus-1.0/include" } }
  95. end
  96. function alsaDep()
  97. print("Checking for ALSA support...")
  98. if not check_include_files("alsa/asoundlib.h")
  99. or os.findlib("asound") == nil
  100. or not check_library_exists_lookup("asound", "snd_pcm_open", "alsa/asoundlib.h")
  101. or not SDL_assertdepfunc("DLOpen") then
  102. print("Warning: ALSA unsupported!")
  103. return { found = false }
  104. end
  105. return { found = true }
  106. end
  107. function pulseAudioDep()
  108. print("Checking for PulseAudio support...")
  109. if os.findlib("libpulse-simple") == nil
  110. or not SDL_assertdepfunc("DLOpen") then
  111. print("Warning: PulseAudio unsupported!")
  112. return { found = false }
  113. end
  114. return { found = true }
  115. end
  116. function esdDep()
  117. print("Checking for ESD support...")
  118. if os.findlib("esd") == nil
  119. or not SDL_assertdepfunc("DLOpen") then
  120. print("Warning: ESD unsupported!")
  121. return { found = false }
  122. end
  123. return { found = true }
  124. end
  125. function nasDep()
  126. print("Checking for NAS support...")
  127. if not check_include_file("audio/audiolib.h")
  128. or not SDL_assertdepfunc("DLOpen") then
  129. print("Warning: NAS unsupported!")
  130. return { found = false }
  131. end
  132. return { found = true }
  133. end
  134. function ossDep()
  135. print("Checking for OSS support...")
  136. if not check_cxx_source_compiles([[
  137. #include <sys/soundcard.h>
  138. int main() { int arg = SNDCTL_DSP_SETFRAGMENT; return 0; }]])
  139. and not check_cxx_source_compiles([[
  140. #include <soundcard.h>
  141. int main() { int arg = SNDCTL_DSP_SETFRAGMENT; return 0; }]]) then
  142. print("Warning: OSS unsupported!")
  143. return { found = false }
  144. end
  145. return { found = true }
  146. end
  147. function dlOpenDep()
  148. print("Checking for DLOpen support...")
  149. if not check_library_exists_multiple("dlopen", "dlfcn.h", "dl", "tdl") then
  150. print("Warning: DLOpen unsupported!")
  151. return { found = false }
  152. end
  153. return { found = true, libs = { "dl" } }
  154. end
  155. function x11Dep()
  156. print("Checking for X11 support...")
  157. for _, v in ipairs { "X11", "Xext", "Xcursor", "Xinerama", "Xi", "Xrandr", "Xrender", "Xss", "Xxf86vm" } do
  158. if os.findlib(v) == nil then
  159. print("Warning: X11 unsupported!")
  160. return { found = false }
  161. end
  162. end
  163. if not check_include_files("X11/Xcursor/Xcursor.h", "X11/extensions/Xinerama.h",
  164. "X11/extensions/XInput2.h", "X11/extensions/Xrandr.h", "X11/extensions/Xrender.h",
  165. "X11/extensions/scrnsaver.h", "X11/extensions/shape.h", "X11/Xlib.h",
  166. "X11/extensions/xf86vmode.h") then
  167. print("Warning: X11 unsupported!")
  168. return { found = false }
  169. end
  170. if not SDL_assertdepfunc("DLOpen") then
  171. print("Warning: X11 unsupported!")
  172. return { found = false }
  173. end
  174. -- XXX: shared memory check...
  175. -- there's a LOT more to check to properly configure X11...
  176. return { found = true, libs = { "X11" } }
  177. end
  178. -- register all of these dependency functions with the definition system
  179. SDL_registerDependencyChecker("OpenGL", openGLDep)
  180. SDL_registerDependencyChecker("DirectX", directXDep)
  181. SDL_registerDependencyChecker("DBus", dbusDep)
  182. SDL_registerDependencyChecker("ALSA", alsaDep)
  183. SDL_registerDependencyChecker("PulseAudio", pulseAudioDep)
  184. SDL_registerDependencyChecker("ESD", esdDep)
  185. SDL_registerDependencyChecker("NAS", nasDep)
  186. SDL_registerDependencyChecker("OSS", ossDep)
  187. SDL_registerDependencyChecker("DLOpen", dlOpenDep)
  188. SDL_registerDependencyChecker("X11", x11Dep)