26 from distutils.command.build
import build
as _build
27 from setuptools
import find_namespace_packages, setup, Extension
28 from setuptools.command.build_ext
import build_ext
29 from setuptools.command.build_py
import build_py
31 _thisdir = os.path.abspath(os.path.dirname(__file__))
38 self.run_command(
"build_py")
39 self.run_command(
"build_ext")
40 self.run_command(
"build_scripts")
46 Extension.__init__(self, name, sources=[])
47 self.
sourcedirsourcedir = os.path.abspath(sourcedir)
54 target_dir = os.path.abspath(self.build_lib)
55 cmake_build_dir = os.getenv(
"PYCDE_CMAKE_BUILD_DIR")
56 if not cmake_build_dir:
57 cmake_build_dir = os.path.abspath(
58 os.path.join(target_dir,
"..",
"cmake_build"))
61 os.makedirs(cmake_build_dir, exist_ok=
True)
62 cmake_cache_file = os.path.join(cmake_build_dir,
"CMakeCache.txt")
63 if os.path.exists(cmake_cache_file):
64 os.remove(cmake_cache_file)
69 "-DCMAKE_BUILD_TYPE={}".format(cfg),
70 "-DCAPNP_PATH={}".format(os.getenv(
"CAPNP_PATH")),
71 "-DPython3_EXECUTABLE={}".format(sys.executable.replace(
"\\",
"/")),
74 cxx = os.getenv(
"CXX")
76 cmake_args.append(
"-DCMAKE_CXX_COMPILER={}".format(cxx))
80 cmake_args.append(
"-DCMAKE_C_COMPILER={}".format(cc))
82 if "CIRCT_EXTRA_CMAKE_ARGS" in os.environ:
83 cmake_args += os.environ[
"CIRCT_EXTRA_CMAKE_ARGS"].split(
" ")
89 if platform.system() ==
"Linux":
90 python_libdir = sysconfig.get_config_var(
'LIBDIR')
91 python_library = sysconfig.get_config_var(
'LIBRARY')
92 if python_libdir
and not os.path.isabs(python_library):
93 python_library = os.path.join(python_libdir, python_library)
94 if python_library
and not os.path.exists(python_library):
95 print(
"Detected static linked python. Faking a library for cmake.")
96 fake_libdir = os.path.join(cmake_build_dir,
"fake_python",
"lib")
97 os.makedirs(fake_libdir, exist_ok=
True)
98 fake_library = os.path.join(fake_libdir,
99 sysconfig.get_config_var(
'LIBRARY'))
100 subprocess.check_call([
"ar",
"q", fake_library])
101 cmake_args.append(
"-DPython3_LIBRARY:PATH={}".format(fake_library))
104 subprocess.check_call([
"cmake", src_dir] + cmake_args, cwd=cmake_build_dir)
107 subprocess.check_call([
121 if os.path.exists(target_dir):
122 shutil.rmtree(target_dir)
123 subprocess.check_call([
124 "cmake",
"--install",
".",
"--prefix",
125 os.path.join(target_dir,
"esiaccel"),
"--component",
"ESIRuntime"
136 setup(name=
"esiaccel",
137 include_package_data=
True,
139 CMakeExtension(
"esiaccel.esiCppAccel"),
142 "build": CustomBuild,
143 "built_ext": NoopBuildExtension,
144 "build_py": CMakeBuild,
147 packages=find_namespace_packages(include=[
def __init__(self, name, sourcedir="")
def build_extension(self, ext)