From c2cc762616ba6bd2bbc57fc2fda999ac80d1c80b Mon Sep 17 00:00:00 2001 From: Ralph Sennhauser Date: Sat, 5 Jul 2025 21:09:52 +0200 Subject: [PATCH] Better handling of PKG_CONFIG_PATH Allow override PKG_CONFIG_PATH via env, making it possible to easily inject alternative library builds for testing or bisecting. This was only possible when the premake script didn't override it which it unconditionally did on macos. Also don't expose the variable holding the path directly but offer a function to append to the path instead. Ref: #8135 Signed-off-by: Ralph Sennhauser --- build/premake/extern_libs5.lua | 2 +- build/premake/pkgconfig/pkgconfig.lua | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/build/premake/extern_libs5.lua b/build/premake/extern_libs5.lua index 17301b3295..3baabd7ef4 100644 --- a/build/premake/extern_libs5.lua +++ b/build/premake/extern_libs5.lua @@ -64,7 +64,7 @@ pkgconfig = require "pkgconfig" -- Configure pkgconfig for MacOSX systems if os.istarget("macosx") then - pkgconfig.additional_pc_path = libraries_dir .. "pkgconfig/" + pkgconfig.add_pkg_config_path(libraries_dir .. "pkgconfig/") pkgconfig.static_link_libs = true end diff --git a/build/premake/pkgconfig/pkgconfig.lua b/build/premake/pkgconfig/pkgconfig.lua index d1523c2de5..166fde2fb7 100644 --- a/build/premake/pkgconfig/pkgconfig.lua +++ b/build/premake/pkgconfig/pkgconfig.lua @@ -1,7 +1,6 @@ local m = {} -m._VERSION = "1.3.0-dev" +m._VERSION = "1.4.0-dev" -m.additional_pc_path = nil m.static_link_libs = false local pkg_config_command = "pkg-config" @@ -9,6 +8,12 @@ if os.getenv("PKG_CONFIG") then pkg_config_command = os.getenv("PKG_CONFIG") end +local pkg_config_path = "" +if os.getenv("PKG_CONFIG_PATH") then + pkg_config_path = os.getenv("PKG_CONFIG_PATH") +end + + local function os_capture(cmd) return io.popen(cmd, 'r'):read('*a'):gsub("\n", " ") end @@ -16,8 +21,7 @@ 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_command .. " --cflags " .. lib) + result = os_capture("PKG_CONFIG_PATH=" .. pkg_config_path .. " " .. pkg_config_command .. " --cflags " .. lib) else if not alternative_flags then result = os_capture(alternative_cmd.." --cflags") @@ -49,6 +53,14 @@ local function parse_pkg_config_includes(lib, alternative_cmd, alternative_flags return dirs, files, options end +function m.add_pkg_config_path(path) + if pkg_config_path == "" then + pkg_config_path = path + else + pkg_config_path = pkg_config_path .. ":" .. path + end +end + function m.add_includes(lib, alternative_cmd, alternative_flags) local dirs, files, options = parse_pkg_config_includes(lib, alternative_cmd, alternative_flags) @@ -68,9 +80,8 @@ 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_command .. " --libs " .. static .. lib) + result = os_capture("PKG_CONFIG_PATH=" .. pkg_config_path .. " " .. pkg_config_command .. " --libs " .. static .. lib) else if not alternative_flags then result = os_capture(alternative_cmd.." --libs")