Skip to content

Commit 25cc682

Browse files
committed
windows support
1 parent b075de8 commit 25cc682

File tree

1 file changed

+58
-11
lines changed

1 file changed

+58
-11
lines changed

setup.py

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,36 @@
1717

1818

1919
def get_boost_libraries():
20-
base_lib = "boost_python"
21-
major, minor = str(sys.version_info[0]), str(sys.version_info[1])
22-
tags = [f"{major}{minor}", major, ""]
23-
mttags = ["", "-mt"]
24-
candidates = [base_lib + tag for tag in tags for mt in mttags] + [base_lib]
25-
for lib in candidates:
26-
if find_library(lib):
27-
return [lib]
28-
raise RuntimeError("Cannot find a suitable Boost.Python library.")
20+
"""
21+
Link against both Boost.Python and Boost.Serialization
22+
from the active conda env’s lib/ directory.
23+
"""
24+
conda_prefix = os.environ.get("CONDA_PREFIX")
25+
if not conda_prefix:
26+
raise EnvironmentError("CONDA_PREFIX is not set; please activate your conda environment.")
27+
28+
libdir = Path(conda_prefix) / "lib"
29+
major, minor = sys.version_info[:2]
30+
31+
# look for the _python_ library
32+
py_cands = [f"boost_python{major}{minor}", f"boost_python{major}", "boost_python"]
33+
for lib in py_cands:
34+
if (libdir / f"lib{lib}.so").exists():
35+
boost_py = lib
36+
break
37+
else:
38+
raise RuntimeError(f"Could not find any of {py_cands!r} in {libdir}")
39+
40+
# look for the _serialization_ library
41+
ser_cands = ["boost_serialization"]
42+
for lib in ser_cands:
43+
if (libdir / f"lib{lib}.so").exists():
44+
boost_ser = lib
45+
break
46+
else:
47+
raise RuntimeError(f"Could not find any of {ser_cands!r} in {libdir}")
48+
49+
return [boost_ser, boost_py]
2950

3051

3152
def get_boost_config():
@@ -48,20 +69,46 @@ def get_boost_config():
4869
return {"include_dirs": [str(inc)], "library_dirs": [str(lib)]}
4970

5071

72+
def get_objcryst_libraries():
73+
conda_prefix = os.environ.get("CONDA_PREFIX")
74+
if not conda_prefix:
75+
raise EnvironmentError(
76+
"CONDA_PREFIX is not set. Please install ObjCryst using conda and activate the environment."
77+
)
78+
if os.name == "nt":
79+
libdir = Path(conda_prefix) / "Library" / "lib"
80+
else:
81+
libdir = Path(conda_prefix) / "lib"
82+
83+
libs = []
84+
for fn in os.listdir(libdir):
85+
low = fn.lower()
86+
if low.endswith(".lib") and "objcryst" in low:
87+
libs.append(os.path.splitext(fn)[0])
88+
if not libs:
89+
raise RuntimeError(f"No ObjCryst libraries found in {libdir}")
90+
return libs
91+
92+
5193
if os.name == "nt":
5294
compile_args = ["/std:c++14"]
5395
macros = [("_USE_MATH_DEFINES", None)]
96+
extra_link_args = ["/FORCE:MULTIPLE"]
5497
else:
5598
compile_args = ["-std=c++11"]
5699
macros = []
100+
extra_link_args = []
57101

58102
boost_cfg = get_boost_config()
103+
objcryst_libs = get_objcryst_libraries()
104+
59105
ext_kws = {
60-
"libraries": ["diffpy"] + get_boost_libraries(),
106+
"libraries": ["diffpy"] + get_boost_libraries() + objcryst_libs,
61107
"extra_compile_args": compile_args,
62-
"extra_link_args": [],
108+
"extra_link_args": extra_link_args,
63109
"include_dirs": [numpy.get_include()] + boost_cfg["include_dirs"],
64110
"library_dirs": boost_cfg["library_dirs"],
111+
"runtime_library_dirs": boost_cfg["library_dirs"],
65112
"define_macros": macros,
66113
}
67114

0 commit comments

Comments
 (0)