Changeset View
Changeset View
Standalone View
Standalone View
build/premake/pkgconfig/pkgconfig.lua
local m = {} | local m = {} | ||||
m._VERSION = "1.1.0-dev" | m._VERSION = "1.2.1-dev" | ||||
local function os_capture(cmd) | local function os_capture(cmd) | ||||
return io.popen(cmd, 'r'):read('*a'):gsub("\n", " ") | return io.popen(cmd, 'r'):read('*a'):gsub("\n", " ") | ||||
end | end | ||||
function m.add_includes(lib, alternative_cmd, alternative_flags) | local function find_includes(lib, alternative_cmd, alternative_flags) | ||||
local result | local result | ||||
if not alternative_cmd then | if not alternative_cmd then | ||||
result = os_capture("pkg-config --cflags "..lib) | result = os_capture("pkg-config --cflags "..lib) | ||||
else | else | ||||
if not alternative_flags then | if not alternative_flags then | ||||
result = os_capture(alternative_cmd.." --cflags") | result = os_capture(alternative_cmd.." --cflags") | ||||
else | else | ||||
result = os_capture(alternative_cmd.." "..alternative_flags) | result = os_capture(alternative_cmd.." "..alternative_flags) | ||||
end | end | ||||
end | end | ||||
-- Small trick: delete the space after -include so that we can detect | -- Small trick: delete the space after -include and -isystem so that | ||||
-- which files have to be force-included without difficulty. | -- we can detect which files have to be included without difficulty. | ||||
result = result:gsub("%-include +(%g+)", "-include%1") | result = result:gsub("%-include +(%g+)", "-include%1") | ||||
result = result:gsub("%-isystem +(%g+)", "-isystem%1") | |||||
local dirs = {} | local dirs = {} | ||||
local files = {} | local files = {} | ||||
local options = {} | local options = {} | ||||
for w in string.gmatch(result, "[^' ']+") do | for w in string.gmatch(result, "[^' ']+") do | ||||
if string.sub(w,1,2) == "-I" then | if string.sub(w,1,2) == "-I" then | ||||
table.insert(dirs, string.sub(w,3)) | table.insert(dirs, string.sub(w,3)) | ||||
elseif string.sub(w,1,8) == "-isystem" then | |||||
table.insert(dirs, string.sub(w,9)) | |||||
elseif string.sub(w,1,8) == "-include" then | elseif string.sub(w,1,8) == "-include" then | ||||
table.insert(files, string.sub(w,9)) | table.insert(files, string.sub(w,9)) | ||||
else | else | ||||
table.insert(options, w) | table.insert(options, w) | ||||
end | end | ||||
end | end | ||||
sysincludedirs(dirs) | return dirs, files, options | ||||
forceincludes(files) | |||||
buildoptions(options) | |||||
end | end | ||||
function m.add_links(lib, alternative_cmd, alternative_flags) | local function find_links(lib, alternative_cmd, alternative_flags) | ||||
local result | local result | ||||
if not alternative_cmd then | if not alternative_cmd then | ||||
result = os_capture("pkg-config --libs "..lib) | result = os_capture("pkg-config --libs "..lib) | ||||
else | else | ||||
if not alternative_flags then | if not alternative_flags then | ||||
result = os_capture(alternative_cmd.." --libs") | result = os_capture(alternative_cmd.." --libs") | ||||
else | else | ||||
result = os_capture(alternative_cmd.." "..alternative_flags) | result = os_capture(alternative_cmd.." "..alternative_flags) | ||||
Show All 13 Lines | if string.sub(w,1,2) == "-l" then | ||||
table.insert(libs, string.sub(w,3)) | table.insert(libs, string.sub(w,3)) | ||||
elseif string.sub(w,1,2) == "-L" then | elseif string.sub(w,1,2) == "-L" then | ||||
table.insert(dirs, string.sub(w,3)) | table.insert(dirs, string.sub(w,3)) | ||||
else | else | ||||
table.insert(options, w) | table.insert(options, w) | ||||
end | end | ||||
end | end | ||||
return libs, dirs, options | |||||
end | |||||
function m.find_system(lib, alternative_cmd) | |||||
local meths = {} | |||||
function meths.add_includes(alternative_flags) | |||||
local dirs, files, options = find_includes(lib, alternative_cmd, alternative_flags) | |||||
sysincludedirs(dirs) | |||||
forceincludes(files) | |||||
buildoptions(options) | |||||
end | |||||
function meths.add_includes_after_system(alternative_flags) | |||||
local dirs, files, options = find_includes(lib, alternative_cmd, alternative_flags) | |||||
aftersysincludedirs(dirs) | |||||
forceincludes(files) | |||||
buildoptions(options) | |||||
end | |||||
function meths.add_links(alternative_flags) | |||||
local libs, dirs, options = find_links(lib, alternative_cmd, alternative_flags) | |||||
links(libs) | links(libs) | ||||
libdirs(dirs) | libdirs(dirs) | ||||
linkoptions(options) | linkoptions(options) | ||||
end | end | ||||
return meths | |||||
wraitii: I like this approach, I think you ought to add an explicit failure message and rename "load" to… | |||||
Done Inline ActionsI disagree with adding a failure state - it is possible that a dependency might not need any additional include paths on certain systems. For instance, x11 on my machine doesn't need additional include paths beyond the standard system paths. But if one considers the hard-coded paths that were removed in rP22302 (the sysincludedirs), this is clearly not true for everyone. s0600204: I disagree with adding a failure state - it is possible that a dependency might not need any… | |||||
Not Done Inline ActionsIt fails regardless in your code because there are calls with 'nil' then, which should be fixed regardless wraitii: It fails regardless in your code because there are calls with 'nil' then, which should be fixed… | |||||
Not Done Inline ActionsYou mean you're getting error messages and/or the build's failing at this point? s0600204: You mean you're getting error messages and/or the build's failing at this point? | |||||
Not Done Inline ActionsYes, aftersysincludedirs(nil) fails. I added the "fail" because at least it's an explicit failure. If that's not what you want, it ought to be changed. wraitii: Yes, `aftersysincludedirs(nil)` fails. I added the "fail" because at least it's an explicit… | |||||
Not Done Inline ActionsHmm.
Am I missing something? s0600204: Hmm.
1. Replacing `aftersysincludedirs(dirs)` with `aftersysincludedirs(nil)` does not cause… | |||||
end | |||||
return m | return m |
Wildfire Games · Phabricator
I like this approach, I think you ought to add an explicit failure message and rename "load" to "find_system" or something, like so: