Skip to content
Snippets Groups Projects
Commit dd7fdacf authored by Christophe Guillon's avatar Christophe Guillon
Browse files

[CMake] Add installation of python binding

Add installation of the python bindings target to the build system.
This avoids to have a specific postprocessing in the
python package management tools.
parent 1f76661a
No related branches found
No related tags found
2 merge requests!212Version 0.3.0,!154[Setup] Add support for development install
......@@ -16,6 +16,7 @@ message(STATUS "Project version: ${version}")
# Note : project name is {project} and python module name is also {project}
set(module_name _${CMAKE_PROJECT_NAME}) # target name
set(pybind_module_name ${CMAKE_PROJECT_NAME}) # name of submodule for python bindings
##############################################
# Define options
......@@ -84,8 +85,12 @@ endif()
# PYTHON BINDING
if (PYBIND)
# Python binding lib is by default installed in <prefix>/python_packages/<package>/
# When installed from python, setup.py should set it to the python package dir
set(PYBIND_INSTALL_PREFIX python_packages/${pybind_module_name} CACHE PATH "Python package install prefix")
include(PybindModuleCreation)
generate_python_binding(${CMAKE_PROJECT_NAME} ${module_name})
generate_python_binding(${pybind_module_name} ${module_name})
# Handles Python + pybind11 headers dependencies
target_link_libraries(${module_name}
......@@ -156,6 +161,12 @@ install(TARGETS ${module_name} EXPORT ${CMAKE_PROJECT_NAME}-targets
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if (PYBIND)
install(TARGETS ${pybind_module_name}
DESTINATION ${PYBIND_INSTALL_PREFIX}
)
endif()
#Export the targets to a script
install(EXPORT ${CMAKE_PROJECT_NAME}-targets
......
......@@ -33,6 +33,9 @@ class CMakeBuild(build_ext):
if not build_lib.exists():
build_lib.mkdir(parents=True, exist_ok=True)
package_prefix = build_lib
pybind_install_prefix = (package_prefix / PROJECT_NAME).absolute()
os.chdir(str(build_temp))
compile_type = os.environ.get("AIDGE_PYTHON_BUILD_TYPE", "Release")
......@@ -57,6 +60,7 @@ class CMakeBuild(build_ext):
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",
]
......@@ -69,20 +73,6 @@ class CMakeBuild(build_ext):
self.spawn(["cmake", "--install", ".", "--config", compile_type])
os.chdir(str(cwd))
aidge_package = build_lib / PROJECT_NAME
# Get "aidge core" package
# ext_lib = build_temp
print(build_temp.absolute())
# Copy all shared object files from build_temp/lib to aidge_package
for root, _, files in os.walk(build_temp.absolute()):
for file in files:
if (file.endswith(".so") or file.endswith(".pyd")) and (
root != str(aidge_package.absolute())
):
currentFile = os.path.join(root, file)
shutil.copy(currentFile, str(aidge_package.absolute()))
if __name__ == "__main__":
setup(
......
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