Skip to content
Snippets Groups Projects
Commit ce8e73ce authored by Grégoire Kubler's avatar Grégoire Kubler
Browse files

fix : found python in cmake on manylinux images

parent 9c8d5950
No related branches found
No related tags found
2 merge requests!212Version 0.3.0,!116feat/release_pip
Pipeline #45500 failed
...@@ -33,10 +33,12 @@ endif() ...@@ -33,10 +33,12 @@ endif()
# Find system dependencies # Find system dependencies
Include(FetchContent) Include(FetchContent)
set(FMT_VERSION 10.2.1)
message(STATUS "Retrieving fmt ${FMT_VERSION} from git")
FetchContent_Declare( FetchContent_Declare(
fmt fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 10.2.1 # or a later release GIT_TAG ${FMT_VERSION} # or a later release
) )
set(FMT_SYSTEM_HEADERS ON) set(FMT_SYSTEM_HEADERS ON)
...@@ -79,13 +81,13 @@ endif() ...@@ -79,13 +81,13 @@ endif()
# PYTHON BINDING # PYTHON BINDING
if (PYBIND) if (PYBIND)
include(PybindModuleCreation) include(PybindModuleCreation)
# retrieves pybind and python pkg and link them to _aidge_core # retrieves pybind and python pkg and link them to _aidge_core
generate_python_binding(${project} ${module_name}) generate_python_binding()
# Handles Python + pybind11 headers dependencies # Handles Python + pybind11 headers dependencies
target_link_libraries(${module_name} target_link_libraries(${module_name}
PRIVATE PRIVATE
${Python_LIBRARIES} Python::Module
PUBLIC PUBLIC
pybind11::pybind11 pybind11::pybind11
) )
......
function(generate_python_binding name target_to_bind) macro(generate_python_binding )
add_definitions(-DPYBIND) add_definitions(-DPYBIND)
Include(FetchContent) Include(FetchContent)
# Use the New FindPython mode, recommanded. Requires CMake 3.15+
find_package(Python 3.7.0
COMPONENTS Interpreter Development.Module
REQUIRED)
set(PYBIND11_FINDPYTHON ON)
set(PYBIND_VERSION v2.10.4)
message(STATUS "Retrieving pybind ${PYBIND_VERSION} from git")
FetchContent_Declare( FetchContent_Declare(
PyBind11 PyBind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.10.4 # or a later release GIT_TAG ${PYBIND_VERSION} # or a later release
) )
# Use the New FindPython mode, recommanded. Requires CMake 3.15+
find_package(Python 3.7
COMPONENTS Interpreter Development.Module
REQUIRED)
FetchContent_MakeAvailable(PyBind11) FetchContent_MakeAvailable(PyBind11)
message(STATUS "Creating binding for module ${name}") message(STATUS "Creating binding for module ${project}")
file(GLOB_RECURSE pybind_src_files "python_binding/*.cpp") file(GLOB_RECURSE pybind_src_files "python_binding/*.cpp")
pybind11_add_module(${name} MODULE ${pybind_src_files} "NO_EXTRAS") # NO EXTRA recquired for pip install pybind11_add_module(${project} MODULE ${pybind_src_files} "NO_EXTRAS") # NO EXTRA required for pip install
target_include_directories(${name} PUBLIC "python_binding" ) target_include_directories(${project} PUBLIC "python_binding" ${pybind11_INCLUDE_DIRECTORIES})
target_link_libraries(${name} PUBLIC ${target_to_bind}) target_link_libraries(${project} PUBLIC ${module_name})
target_include_directories(${target_to_bind} PRIVATE ${Python_INCLUDE_DIRECTORIES}) endmacro()
target_link_directories(${target_to_bind} PRIVATE ${Python_LIBRARY_DIRS})
endfunction()
# cmake_minimum_required(VERSION 3.18...3.26)
# project(test)
# find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
# set(PYBIND11_FINDPYTHON ON)
# find_package(pybind11 CONFIG REQUIRED)
[project] [project]
name = "aidge_core" name = "aidge_core"
description="Core alogrithms for operators and graph of the AIDGE framework" description="Core alogrithms for operators and graph of the AIDGE framework"
dependencies = ["numpy>=1.21.6"] dependencies = [
"numpy>=1.21.6",
]
requires-python = ">= 3.7" requires-python = ">= 3.7"
readme = "README.md" readme = "README.md"
license = { file = "LICENSE" } license = { file = "LICENSE" }
...@@ -9,13 +11,14 @@ classifiers = [ ...@@ -9,13 +11,14 @@ classifiers = [
"Development Status :: 2 - Pre-Alpha", "Development Status :: 2 - Pre-Alpha",
"Programming Language :: Python :: 3" "Programming Language :: Python :: 3"
] ]
dynamic = ["version"] # defined in tool.setuptools_scm # dynamic = ["version"] # defined in tool.setuptools_scm
version="1"
[build-system] [build-system]
requires = [ requires = [
"setuptools>=64", "setuptools>=64",
"setuptools_scm[toml]==7.1.0", "setuptools_scm[toml]==7.1.0",
"cmake", "cmake>=3.29",
"toml" "toml"
] ]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"
...@@ -29,8 +32,8 @@ include = ["aidge_core*"] # package names should match these glob patterns (["* ...@@ -29,8 +32,8 @@ include = ["aidge_core*"] # package names should match these glob patterns (["*
exclude = ["aidge_core.unit_tests*"] # exclude packages matching these glob patterns (empty by default) exclude = ["aidge_core.unit_tests*"] # exclude packages matching these glob patterns (empty by default)
namespaces = false # to disable scanning PEP 420 namespaces (true by default) namespaces = false # to disable scanning PEP 420 namespaces (true by default)
# SETUPTOOLS_SCM # SETUPTOOLS_SCM
[tool.setuptools_scm] # [tool.setuptools_scm]
write_to = "aidge_core/_version.py" # write_to = "aidge_core/_version.py"
##################################################### #####################################################
# CIBUILDWHEEL # CIBUILDWHEEL
......
...@@ -43,6 +43,18 @@ class CMakeBuild(build_ext): ...@@ -43,6 +43,18 @@ class CMakeBuild(build_ext):
os.chdir(str(build_temp)) os.chdir(str(build_temp))
# Impose to use the executable of the python
# used to launch setup.py to setup PythonInterp
python_executable = sys.executable
python_include_dirs = sysconfig.get_path('include')
python_library = sysconfig.get_config_var('LIBDIR')
python_prefix = sys.exec_prefix
print(f"python\texecutable\t{python_executable}")
print(f"\t\t\tinclude\tdirs {python_include_dirs}")
print(f"-DPYTHON_INCLUDE_DIRS={sysconfig.get_config_var('INCLUDEPY')}") # this might need to be the subdir
print(f"\t\t\tlibrary\t{python_library}")
print(f"-DPYTHON_LIBRARIES={sysconfig.get_config_var('LIBDEST')}")
print(f"\t\t\tprefix\t{python_prefix}")
compile_type = "Debug" compile_type = "Debug"
install_path = ( install_path = (
os.path.join(sys.prefix, "lib", "libAidge") os.path.join(sys.prefix, "lib", "libAidge")
...@@ -53,6 +65,9 @@ class CMakeBuild(build_ext): ...@@ -53,6 +65,9 @@ class CMakeBuild(build_ext):
[ [
"cmake", "cmake",
str(cwd), str(cwd),
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-DPYTHON_INCLUDE_DIRS={sysconfig.get_config_var('INCLUDEPY')}",
f"-DPYTHON_LIBRARIES={sysconfig.get_config_var('LIBDEST')}",
"-DTEST=OFF", "-DTEST=OFF",
f"-DCMAKE_INSTALL_PREFIX:PATH={install_path}", f"-DCMAKE_INSTALL_PREFIX:PATH={install_path}",
f"-DCMAKE_BUILD_TYPE={compile_type}", f"-DCMAKE_BUILD_TYPE={compile_type}",
......
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