2021-05-21 23:44:28 +00:00
|
|
|
-- Helper methods to use the system pkg-config utility
|
|
|
|
|
|
|
|
pkg_config = {}
|
|
|
|
|
|
|
|
function pkg_config.cflags(lib)
|
2021-07-20 17:16:39 +00:00
|
|
|
if not os.istarget("linux") then
|
2021-05-21 23:44:28 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
buildoptions({
|
|
|
|
({os.outputof("pkg-config --cflags "..lib)})[1],
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
function pkg_config.lflags(lib)
|
2021-07-20 17:16:39 +00:00
|
|
|
if not os.istarget("linux") then
|
2021-05-21 23:44:28 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
linkoptions({
|
|
|
|
({os.outputof("pkg-config --libs-only-L " ..lib)})[1],
|
|
|
|
({os.outputof("pkg-config --libs-only-other "..lib)})[1],
|
|
|
|
})
|
|
|
|
-- We can't just drop the stdout of the `--libs` command in
|
|
|
|
-- linkoptions because library order matters
|
|
|
|
local output = ({os.outputof("pkg-config --libs-only-l "..lib)})[1]
|
|
|
|
for k, flag in next, string.explode(output, " ") do
|
|
|
|
-- remove "-l"
|
2021-07-21 14:32:58 +00:00
|
|
|
if flag ~= "" then
|
|
|
|
links(string.sub(flag, 3))
|
|
|
|
end
|
2021-05-21 23:44:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function pkg_config.all(lib)
|
|
|
|
pkg_config.cflags(lib)
|
|
|
|
pkg_config.lflags(lib)
|
|
|
|
end
|