From 9ea46247048f861f088f09541cd434aeb16e6f9c Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Tue, 15 Mar 2022 23:31:59 -0600 Subject: [PATCH 1/2] Search pkg-config system libs/cflags. We need to search the system paths as well from pkg-config for some packages to be found properly. --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 9a05e5105..d41aedbd6 100755 --- a/setup.py +++ b/setup.py @@ -252,8 +252,8 @@ def _cmd_exists(cmd): def _pkg_config(name): try: command = os.environ.get("PKG_CONFIG", "pkg-config") - command_libs = [command, "--libs-only-L", name] - command_cflags = [command, "--cflags-only-I", name] + command_libs = [command, "--libs-only-L", "--keep-system-libs", name] + command_cflags = [command, "--cflags-only-I", "--keep-system-cflags", name] if not DEBUG: command_libs.append("--silence-errors") command_cflags.append("--silence-errors") From 6ec9dfb9c0bc04a5504231887a3fb86cb8863721 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 23 Apr 2022 21:58:30 +1000 Subject: [PATCH 2/2] If an exception is raised, try again without system paths --- setup.py | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/setup.py b/setup.py index d41aedbd6..37bb2ceb8 100755 --- a/setup.py +++ b/setup.py @@ -250,28 +250,32 @@ def _cmd_exists(cmd): def _pkg_config(name): - try: - command = os.environ.get("PKG_CONFIG", "pkg-config") - command_libs = [command, "--libs-only-L", "--keep-system-libs", name] - command_cflags = [command, "--cflags-only-I", "--keep-system-cflags", name] - if not DEBUG: - command_libs.append("--silence-errors") - command_cflags.append("--silence-errors") - libs = ( - subprocess.check_output(command_libs) - .decode("utf8") - .strip() - .replace("-L", "") - ) - cflags = ( - subprocess.check_output(command_cflags) - .decode("utf8") - .strip() - .replace("-I", "") - ) - return libs, cflags - except Exception: - pass + command = os.environ.get("PKG_CONFIG", "pkg-config") + for keep_system in (True, False): + try: + command_libs = [command, "--libs-only-L", name] + command_cflags = [command, "--cflags-only-I", name] + if keep_system: + command_libs.append("--keep-system-libs") + command_cflags.append("--keep-system-cflags") + if not DEBUG: + command_libs.append("--silence-errors") + command_cflags.append("--silence-errors") + libs = ( + subprocess.check_output(command_libs) + .decode("utf8") + .strip() + .replace("-L", "") + ) + cflags = ( + subprocess.check_output(command_cflags) + .decode("utf8") + .strip() + .replace("-I", "") + ) + return libs, cflags + except Exception: + pass class pil_build_ext(build_ext):