premake/util/sdl_dependency_checkers.lua
changeset 7925 f090a47eb7f7
child 8149 681eb46b8ac4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/premake/util/sdl_dependency_checkers.lua	Sun Nov 10 00:38:37 2013 -0500
     1.3 @@ -0,0 +1,204 @@
     1.4 +-- Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     1.5 +--
     1.6 +-- This software is provided 'as-is', without any express or implied
     1.7 +-- warranty.  In no event will the authors be held liable for any damages
     1.8 +-- arising from the use of this software.
     1.9 +--
    1.10 +-- Permission is granted to anyone to use this software for any purpose,
    1.11 +-- including commercial applications, and to alter it and redistribute it
    1.12 +-- freely.
    1.13 +--
    1.14 +-- Meta-build system using premake created and maintained by
    1.15 +-- Benjamin Henning <b.henning@digipen.edu>
    1.16 +
    1.17 +--[[
    1.18 +sdl_dependency_checkers.lua
    1.19 +
    1.20 +	This script contains a bunch of functions which determine whether certain
    1.21 +	dependencies exist on the current platform. These functions are able to use
    1.22 +	any and all available utilities for trying to determine both whether the
    1.23 +	dependency is available on this platform, and how to build to the dependency.
    1.24 +	There are a few limitations with these functions, but many of the limitations
    1.25 +	can be mitigated by using the dependency definition functions in the project
    1.26 +	definition files.
    1.27 +	
    1.28 +	Each function in this file, in order to be a valid dependency function, must
    1.29 +	return a table with the following entries:
    1.30 +	
    1.31 +	'found' = boolean value indicating whether the dependency was found
    1.32 +	'incDirs' = table of include directory strings, or nil if none are needed
    1.33 +	'libDirs' = table of library directory strings, or nil if none are needed
    1.34 +	'libs' = table of libraries to link to, or nil if none are needed
    1.35 +	
    1.36 +	All functions must be properly registered with the project definition system
    1.37 +	in order to be properly referenced by projects.
    1.38 +]]
    1.39 +
    1.40 +-- dependency functions must return the following:
    1.41 +-- table with an element found, incDirs, libDirs, and libs
    1.42 +function openGLDep()
    1.43 +	print("Checking OpenGL dependencies...")
    1.44 +	if SDL_getos() == "macosx" then
    1.45 +		-- mac should always have support for OpenGL...
    1.46 +		return { found = true, libs = { "OpenGL.framework" } }
    1.47 +	elseif SDL_getos() == "ios" then
    1.48 +		--...unless on iOS
    1.49 +		print("Desktop OpenGL is not supported on iOS targets.")
    1.50 +		return { found = false, libs = { "OpenGL.framework" } }
    1.51 +	elseif SDL_getos() == "cygwin" then
    1.52 +		print("OpenGL is not currently supported on Cygwin.")
    1.53 +		return { found = false, libDirs = { }, libs = { "OpenGL32" } }
    1.54 +	end
    1.55 +	local libpath = nil
    1.56 +  local libname = nil
    1.57 +	if SDL_getos() == "windows" or SDL_getos() == "mingw" then
    1.58 +		libpath = os.findlib("OpenGL32")
    1.59 +		libname = "OpenGL32"
    1.60 +	else -- *nix
    1.61 +		libpath = os.findlib("libGL")
    1.62 +		libname = "GL"
    1.63 +	end
    1.64 +	local foundLib = libpath ~= nil
    1.65 +	-- another way to possibly find the dependency on windows
    1.66 +	--if not foundLib then
    1.67 +	--	foundLib, libpath = find_dependency_dir_windows(nil, "C:/Program Files (x86);C:/Program Files", "Microsoft SDKs", "Lib")
    1.68 +	--end
    1.69 +	if not foundLib then return { found = false } end
    1.70 +	if SDL_getos() == "mingw" then
    1.71 +		libpath = libpath:gsub("\\", "/"):gsub("//", "/")
    1.72 +	end
    1.73 +	return { found = foundLib, libDirs = { }, libs = { libname } }
    1.74 +end
    1.75 +
    1.76 +function directXDep()
    1.77 +	print("Checking DirectX dependencies...")
    1.78 +	-- enable this for more correct searching, but it's much slower
    1.79 +	local searchPath = nil --os.getenvpath("ProgramFiles", "ProgramFiles(x86)")
    1.80 +	local foundInc, incpath = find_dependency_dir_windows("DXSDK_DIR", searchPath, "DirectX", "Include")
    1.81 +	local foundLib, libpath = find_dependency_dir_windows("DXSDK_DIR", searchPath, "DirectX", "Lib/x86")
    1.82 +	if not foundInc or not foundLib then return { found = false } end
    1.83 +	-- XXX: hacked mingw check...
    1.84 +	if foundInc and SDL_getos() == "mingw" then
    1.85 +		incpath = incpath:gsub("%$%(DXSDK_DIR%)", os.getenv("DXSDK_DIR")):gsub("\\", "/"):gsub("//", "/")
    1.86 +		libpath = libpath:gsub("%$%(DXSDK_DIR%)", os.getenv("DXSDK_DIR")):gsub("\\", "/"):gsub("//", "/")
    1.87 +	end
    1.88 +	if SDL_getos() == "mingw" then
    1.89 +		print("DirectX is not currently supported on MinGW targets.")
    1.90 +		return { found = false, incDirs = { incpath }, libDirs = { libpath } }
    1.91 +	end
    1.92 +	if SDL_getos() == "cygwin" then
    1.93 +		print("DirectX is not currently supported on Cygwin targets.")
    1.94 +		return { found = false, incDirs = { incpath }, libDirs = { libpath } }
    1.95 +	end
    1.96 +	return { found = true, incDirs = { incpath }, libDirs = { libpath } }
    1.97 +end
    1.98 +
    1.99 +function dbusDep()
   1.100 +	print("Checking for D-Bus support...")
   1.101 +	if not check_include_directories("/usr/include/dbus-1.0", "/usr/lib/x86_64-linux-gnu/dbus-1.0/include") then
   1.102 +		print("Warning: D-Bus unsupported!")
   1.103 +		return { found = false }
   1.104 +	end
   1.105 +	return { found = true, incDirs = { "/usr/include/dbus-1.0", "/usr/lib/x86_64-linux-gnu/dbus-1.0/include" } }
   1.106 +end
   1.107 +
   1.108 +function alsaDep()
   1.109 +	print("Checking for ALSA support...")
   1.110 +	if not check_include_files("alsa/asoundlib.h")
   1.111 +			or os.findlib("asound") == nil
   1.112 +			or not check_library_exists_lookup("asound", "snd_pcm_open", "alsa/asoundlib.h")
   1.113 +			or not SDL_assertdepfunc("DLOpen") then
   1.114 +		print("Warning: ALSA unsupported!")
   1.115 +		return { found = false }
   1.116 +	end
   1.117 +	return { found = true }
   1.118 +end
   1.119 +
   1.120 +function pulseAudioDep()
   1.121 +	print("Checking for PulseAudio support...")
   1.122 +	if os.findlib("libpulse-simple") == nil
   1.123 +			or not SDL_assertdepfunc("DLOpen") then
   1.124 +		print("Warning: PulseAudio unsupported!")
   1.125 +		return { found = false }
   1.126 +	end
   1.127 +	return { found = true }
   1.128 +end
   1.129 +
   1.130 +function esdDep()
   1.131 +	print("Checking for ESD support...")
   1.132 +	if os.findlib("esd") == nil
   1.133 +			or not SDL_assertdepfunc("DLOpen") then
   1.134 +		print("Warning: ESD unsupported!")
   1.135 +		return { found = false }
   1.136 +	end
   1.137 +	return { found = true }
   1.138 +end
   1.139 +
   1.140 +function nasDep()
   1.141 +	print("Checking for NAS support...")
   1.142 +	if not check_include_file("audio/audiolib.h")
   1.143 +			or not SDL_assertdepfunc("DLOpen") then
   1.144 +		print("Warning: NAS unsupported!")
   1.145 +		return { found = false }
   1.146 +	end
   1.147 +	return { found = true }
   1.148 +end
   1.149 +
   1.150 +function ossDep()
   1.151 +	print("Checking for OSS support...")
   1.152 +	if not check_cxx_source_compiles([[
   1.153 +				#include <sys/soundcard.h>
   1.154 +				int main() { int arg = SNDCTL_DSP_SETFRAGMENT; return 0; }]])
   1.155 +			and not check_cxx_source_compiles([[
   1.156 +				#include <soundcard.h>
   1.157 +				int main() { int arg = SNDCTL_DSP_SETFRAGMENT; return 0; }]]) then
   1.158 +		print("Warning: OSS unsupported!")
   1.159 +		return { found = false }
   1.160 +	end
   1.161 +	return { found = true }
   1.162 +end
   1.163 +
   1.164 +function dlOpenDep()
   1.165 +	print("Checking for DLOpen support...")
   1.166 +	if not check_library_exists_multiple("dlopen", "dlfcn.h", "dl", "tdl") then
   1.167 +		print("Warning: DLOpen unsupported!")
   1.168 +		return { found = false }
   1.169 +	end
   1.170 +	return { found = true, libs = { "dl" } }
   1.171 +end
   1.172 +
   1.173 +function x11Dep()
   1.174 +	print("Checking for X11 support...")
   1.175 +	for _, v in ipairs { "X11", "Xext", "Xcursor", "Xinerama", "Xi", "Xrandr", "Xrender", "Xss", "Xxf86vm" } do
   1.176 +		if os.findlib(v) == nil then
   1.177 +			print("Warning: X11 unsupported!")
   1.178 +			return { found = false }
   1.179 +		end
   1.180 +	end
   1.181 +	if not check_include_files("X11/Xcursor/Xcursor.h", "X11/extensions/Xinerama.h",
   1.182 +			"X11/extensions/XInput2.h", "X11/extensions/Xrandr.h", "X11/extensions/Xrender.h",
   1.183 +			"X11/extensions/scrnsaver.h", "X11/extensions/shape.h", "X11/Xlib.h",
   1.184 +			"X11/extensions/xf86vmode.h") then
   1.185 +		print("Warning: X11 unsupported!")
   1.186 +		return { found = false }
   1.187 +	end
   1.188 +	if not SDL_assertdepfunc("DLOpen") then
   1.189 +		print("Warning: X11 unsupported!")
   1.190 +		return { found = false }
   1.191 +	end
   1.192 +	-- XXX: shared memory check...
   1.193 +	-- there's a LOT more to check to properly configure X11...
   1.194 +	return { found = true, libs = { "X11" } }
   1.195 +end
   1.196 +
   1.197 +-- register all of these dependency functions with the definition system
   1.198 +SDL_registerDependencyChecker("OpenGL", openGLDep)
   1.199 +SDL_registerDependencyChecker("DirectX", directXDep)
   1.200 +SDL_registerDependencyChecker("DBus", dbusDep)
   1.201 +SDL_registerDependencyChecker("ALSA", alsaDep)
   1.202 +SDL_registerDependencyChecker("PulseAudio", pulseAudioDep)
   1.203 +SDL_registerDependencyChecker("ESD", esdDep)
   1.204 +SDL_registerDependencyChecker("NAS", nasDep)
   1.205 +SDL_registerDependencyChecker("OSS", ossDep)
   1.206 +SDL_registerDependencyChecker("DLOpen", dlOpenDep)
   1.207 +SDL_registerDependencyChecker("X11", x11Dep)
   1.208 \ No newline at end of file