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