macro(generate_python_binding ) add_definitions(-DPYBIND) 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( PyBind11 GIT_REPOSITORY https://github.com/pybind/pybind11.git GIT_TAG ${PYBIND_VERSION} # or a later release ) FetchContent_MakeAvailable(PyBind11) message(STATUS "Creating binding for module ${project}") file(GLOB_RECURSE pybind_src_files "python_binding/*.cpp") pybind11_add_module(${project} MODULE ${pybind_src_files} "NO_EXTRAS") # NO EXTRA required for pip install target_include_directories(${project} PUBLIC "python_binding" ${pybind11_INCLUDE_DIRECTORIES}) target_link_libraries(${project} PUBLIC ${module_name}) endmacro() # 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)