premake/util/sdl_dependency_checkers.lua
author Sam Lantinga
Thu, 01 Sep 2016 01:26:56 -0700
changeset 10304 ee83e0b4a36f
parent 9998 f67cf37e9cd4
permissions -rwxr-xr-x
wayland: Add support for relative mouse mode, by Jonas Ã…dahl <jadahl@gmail.com>

Generate the C protocol files from the protocol XML files installed by
wayland-protocols, and use them to implement support for relative pointer
motions and pointer locking.

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