Skip to content

Commit 822e810

Browse files
authored
Add fallback for pkg-config in setup.py (#246)
1 parent d6a3203 commit 822e810

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

setup.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pathlib
21
from setuptools import setup
32
from Cython.Distutils.extension import Extension
43
from Cython.Build import cythonize
@@ -9,32 +8,35 @@
98
MOCKED_ENV = "PYPRECICE_MOCKED"
109

1110

12-
def get_extensions():
11+
def find_precice():
1312
if not pkgconfig.exists("libprecice"):
14-
raise Exception(
15-
"\n".join(
16-
[
17-
"pkg-config was unable to find libprecice.",
18-
"Please make sure that preCICE was installed correctly and pkg-config is able to find it.",
19-
"You may need to set PKG_CONFIG_PATH to include the location of the libprecice.pc file.",
20-
'Use "pkg-config --modversion libprecice" for debugging.',
21-
]
22-
)
13+
print(
14+
"pkg-config was unable to find libprecice.\n"
15+
"Please make sure that preCICE was installed correctly and pkg-config is able to find it.\n"
16+
"You may need to set PKG_CONFIG_PATH to include the location of the libprecice.pc file.\n"
17+
'Use "pkg-config --modversion libprecice" for debugging.'
2318
)
19+
return [], ["-lprecice"]
20+
21+
version = pkgconfig.modversion("libprecice")
22+
print(f"Found preCICE version {version}")
23+
return pkgconfig.cflags("libprecice").split(), pkgconfig.libs("libprecice").split()
2424

25-
print("Found preCICE version " + pkgconfig.modversion("libprecice"))
25+
26+
def get_extensions():
27+
cflags, ldflags = find_precice()
2628

2729
compile_args = ["-std=c++17"]
2830
link_args = []
2931
include_dirs = [numpy.get_include()]
3032
bindings_sources = ["cyprecice/cyprecice.pyx"]
31-
compile_args += pkgconfig.cflags("libprecice").split()
33+
compile_args += cflags
3234

3335
if os.environ.get(MOCKED_ENV) is not None:
3436
print(f"Building mocked pyprecice as {MOCKED_ENV} is set")
3537
bindings_sources.append("test/Participant.cpp")
3638
else:
37-
link_args += pkgconfig.libs("libprecice").split()
39+
link_args += ldflags
3840

3941
return [
4042
Extension(

0 commit comments

Comments
 (0)