mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-20 07:13:56 -07:00
Cherry-pick upstream patch adding support for -idirafter [1] which allows us to work around the issue of some distributions bundling the icu headers with spidermonkey resulting in a conflict. Further add support to our premake pkgconfig module to allow using this feature and make use of it for when building with --with-system-mozjs. [1] premake-core baf145dc388509c953a01bcd964835e2027208bf Fixes: #5868 Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
116 lines
3.5 KiB
Lua
116 lines
3.5 KiB
Lua
local m = {}
|
|
m._VERSION = "1.2.0-dev"
|
|
|
|
m.additional_pc_path = nil
|
|
m.static_link_libs = false
|
|
|
|
local function os_capture(cmd)
|
|
return io.popen(cmd, 'r'):read('*a'):gsub("\n", " ")
|
|
end
|
|
|
|
local function parse_pkg_config_includes(lib, alternative_cmd, alternative_flags)
|
|
local result
|
|
if not alternative_cmd then
|
|
local pc_path = m.additional_pc_path and "PKG_CONFIG_PATH="..m.additional_pc_path or ""
|
|
result = os_capture(pc_path.." pkg-config --cflags "..lib)
|
|
else
|
|
if not alternative_flags then
|
|
result = os_capture(alternative_cmd.." --cflags")
|
|
else
|
|
result = os_capture(alternative_cmd.." "..alternative_flags)
|
|
end
|
|
end
|
|
|
|
-- Small trick: delete the space after -include so that we can detect
|
|
-- which files have to be force-included without difficulty.
|
|
result = result:gsub("%-include +(%g+)", "-include%1")
|
|
result = result:gsub("%-isystem +(%g+)", "-isystem%1")
|
|
|
|
local dirs = {}
|
|
local files = {}
|
|
local options = {}
|
|
for w in string.gmatch(result, "[^' ']+") do
|
|
if string.sub(w,1,2) == "-I" then
|
|
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
|
|
table.insert(files, string.sub(w,9))
|
|
else
|
|
table.insert(options, w)
|
|
end
|
|
end
|
|
|
|
return dirs, files, options
|
|
end
|
|
|
|
function m.add_includes(lib, alternative_cmd, alternative_flags)
|
|
local dirs, files, options = parse_pkg_config_includes(lib, alternative_cmd, alternative_flags)
|
|
|
|
-- As of premake5-beta2, `sysincludedirs` has been deprecated in favour of
|
|
-- `externalincludedirs`, and continuing to use it causes warnings to be emitted.
|
|
-- We use `externalincludedirs` when available to prevent the warnings, falling back
|
|
-- to `sysincludedirs` when not to prevent breakage of the `--with-system-premake5`
|
|
-- build argument.
|
|
if externalincludedirs then
|
|
externalincludedirs(dirs)
|
|
else
|
|
sysincludedirs(dirs)
|
|
end
|
|
|
|
forceincludes(files)
|
|
buildoptions(options)
|
|
end
|
|
|
|
function m.add_includes_after(lib, alternative_cmd, alternative_flags)
|
|
-- Support for includedirsafter was added after the 5.0.0-beta2 release.
|
|
-- Fall back if unavailable to support `--with-system-premake5`
|
|
if includedirsafter then
|
|
local dirs, files, options = parse_pkg_config_includes(lib, alternative_cmd, alternative_flags)
|
|
|
|
includedirsafter(dirs)
|
|
forceincludes(files)
|
|
buildoptions(options)
|
|
else
|
|
m.add_includes(lib, alternative_cmd, alternative_flags)
|
|
end
|
|
end
|
|
|
|
function m.add_links(lib, alternative_cmd, alternative_flags)
|
|
local result
|
|
if not alternative_cmd then
|
|
local pc_path = m.additional_pc_path and "PKG_CONFIG_PATH="..m.additional_pc_path or ""
|
|
local static = m.static_link_libs and " --static " or ""
|
|
result = os_capture(pc_path.." pkg-config --libs "..static..lib)
|
|
else
|
|
if not alternative_flags then
|
|
result = os_capture(alternative_cmd.." --libs")
|
|
else
|
|
result = os_capture(alternative_cmd.." "..alternative_flags)
|
|
end
|
|
end
|
|
|
|
-- On OSX, wx-config outputs "-framework foo" instead of "-Wl,-framework,foo"
|
|
-- which doesn't fare well with the splitting into libs, libdirs and options
|
|
-- we perform afterwards.
|
|
result = result:gsub("%-framework +(%g+)", "-Wl,-framework,%1")
|
|
|
|
local libs = {}
|
|
local dirs = {}
|
|
local options = {}
|
|
for w in string.gmatch(result, "[^' ']+") do
|
|
if string.sub(w,1,2) == "-l" then
|
|
table.insert(libs, string.sub(w,3))
|
|
elseif string.sub(w,1,2) == "-L" then
|
|
table.insert(dirs, string.sub(w,3))
|
|
else
|
|
table.insert(options, w)
|
|
end
|
|
end
|
|
|
|
links(libs)
|
|
libdirs(dirs)
|
|
linkoptions(options)
|
|
end
|
|
|
|
return m
|