Hash :
2c4a6ea0
        
        Author :
  
        
        Date :
2015-05-26T06:27:46
        
      
Updated the copyright year to 2015
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
-- Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
--
-- This software is provided 'as-is', without any express or implied
-- warranty.  In no event will the authors be held liable for any damages
-- arising from the use of this software.
--
-- Permission is granted to anyone to use this software for any purpose,
-- including commercial applications, and to alter it and redistribute it
-- freely.
--
-- Meta-build system using premake created and maintained by
-- Benjamin Henning <b.henning@digipen.edu>
--[[
sdl_projects.lua
	This file contains all the functions which are needed to define any project
	within the meta-build system. Many of these functions serve as
	pseudo-replacements for many similarly named premake functions, and that is
	intentional. Even the implementation of these functions are intended to look
	similar to regular premake code. These functions serve to dramatically
	simplify the project definition process to just a few lines of code, versus
	the many more needed for projects defined purely with premake.
	This approach is possible because this meta-build system adds another layer of
	indirection to the premake system, creating a sort of 'meta-meta-build'
	system. Nevertheless, there is a lot more flexibility because the meta-build
	system itself can be used to check for dependencies in a much more complex way
	than premake originally intended. All of the functions useful to the project
	definition system are contained in this file and are documented.
]]
projects = { }
local currentProject = nil
local currentDep = nil
local nextFuncCompat = true -- by default, unless state otherwise changed
local dependencyFunctions = { }
local dependencyResults = { } -- for when the dependencies are executed
-- query whether this function is compatible; resets internal state of
-- compatibility to true until SDL_isos is called again
local function oscompat()
	local compat = nextFuncCompat
	nextFuncCompat = true
	return compat
end
-- determine whether the specific OS name is within a pattern.
local function osmatch(name, pattern)
	local checks = pattern:explode('|')
	for i,v in pairs(checks) do
		if name == v then
			return true
		end
	end
	return false
