From 0d77833bfa6bd5c9ba79cd633ad86a0ea3cc025d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Simonis?= Date: Tue, 14 Oct 2025 13:15:42 +0200 Subject: [PATCH] Add fallback for pkg-config in setup.py --- setup.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/setup.py b/setup.py index 0013d62f..f3a3c2b2 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,3 @@ -import pathlib from setuptools import setup from Cython.Distutils.extension import Extension from Cython.Build import cythonize @@ -9,32 +8,35 @@ MOCKED_ENV = "PYPRECICE_MOCKED" -def get_extensions(): +def find_precice(): if not pkgconfig.exists("libprecice"): - raise Exception( - "\n".join( - [ - "pkg-config was unable to find libprecice.", - "Please make sure that preCICE was installed correctly and pkg-config is able to find it.", - "You may need to set PKG_CONFIG_PATH to include the location of the libprecice.pc file.", - 'Use "pkg-config --modversion libprecice" for debugging.', - ] - ) + print( + "pkg-config was unable to find libprecice.\n" + "Please make sure that preCICE was installed correctly and pkg-config is able to find it.\n" + "You may need to set PKG_CONFIG_PATH to include the location of the libprecice.pc file.\n" + 'Use "pkg-config --modversion libprecice" for debugging.' ) + return [], ["-lprecice"] + + version = pkgconfig.modversion("libprecice") + print(f"Found preCICE version {version}") + return pkgconfig.cflags("libprecice").split(), pkgconfig.libs("libprecice").split() - print("Found preCICE version " + pkgconfig.modversion("libprecice")) + +def get_extensions(): + cflags, ldflags = find_precice() compile_args = ["-std=c++17"] link_args = [] include_dirs = [numpy.get_include()] bindings_sources = ["cyprecice/cyprecice.pyx"] - compile_args += pkgconfig.cflags("libprecice").split() + compile_args += cflags if os.environ.get(MOCKED_ENV) is not None: print(f"Building mocked pyprecice as {MOCKED_ENV} is set") bindings_sources.append("test/Participant.cpp") else: - link_args += pkgconfig.libs("libprecice").split() + link_args += ldflags return [ Extension(