diff --git a/setup.py b/setup.py index ea931a6..6c322f3 100644 --- a/setup.py +++ b/setup.py @@ -7,8 +7,10 @@ """ import glob +import os import sys from ctypes.util import find_library +from pathlib import Path import numpy from setuptools import Extension, setup @@ -26,11 +28,33 @@ def get_boost_libraries(): raise RuntimeError("Cannot find a suitable Boost.Python library.") +def get_boost_config(): + boost_path = os.environ.get("BOOST_PATH", "") + if boost_path: + inc = Path(boost_path) / "include" + lib = Path(boost_path) / "lib" + else: + conda_prefix = os.environ.get("CONDA_PREFIX") + if not conda_prefix: + raise EnvironmentError( + "Neither BOOST_PATH nor CONDA_PREFIX are set. " "Please install Boost or set BOOST_PATH." + ) + if os.name == "nt": + inc = Path(conda_prefix) / "Library" / "include" + lib = Path(conda_prefix) / "Library" / "lib" + else: + inc = Path(conda_prefix) / "include" + lib = Path(conda_prefix) / "lib" + return {"include_dirs": [str(inc)], "library_dirs": [str(lib)]} + + +boost_cfg = get_boost_config() ext_kws = { "libraries": ["diffpy"] + get_boost_libraries(), "extra_compile_args": ["-std=c++11"], "extra_link_args": [], - "include_dirs": [numpy.get_include()], + "include_dirs": [numpy.get_include()] + boost_cfg["include_dirs"], + "library_dirs": boost_cfg["library_dirs"], }