end
-- Registers a dependency checker function based on a name. This function is
-- used in order to determine compatibility with the current system for a given
-- SDL_dependency. See SDL_depfunc for more information.
--
-- Specifies a function which will be invoked upon determining whether this
-- dependency is valid for the current system setup (ie, whether the system
-- has the right architecture, operating system, or even if it's installed).
-- The dependency function takes no arguments, but it must return the following
-- values:
--
--   <foundDep> [includePaths] [libPaths] [inputLibLibraries]
--
-- The last three are optional, unless foundDep is true. The name should be
-- descriptive of the outside dependency, since it may be shown to the user.
-- This function is intended to be used only after invoking SDL_dependency.
function SDL_registerDependencyChecker(name, func)
	dependencyFunctions[name:lower()] = func
end
-- Initializes the definition of a SDL project given the name of the project.
function SDL_project(name)
	if not oscompat() then return end
	currentProject = { }
	currentProject.name = name
	currentProject.compat = true
	projects[name] = currentProject
	currentProject.dependencyTree = { }
	-- stores which dependencies have already been checked on behalf of this
	-- project
	currentProject.dependencyValues = { }
	currentDep = nil
end
-- Specifies the build kind of the SDL project (e.g. StaticLib, SharedLib,
-- ConsoleApp, etc.), based on premake presets.
function SDL_kind(k)
	if not oscompat() then return end
	currentProject.kind = k
end
-- Specifies which platforms this project supports. Note: this list is not the
-- exact list of supported platforms in the generated project. The list of
-- platforms this project supports will be the unique list of all combined
-- projects for this SDL solution. Thus, only one project needs to actually
-- maintain a list. This function is additive, that is, everytime it is called
-- it adds it to a unique list of platforms
function SDL_platforms(tbl)
	if not oscompat() then return end
	if not currentProject.platforms then
		currentProject.platforms = { }
	end
	for k,v in pairs(tbl) do
		currentProject.platforms[#currentProject.platforms + 1] = v
	end
end
-- Specifies the programming language of the project, such as C or C++.
function SDL_language(k)
	if not oscompat() then return end
	currentProject.language = k
end
-- Specifies the root directory in which the meta-build system should search for
-- source files, given the paths and files added.
function SDL_sourcedir(src)
	if not oscompat() then return end
	currentProject.sourcedir = src
end
-- Specifies the destination location of where the IDE files related to the
-- project should be saved after generation.
function SDL_projectLocation(loc)
	if not oscompat() then return end
	currentProject.projectLocation = loc
end
-- Specifies a table of files that should be copied from the source directory
-- to the end result build directory of the binary file.
function SDL_copy(tbl)
	if not oscompat() then return end
	currentProject.copy = tbl
end
-- Specifies a list of other SDL projects in this workspace the currently active
-- project is dependent on. If the dependent project is a library, the binary
-- result will be copied from its directory to the build directory of the
-- currently active project automatically.
function SDL_projectDependencies(tbl)
	if not oscompat() then return end
	currentProject.projectDependencies = tbl
end
-- Specifies a list of compiler-level preprocessor definitions that should be
-- set in the resulting project upon compile time. This adds to the current
-- table of defines.
function SDL_defines(tbl)
	if not oscompat() then return end
	if not currentProject.defines then
		currentProject.defines = { }
	end
	for k,v in pairs(tbl) do
		currentProject.defines[#currentProject.defines + 1] = v
	end
end
-- Initializes an outside dependency this project has, such as X11 or DirectX.
-- This function, once invoked, may change the behavior of other SDL
-- project-related functions, so be sure to be familiar with all the functions
-- and any specified behavior when used around SDL_dependency.
function SDL_dependency(name)
	if not oscompat() then return end
	currentDep = { nil, compat = true, }
	currentDep.name = name
	table.insert(currentProject.dependencyTree, currentDep)
end
-- Special function for getting the current OS. This factors in whether the
-- metabuild system is in MinGW, Cygwin, or iOS mode.
function SDL_getos()
	if _OPTIONS["ios"] ~= nil then
		return "ios"
	elseif _OPTIONS["mingw"] ~= nil then
		return "mingw"
	elseif _OPTIONS["cygwin"] ~= nil then
		return "cygwin"
	end
	return os.get()
end
-- Specifies which operating system this dependency targets, such as windows or
-- macosx, as per premake presets.
function SDL_os(name)
	if not oscompat() then return end
	if not currentProject then return end
	if not currentDep then
		currentProject.opsys = name
		currentProject.compat = osmatch(SDL_getos(), name)
	else
		currentDep.opsys = name
		currentDep.compat = osmatch(SDL_getos(), name)
	end
end
-- Specifies which operating system this dependency does not targets. This is
-- for nearly platform-independent projects or dependencies that will not work
-- on specific systems, such as ios.
function SDL_notos(name)
	if not oscompat() then return end
	if not currentProject then return end
	if not currentDep then
		currentProject.opsys = "~" .. name
		currentProject.compat = not osmatch(SDL_getos(), name)
	else
		currentDep.opsys = "~" .. name
		currentDep.compat = not osmatch(SDL_getos(), name)
	end
end
-- Changes the internal state of function compatibility based on whether the
-- current os is the one expected; the next function will be affected by this
-- change, but no others. The name can be a pattern using '|' to separate
-- multiple operating systems, such as:
--   SDL_isos("windows|macosx")
function SDL_isos(name)
	nextFuncCompat = osmatch(SDL_getos(), name)
end
-- Same as SDL_isos, except it negates the internal state for exclusion
-- checking.
function SDL_isnotos(name)
	nextFuncCompat = not osmatch(SDL_getos(), name)
end
-- Changes the internal state of function compatibility based on whether the
-- current system is running a 64bit Operating System and architecture; the
-- next function will be affected by this change, but none thereafter.
function SDL_is64bit()
	nextFuncCompat = os.is64bit()
end
-- Same as SDL_is64bit, except it negates the internal state for
-- exclusion checking.
function SDL_isnot64bit()
	nextFuncCompat = not os.is64bit()
end
-- Look at SDL_depfunc and SDL_notdepfunc for detailed information about this
-- function.
local function SDL_depfunc0(funcname, exclude)
	if not oscompat() then return end
	if not currentDep.compat then return end
	local force = _OPTIONS[funcname:lower()] ~= nil
	local func = dependencyFunctions[funcname:lower()]
	if not func then
		print("Warning: could not find dependency function named: " .. funcname)
		currentDep.compat = false
		return
	end
	local cachedFuncResults = dependencyResults[funcname:lower()]
	local depFound, depInc, depLib, depInput
	if cachedFuncResults then
		depFound = cachedFuncResults.depFound
		-- just skip the rest of the function, the user was already warned
		-- exclude mode varies the compatibility slightly
		if force then
			depFound = true
		end
		if not depFound and not exclude then
			currentDep.compat = false
			return
		elseif depFound and exclude then
			currentDep.compat = false
			return
		end
		depInc = cachedFuncResults.depInc
		depLib = cachedFuncResults.depLib
		depInput = cachedFuncResults.depInput
	else
		local result = func()
		if result.found then
			depFound = result.found
		else
			depFound = false
		end
		if force then
			depFound = true
		end
		if result.incDirs then
			depInc = result.incDirs
		else
			depInc = { }
		end
		if result.libDirs then
			depLib = result.libDirs
		else
			depLib = { }
		end
		if result.libs then
			depInput = result.libs
		else
			depInput = { }
		end
		cachedFuncResults = { }
		cachedFuncResults.depFound = depFound
		cachedFuncResults.depInc = depInc
		cachedFuncResults.depLib = depLib
		cachedFuncResults.depInput = depInput
		dependencyResults[funcname:lower()] = cachedFuncResults
		if not depFound and not exclude then
			currentDep.compat = false
			return
		elseif depFound and exclude then
			currentDep.compat = false
			return
		end
	end
	-- we only want to embed this dependency if we're not in exclude mode
	if depFound and not exclude then
		local dependency = { }
		if not currentDep.includes then
			currentDep.includes = { }
		end
		for k,v in pairs(depInc) do
			currentDep.includes[v] = v
		end
		if not currentDep.libs then
			currentDep.libs = { }
		end
		for k,v in pairs(depLib) do
			currentDep.libs[v] = v
		end
		if not currentDep.links then
			currentDep.links = { }
		end
		for k,v in pairs(depInput) do
			currentDep.links[v] = v
		end
	else -- end of dependency found check
		-- if we are not excluding this dependency, then print a warning
		-- if not found
		if not exclude then
			print("Warning: could not find dependency: " .. funcname)
		end
		currentDep.compat = exclude
	end
end
-- Given a dependency name, this function will register the dependency and try
-- to pair it with a dependency function that was registered through
-- SDL_registerDependencyChecker. If the function is not found, compatibility
-- will automatically be dropped for this project and a warning will be printed
-- to the standard output. Otherwise, the dependency function will be invoked
-- and compatibility for the project will be updated. If the project currently
-- is not compatible based on the Operating System or previous dependency, the
-- dependency function will not be checked at all and this function will
-- silently return.
function SDL_depfunc(funcname)
	SDL_depfunc0(funcname, false)
end
-- Same as SDL_depfunc, except this forces dependency on the function failing,
-- rather than succeeding. This is useful for situations where two different
-- files are required based on whether a dependency is found (such as the
-- joystick and haptic systems).
function SDL_notdepfunc(funcname)
	SDL_depfunc0(funcname, true)
end
-- Determines whether the specified dependency is supported without actually
-- executing the dependency or changing the internal states of the current
-- project or dependency definition. This function will only work if the
-- dependency has already been checked and its results cached within the
-- definition system. This function returns true if the dependency is known to
-- be supported, or false if otherwise (or if it cannot be known at this time).
function SDL_assertdepfunc(funcname)
	-- if forced, then of course it's on
	if _OPTIONS[funcname:lower()] then
		return true
	end
	local results = dependencyResults[funcname:lower()]
	if not results or not results.depFound then
		-- either not excuted yet, doesn't exist, or wasn't found
		print("Warning: required dependency not found: " .. funcname ..
			". Make sure your dependencies are in a logical order.")
		return false
	end
	return true
end
-- Returns a list of currently registered dependencies. The values within the
-- table will be sorted, but their names will be lowercased due to internal
-- handling of case-insensitive dependency names.
function SDL_getDependencies()
	local deps = { }
	for k,_ in pairs(dependencyFunctions) do
		deps[#deps + 1] = k
	end
	table.sort(deps)
	return deps
end
-- Specifies a list of libraries that should always be linked to in this
-- project, regardless of a dependency function. If after a dependency
-- declaration, these files will only be included in the project if the
-- dependency is compatible with the native system, given SDL_os usage and any
-- sort of custom dependency function.
function SDL_links(tbl)
	if not oscompat() then return end
	if currentDep and not currentDep.compat then return end
	if currentProject.customLinks == nil then
		currentProject.customLinks = { }
	end
	for i,v in ipairs(tbl) do
		currentProject.customLinks[#currentProject.customLinks + 1] = v
	end
end
-- Specifies a list of configuration values that are assigned as preprocessor
-- definitions in the SDL configuration header, used to globally configure
-- features during the building of the SDL library. If after a dependency
-- declaration, these files will only be included in the project if the
-- dependency is compatible with the native system, given SDL_os usage and any
-- sort of custom dependency function.
function SDL_config(tbl)
	if not oscompat() then return end
	if not currentDep then
		currentProject.config = tbl
		return
	end
	if not currentDep.compat then return end
	currentDep.config = tbl
end
-- Specifies a list of paths where all .c, .h, and .m files should be included
-- for compiling, where the source directory is the root. If after a dependency
-- declaration, these files will only be included in the project if the
-- dependency is compatible with the native system, given SDL_os usage and any
-- sort of custom dependency function.
function SDL_paths(tbl)
	if not oscompat() then return end
	if not currentDep then
		currentProject.paths = tbl
		return
	end
	if not currentDep.compat then return end
	currentDep.paths = tbl
end
-- Specifies a list of files found within the source directory that this project
-- should include during compile time. If after a dependency declaration, these
-- files will only be included in the project if the dependency is compatible
-- with the native system, given SDL_os usage and any sort of custom dependency
-- function.
function SDL_files(tbl)
	if not oscompat() then return end
	if not currentDep then
		currentProject.files = tbl
		return
	end
	if not currentDep.compat then return end
	currentDep.files = tbl
end