From 722579d671749cb22688e565941a3d0a19487d8d Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Thu, 18 May 2017 11:47:51 +0200 Subject: [PATCH] Guess include and lib directory using capnp executable --- buildutils/detect.py | 4 ++-- setup.py | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/buildutils/detect.py b/buildutils/detect.py index 03f1be4..4a1c117 100644 --- a/buildutils/detect.py +++ b/buildutils/detect.py @@ -148,7 +148,7 @@ def detect_version(basedir, compiler=None, **compiler_attrs): return props -def test_build(): +def test_build(**compiler_attrs): """do a test build of libcapnp""" tmp_dir = tempfile.mkdtemp() @@ -156,7 +156,7 @@ def test_build(): # info("Configure: Autodetecting Cap'n Proto settings...") # info(" Custom Cap'n Proto dir: %s" % prefix) try: - detected = detect_version(tmp_dir) + detected = detect_version(tmp_dir, None, **compiler_attrs) finally: erase_dir(tmp_dir) diff --git a/setup.py b/setup.py index f070213..09ac805 100644 --- a/setup.py +++ b/setup.py @@ -11,6 +11,7 @@ import sys from distutils.command.clean import clean as _clean from distutils.errors import CompileError from distutils.extension import Extension +from distutils.spawn import find_executable from setuptools import setup @@ -113,10 +114,16 @@ class build_libcapnp_ext(build_ext_c): elif force_system_libcapnp: need_build = False else: + # Try to use capnp executable to find include and lib path + capnp_executable = find_executable("capnp") + if capnp_executable: + self.include_dirs += [os.path.join(os.path.dirname(capnp_executable), '..', 'include')] + self.library_dirs += [os.path.join(os.path.dirname(capnp_executable), '..', 'lib')] + # Try to autodetect presence of library. Requires compile/run # step so only works for host (non-cross) compliation try: - test_build() + test_build(include_dirs=self.include_dirs, library_dirs=self.library_dirs) need_build = False except CompileError: need_build = True