From cf7ad07ff81d2d85c74d7df18c875b51c562fa95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20KUBLER?= <gregoire.kubler@proton.me> Date: Thu, 4 Jul 2024 14:41:11 +0200 Subject: [PATCH] chore : refactored pybindmodule creation --- cmake/PybindModuleCreation.cmake | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/cmake/PybindModuleCreation.cmake b/cmake/PybindModuleCreation.cmake index 2e58bb65a..e2bbb2c3f 100644 --- a/cmake/PybindModuleCreation.cmake +++ b/cmake/PybindModuleCreation.cmake @@ -1,25 +1,25 @@ -function(generate_python_binding pybind_module_name target_to_bind) - add_definitions(-DPYBIND) - Include(FetchContent) +function(generate_python_binding name target_to_bind) - set(PYBIND_VERSION v2.10.4) - set(PYBIND11_FINDPYTHON ON) - message(STATUS "Retrieving pybind ${PYBIND_VERSION} from git") + find_package(Python COMPONENTS Interpreter Development.Module) + add_definitions(-DPYBIND) + Include(FetchContent) FetchContent_Declare( - PyBind11 - GIT_REPOSITORY https://github.com/pybind/pybind11.git - GIT_TAG ${PYBIND_VERSION} # or a later release + PyBind11 + GIT_REPOSITORY https://github.com/pybind/pybind11.git + 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) - 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") - pybind11_add_module(${pybind_module_name} MODULE ${pybind_src_files} "NO_EXTRAS") # NO EXTRA recquired for pip install - target_include_directories(${pybind_module_name} PUBLIC "python_binding") - target_link_libraries(${pybind_module_name} PUBLIC ${target_to_bind}) + pybind11_add_module(${name} MODULE ${pybind_src_files} "NO_EXTRAS") # NO EXTRA recquired for pip install + target_include_directories(${name} PUBLIC "python_binding") + + # Handles Python + pybind11 headers dependencies + target_link_libraries(${name} + PUBLIC + ${target_to_bind} + ) endfunction() -- GitLab