premake/util/sdl_depends.lua
author Ryan C. Gordon
Sun, 03 Jan 2016 20:52:44 -0500
changeset 10004 8f2f519d1e61
parent 9998 f67cf37e9cd4
permissions -rwxr-xr-x
CMake: Don't make a libSDL2.so symlink on Mac OS X (do .dylib instead).
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
-- This is kept just for windows because the other platforms use different means
icculus@7925
    15
-- for determining dependence or compatibility.
icculus@7925
    16
icculus@7925
    17
--[[
icculus@7925
    18
sdl_depends.lua
icculus@7925
    19
icculus@7925
    20
	This file simply contains a function for determining whether a dependency
icculus@7925
    21
	exists on the Windows platform, given a possible environmental variable,
icculus@7925
    22
	delimited search paths, and a main and/or sub-directory paths for more
icculus@7925
    23
	elaborate pattern matching.
icculus@7925
    24
]]
icculus@7925
    25
icculus@7925
    26
-- find_dependency_dir_windows(env, main_search_path, main_dir_path)
icculus@7925
    27
--   Attempt to resolve a dependency (true or false) folder based on either an
icculus@7925
    28
--   environmental variable, start search path, or both. If both are present,
icculus@7925
    29
--   the environmental variable will be preferred. If neither are present, this
icculus@7925
    30
--   function returns false.
icculus@7925
    31
--
icculus@7925
    32
--   Arguments:
icculus@7925
    33
--     env                The name of the environmental variable to treat as a path
icculus@7925
    34
--     main_search_paths  Paths to look for the main directory in
icculus@7925
    35
--     main_dir_path      The a path that must be contained between main_search_path and sub_dir_path
icculus@7925
    36
--     sub_dir_path       The path of the directories that should exist at the searched path
icculus@7925
    37
function find_dependency_dir_windows(env, main_search_paths, main_dir_path, sub_dir_path)
icculus@7925
    38
	if not os.is("windows") then -- if not windows, then fail
icculus@7925
    39
		return false
icculus@7925
    40
	end
icculus@7925
    41
	if env == nil and (main_search_paths == nil or #main_search_paths == 0) then
icculus@7925
    42
		return false
icculus@7925
    43
	end
icculus@7925
    44
	local env_path = nil
icculus@7925
    45
	local main_path = nil
icculus@7925
    46
	if env ~= nil then env_path = os.getenv(env) end
icculus@7925
    47
	local search_table = { n = 0 }
icculus@7925
    48
	if main_search_paths ~= nil then
icculus@7925
    49
		for k,main_search_path in ipairs(explode(main_search_paths, ";")) do
icculus@7925
    50
			local directories = os.matchdirs(main_search_path .. "/**" .. main_dir_path .. "*")
icculus@7925
    51
			for k,v in pairs(directories) do
icculus@7925
    52
				table.insert(search_table, v)
icculus@7925
    53
			end
icculus@7925
    54
		end
icculus@7925
    55
	end
icculus@7925
    56
	if env_path ~= nil then table.insert(search_table, env_path) end
icculus@7925
    57
	local search_path = table.concat(search_table, ";")
icculus@7925
    58
	local result_path = os.dirpathsearch(sub_dir_path, search_path, ";")
icculus@7925
    59
	if result_path == nil then
icculus@7925
    60
		return false
icculus@7925
    61
	end
icculus@7925
    62
	local found_dir = os.isdir(result_path)
icculus@7925
    63
	local abs_path = path.getabsolute(result_path)
icculus@7925
    64
	if found_dir and env_path ~= nil then
icculus@7925
    65
		abs_path = abs_path:gsub("\\", "/")
icculus@7925
    66
		env_path = env_path:gsub("\\", "/")
icculus@7925
    67
		local pos = abs_path:indexOf(env_path)
icculus@7925
    68
		if pos ~= nil then
icculus@7925
    69
			abs_path = abs_path:sub(1, pos - 1) .. "$(" .. env .. ")/" .. abs_path:sub(pos + #env_path)
icculus@7925
    70
		end
icculus@7925
    71
	end
icculus@7925
    72
	-- we want the path in terms of '/'
icculus@7925
    73
	return found_dir, abs_path
slouken@8149
    74
end