Hash :
24c86b55
Author :
Date :
2014-09-11T19:24:42
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
-- Copyright (C) 1997-2014 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>
-- This is kept just for windows because the other platforms use different means
-- for determining dependence or compatibility.
--[[
sdl_depends.lua
This file simply contains a function for determining whether a dependency
exists on the Windows platform, given a possible environmental variable,
delimited search paths, and a main and/or sub-directory paths for more
elaborate pattern matching.
]]
-- find_dependency_dir_windows(env, main_search_path, main_dir_path)
-- Attempt to resolve a dependency (true or false) folder based on either an
-- environmental variable, start search path, or both. If both are present,
-- the environmental variable will be preferred. If neither are present, this
-- function returns false.
--
-- Arguments:
-- env The name of the environmental variable to treat as a path
-- main_search_paths Paths to look for the main directory in
-- main_dir_path The a path that must be contained between main_search_path and sub_dir_path
-- sub_dir_path The path of the directories that should exist at the searched path
function find_dependency_dir_windows(env, main_search_paths, main_dir_path, sub_dir_path)
if not os.is("windows") then -- if not windows, then fail
return false
end
if env == nil and (main_search_paths == nil or #main_search_paths == 0) then
return false
end
local env_path = nil
local main_path = nil
if env ~= nil then env_path = os.getenv(env) end
local search_table = { n = 0 }
if main_search_paths ~= nil then
for k,main_search_path in ipairs(explode(main_search_paths, ";")) do
local directories = os.matchdirs(main_search_path .. "/**" .. main_dir_path .. "*")
for k,v in pairs(directories) do
table.insert(search_table, v)
end
end
end
if env_path ~= nil then table.insert(search_table, env_path) end
local search_path = table.concat(search_table, ";")
local result_path = os.dirpathsearch(sub_dir_path, search_path, ";")
if result_path == nil then
return false
end
local found_dir = os.isdir(result_path)
local abs_path = path.getabsolute(result_path)
if found_dir and env_path ~= nil then
abs_path = abs_path:gsub("\\", "/")
env_path = env_path:gsub("\\", "/")
local pos = abs_path:indexOf(env_path)
if pos ~= nil then
abs_path = abs_path:sub(1, pos - 1) .. "$(" .. env .. ")/" .. abs_path:sub(pos + #env_path)
end
end
-- we want the path in terms of '/'
return found_dir, abs_path
end