Add support for specifying pkg-config via env

For cross compiling there is a need to specify an alternative binary for
pkg-config. It's customary to use the environment variable PKG_CONFIG for
this.

Ref: #8135
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
(cherry picked from commit 2b5830e82a)
Signed-off-by: Itms <itms@wildfiregames.com>
This commit is contained in:
Ralph Sennhauser
2025-06-27 08:24:34 +02:00
committed by Itms
parent bf4eee555f
commit 0dbc1f604a
+8 -3
View File
@@ -1,9 +1,14 @@
local m = {}
m._VERSION = "1.2.0-dev"
m._VERSION = "1.3.0-dev"
m.additional_pc_path = nil
m.static_link_libs = false
local pkg_config_command = "pkg-config"
if os.getenv("PKG_CONFIG") then
pkg_config_command = os.getenv("PKG_CONFIG")
end
local function os_capture(cmd)
return io.popen(cmd, 'r'):read('*a'):gsub("\n", " ")
end
@@ -12,7 +17,7 @@ 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)
result = os_capture(pc_path .. " " .. pkg_config_command .. " --cflags " .. lib)
else
if not alternative_flags then
result = os_capture(alternative_cmd.." --cflags")
@@ -81,7 +86,7 @@ function m.add_links(lib, alternative_cmd, alternative_flags)
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)
result = os_capture(pc_path .. " " .. pkg_config_command .. " --libs " .. static .. lib)
else
if not alternative_flags then
result = os_capture(alternative_cmd.." --libs")