55from setuptools .dist import Distribution
66from shutil import copyfile
77from subprocess import check_call
8- from sys import platform
8+ import sys
9+ import sysconfig
10+
11+
12+ def get_python_library ():
13+ """Get path to the python library associated with the current python
14+ interpreter."""
15+ cfgvar = sysconfig .get_config_var
16+ libname = cfgvar ("LDLIBRARY" )
17+ python_library = os .path .join (
18+ cfgvar ("LIBDIR" ) + (cfgvar ("multiarchsubdir" ) or "" ),
19+ libname )
20+ if os .path .exists (python_library ):
21+ return python_library
22+ for root , dirnames , filenames in os .walk (cfgvar ("base" )):
23+ for filename in filenames :
24+ if filename == libname :
25+ return os .path .join (root , filename )
26+ raise FileNotFoundError (libname )
927
1028
1129class CMakeBuild (build_py ):
12- SHLIBEXT = "dylib" if platform == "darwin" else "so"
30+ SHLIBEXT = "dylib" if sys . platform == "darwin" else "so"
1331
1432 def run (self ):
1533 if not self .dry_run :
@@ -22,10 +40,15 @@ def get_outputs(self, *args, **kwargs):
2240 return outputs
2341
2442 def _build (self , builddir = None ):
43+ syspaths = sysconfig .get_paths ()
2544 check_call (("cmake" , "-DCMAKE_BUILD_TYPE=Release" ,
2645 "-DCUDA_TOOLKIT_ROOT_DIR=%s" % os .getenv (
2746 "CUDA_TOOLKIT_ROOT_DIR" ,
2847 "must_export_CUDA_TOOLKIT_ROOT_DIR" ),
48+ "-DPYTHON_DEFAULT_EXECUTABLE=python3" ,
49+ "-DPYTHON_INCLUDE_DIRS=" + syspaths ["include" ],
50+ "-DPYTHON_EXECUTABLE=" + sys .executable ,
51+ "-DPYTHON_LIBRARY=" + get_python_library (),
2952 "." ))
3053 check_call (("make" , "-j%d" % cpu_count ()))
3154 self .mkpath (self .build_lib )
@@ -55,7 +78,7 @@ def is_pure(self):
5578 py_modules = ["libMHCUDA" ],
5679 install_requires = ["numpy" ],
5780 distclass = BinaryDistribution ,
58- cmdclass = {' build_py' : CMakeBuild },
81+ cmdclass = {" build_py" : CMakeBuild },
5982 classifiers = [
6083 "Development Status :: 5 - Production/Stable" ,
6184 "Intended Audience :: Developers" ,
0 commit comments