54 target_dir = os.path.abspath(self.build_lib)
55 cmake_build_dir = os.getenv(
"CMAKE_BUILD_DIR")
56 if not cmake_build_dir:
57 cmake_build_dir = os.path.abspath(
58 os.path.join(target_dir,
"..",
"cmake_build"))
65 configs_to_build = [
"Release"]
67 for cfg
in configs_to_build:
68 current_build_dir = cmake_build_dir
70 os.makedirs(current_build_dir, exist_ok=
True)
71 cmake_cache_file = os.path.join(current_build_dir,
"CMakeCache.txt")
72 if os.path.exists(cmake_cache_file):
73 os.remove(cmake_cache_file)
78 "-DCMAKE_BUILD_TYPE={}".format(cfg),
79 "-DPython3_EXECUTABLE={}".format(sys.executable.replace(
"\\",
"/")),
80 "-DPython_EXECUTABLE={}".format(sys.executable.replace(
"\\",
"/")),
90 nanobind_dir = nanobind.cmake_dir()
91 cmake_args.append(
"-Dnanobind_DIR={}".format(
92 nanobind_dir.replace(
"\\",
"/")))
94 print(
"Skipping nanobind directory detection, nanobind not found.")
96 cxx = os.getenv(
"CXX")
98 cmake_args.append(
"-DCMAKE_CXX_COMPILER={}".format(cxx))
99 cxxflags = os.getenv(
"CXXFLAGS")
100 if cxxflags
is not None:
101 cmake_args.append(
"-DCMAKE_CXX_FLAGS={}".format(cxxflags))
105 cmake_args.append(
"-DCMAKE_C_COMPILER={}".format(cc))
106 cflags = os.getenv(
"CFLAGS")
107 if cflags
is not None:
108 cmake_args.append(
"-DCMAKE_C_FLAGS={}".format(cflags))
110 if "VCPKG_INSTALLATION_ROOT" in os.environ:
112 f
"-DCMAKE_TOOLCHAIN_FILE={os.environ['VCPKG_INSTALLATION_ROOT']}/scripts/buildsystems/vcpkg.cmake"
115 if "CIRCT_EXTRA_CMAKE_ARGS" in os.environ:
116 cmake_args += os.environ[
"CIRCT_EXTRA_CMAKE_ARGS"].split(
" ")
122 if platform.system() ==
"Linux":
123 python_libdir = sysconfig.get_config_var(
'LIBDIR')
124 python_library = sysconfig.get_config_var(
'LIBRARY')
125 if python_libdir
and not os.path.isabs(python_library):
126 python_library = os.path.join(python_libdir, python_library)
127 if python_library
and not os.path.exists(python_library):
128 print(
"Detected static linked python. Faking a library for cmake.")
129 fake_libdir = os.path.join(current_build_dir,
"fake_python",
"lib")
130 os.makedirs(fake_libdir, exist_ok=
True)
131 fake_library = os.path.join(fake_libdir,
132 sysconfig.get_config_var(
'LIBRARY'))
133 subprocess.check_call([
"ar",
"q", fake_library])
134 cmake_args.append(
"-DPython3_LIBRARY:PATH={}".format(fake_library))
137 print(f
"Configuring {cfg} build...")
138 subprocess.check_call([
"cmake", src_dir] + cmake_args,
139 cwd=current_build_dir)
140 print(
" ".join([
"cmake", src_dir] + cmake_args))
149 print(f
"Building {cfg} configuration...")
150 subprocess.check_call(
159 cwd=current_build_dir,
163 if cfg ==
"Release" and os.path.exists(target_dir):
164 shutil.rmtree(target_dir)
166 print(f
"Installing {cfg} configuration...")
167 subprocess.check_call(
173 os.path.join(target_dir,
"esiaccel"),
177 cwd=current_build_dir,
184 source_dst = os.path.join(target_dir,
"esiaccel",
"source")
185 if os.path.exists(source_dst):
186 shutil.rmtree(source_dst)
187 os.makedirs(source_dst, exist_ok=
True)
188 print(f
"Copying C++ sources into wheel at {source_dst}")
189 shutil.copy2(os.path.join(src_dir,
"CMakeLists.txt"), source_dst)
190 cosim_proto_doc = os.path.join(src_dir,
"cosim-protocol.md")
191 if os.path.exists(cosim_proto_doc):
192 shutil.copy2(cosim_proto_doc, source_dst)
196 shutil.copytree(os.path.join(src_dir,
"cpp"),
197 os.path.join(source_dst,
"cpp"),
198 ignore=shutil.ignore_patterns(
"cmake"))
199 shutil.copytree(os.path.join(src_dir,
"cosim_dpi_server"),
200 os.path.join(source_dst,
"cosim_dpi_server"))