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)
70 "-DCMAKE_BUILD_TYPE={}".format(cfg),
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 "VCPKG_INSTALLATION_ROOT" in os.environ:
84 f
"-DCMAKE_TOOLCHAIN_FILE={os.environ['VCPKG_INSTALLATION_ROOT']}/scripts/buildsystems/vcpkg.cmake"
87 if "CIRCT_EXTRA_CMAKE_ARGS" in os.environ:
88 cmake_args += os.environ[
"CIRCT_EXTRA_CMAKE_ARGS"].split(
" ")
94 if platform.system() ==
"Linux":
95 python_libdir = sysconfig.get_config_var(
'LIBDIR')
96 python_library = sysconfig.get_config_var(
'LIBRARY')
97 if python_libdir
and not os.path.isabs(python_library):
98 python_library = os.path.join(python_libdir, python_library)
99 if python_library
and not os.path.exists(python_library):
100 print(
"Detected static linked python. Faking a library for cmake.")
101 fake_libdir = os.path.join(cmake_build_dir,
"fake_python",
"lib")
102 os.makedirs(fake_libdir, exist_ok=
True)
103 fake_library = os.path.join(fake_libdir,
104 sysconfig.get_config_var(
'LIBRARY'))
105 subprocess.check_call([
"ar",
"q", fake_library])
106 cmake_args.append(
"-DPython3_LIBRARY:PATH={}".format(fake_library))
109 subprocess.check_call([
"cmake", src_dir] + cmake_args, cwd=cmake_build_dir)
110 print(
" ".join([
"cmake", src_dir] + cmake_args))
113 subprocess.check_call([
124 if os.path.exists(target_dir):
125 shutil.rmtree(target_dir)
126 subprocess.check_call([
127 "cmake",
"--install",
".",
"--prefix",
128 os.path.join(target_dir,
"esiaccel"),
"--component",
"ESIRuntime"
139 setup(name=
"esiaccel",
140 include_package_data=
True,
142 CMakeExtension(
"esiaccel.esiCppAccel"),
145 "build": CustomBuild,
146 "built_ext": NoopBuildExtension,
147 "build_py": CMakeBuild,
150 packages=find_namespace_packages(include=[
def __init__(self, name, sourcedir="")
def build_extension(self, ext)