Skip to content
Snippets Groups Projects
Commit 44f252c8 authored by Maxence Naud's avatar Maxence Naud
Browse files

UPD: 'setup.py' to access compilation options form environment variable set by 'setup.sh'

parent a4322a05
No related branches found
No related tags found
2 merge requests!318[Upd] release verision 0.5.0,!315[UPD] Enforce C++ version and improve setup.py flexibility
......@@ -37,6 +37,7 @@ class CMakeBuild(build_ext):
# This lists the number of processors available on the machine
# The compilation will use half of them
max_jobs = str(ceil(multiprocessing.cpu_count() / 2))
max_jobs = os.environ.get("AIDGE_NB_PROC", max_jobs)
cwd = pathlib.Path().absolute()
......@@ -51,14 +52,19 @@ class CMakeBuild(build_ext):
package_prefix = build_lib if not self.editable_mode else SETUP_DIR
pybind_install_prefix = (package_prefix / PROJECT_NAME).absolute()
os.chdir(str(build_temp))
compile_type = os.environ.get("AIDGE_PYTHON_BUILD_TYPE", "Release")
install_path = (
os.path.join(sys.prefix, "lib", "libAidge")
if "AIDGE_INSTALL" not in os.environ
else os.environ["AIDGE_INSTALL"]
)
# Read environment variables for CMake options
c_compiler = os.environ.get("AIDGE_C_COMPILER", "gcc")
cxx_compiler = os.environ.get("AIDGE_CXX_COMPILER", "g++")
build_type = os.environ.get("AIDGE_BUILD_TYPE", "Release")
asan = os.environ.get("AIDGE_ASAN", "OFF")
cmake_arch = os.environ.get("AIDGE_CMAKE_ARCH", "")
build_gen = os.environ.get("AIDGE_BUILD_GEN", "")
build_gen_opts = (
["-G", build_gen]
......@@ -67,26 +73,35 @@ class CMakeBuild(build_ext):
)
test_onoff = os.environ.get("AIDGE_BUILD_TEST", "OFF")
self.spawn(
[
"cmake",
*build_gen_opts,
str(cwd),
f"-DTEST={test_onoff}",
f"-DCMAKE_INSTALL_PREFIX:PATH={install_path}",
f"-DCMAKE_BUILD_TYPE={compile_type}",
"-DPYBIND=ON",
f"-DPYBIND_INSTALL_PREFIX:PATH={pybind_install_prefix}",
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
"-DCOVERAGE=OFF",
]
)
os.chdir(str(build_temp))
cmake_cmd = [
"cmake",
*build_gen_opts,
str(cwd),
f"-DTEST={test_onoff}",
f"-DCMAKE_INSTALL_PREFIX:PATH={install_path}",
f"-DCMAKE_BUILD_TYPE={build_type}",
f"-DCMAKE_C_COMPILER={c_compiler}",
f"-DCMAKE_CXX_COMPILER={cxx_compiler}",
f"-DENABLE_ASAN={asan}",
"-DPYBIND=ON",
f"-DPYBIND_INSTALL_PREFIX:PATH={pybind_install_prefix}",
"-DCMAKE_EXPORT_COMPILE_COMMANDS=1",
"-DCOVERAGE=OFF",
]
# Append architecture-specific arguments if provided
if cmake_arch:
cmake_cmd.append(cmake_arch)
self.spawn(cmake_cmd)
if not self.dry_run:
self.spawn(
["cmake", "--build", ".", "--config", compile_type, "-j", max_jobs]
["cmake", "--build", ".", "--config", build_type, "-j", max_jobs]
)
self.spawn(["cmake", "--install", ".", "--config", compile_type])
self.spawn(["cmake", "--install", ".", "--config", build_type])
os.chdir(str(cwd))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment