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

chore : refactored pybindmodule creation

parent 1ebf322c
No related branches found
No related tags found
2 merge requests!212Version 0.3.0,!116feat/release_pip
function(generate_python_binding pybind_module_name target_to_bind) function(generate_python_binding name target_to_bind)
add_definitions(-DPYBIND)
Include(FetchContent)
set(PYBIND_VERSION v2.10.4) find_package(Python COMPONENTS Interpreter Development.Module)
set(PYBIND11_FINDPYTHON ON)
message(STATUS "Retrieving pybind ${PYBIND_VERSION} from git")
add_definitions(-DPYBIND)
Include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
PyBind11 PyBind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG ${PYBIND_VERSION} # or a later release GIT_TAG v2.10.4 # or a later release
) )
# Use the New FindPython mode, recommanded. Requires CMake 3.15+
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
FetchContent_MakeAvailable(PyBind11) FetchContent_MakeAvailable(PyBind11)
message(STATUS "Creating binding for module ${pybind_module_name}") message(STATUS "Creating binding for module ${name}")
file(GLOB_RECURSE pybind_src_files "python_binding/*.cpp") file(GLOB_RECURSE pybind_src_files "python_binding/*.cpp")
pybind11_add_module(${pybind_module_name} MODULE ${pybind_src_files} "NO_EXTRAS") # NO EXTRA recquired for pip install pybind11_add_module(${name} MODULE ${pybind_src_files} "NO_EXTRAS") # NO EXTRA recquired for pip install
target_include_directories(${pybind_module_name} PUBLIC "python_binding") target_include_directories(${name} PUBLIC "python_binding")
target_link_libraries(${pybind_module_name} PUBLIC ${target_to_bind})
# Handles Python + pybind11 headers dependencies
target_link_libraries(${name}
PUBLIC
${target_to_bind}
)
endfunction() endfunction()
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