From 6d155613ca1428b69652d5b5653290fa9e63259f Mon Sep 17 00:00:00 2001 From: Ian Harry Date: Fri, 26 Apr 2024 12:01:06 -0700 Subject: [PATCH] Use pkgconfig for lal dirs --- setup.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 1a72a4b..44b63a8 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,7 @@ """ import os +import subprocess from setuptools import setup, Extension @@ -14,6 +15,15 @@ __author__ = "Duncan Macleod " +# Ensure we can find lal libraries +def pkgconfig(package, kw): + flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'} + output = subprocess.getoutput( + 'pkg-config --cflags --libs {}'.format(package)) + for token in output.strip().split(): + kw.setdefault(flag_map.get(token[:2]), []).append(token[2:]) + return kw + # define cython options cython_compile_args = [ @@ -33,16 +43,24 @@ cython_directives["linetrace"] = True cython_compile_args.append("-DCYTHON_TRACE") +# Set extension arguments +extension_kwargs = { + include_dirs=[numpy.get_include()], + language="c", + libraries=["lal"], + extra_compile_args=cython_compile_args, + extra_link_args=[], +} + +# lal arguments +extension_kwargs = pkgconfig('lal', extension_kwargs) + # define compiled extensions exts = [ Extension( "sbank.overlap_cpu", ["sbank/overlap_cpu.pyx"], - include_dirs=[numpy.get_include()], - language="c", - libraries=["lal"], - extra_compile_args=cython_compile_args, - extra_link_args=[], + **extension_kwargs ), ]