It was just too hard trying to make it work with separate libs. The main issue was getting the python md and execution modules to recognize PySecurityList and other types defined in the core module.
72 lines
2.0 KiB
CMake
72 lines
2.0 KiB
CMake
include_guard(DIRECTORY)
|
|
include(GNUInstallDirs)
|
|
include(${CMAKE_SOURCE_DIR}/cmake/ExportToParent.cmake)
|
|
include(${CMAKE_SOURCE_DIR}/cmake/SetFirstDefined.cmake)
|
|
|
|
function(init_python_module)
|
|
set(_options)
|
|
set(_one_value_args
|
|
NAME
|
|
)
|
|
set(_multi_value_args
|
|
SOURCES
|
|
)
|
|
cmake_parse_arguments(_ARGS "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN})
|
|
set_first_defined(_name _ARGS_NAME PROJECT_NAME)
|
|
set_first_defined(_sources _ARGS_SOURCES ${_name}_SOURCES)
|
|
|
|
set(module_proj ${_name}_module)
|
|
set(${module_proj}_SOURCES ${_sources})
|
|
pybind11_add_module(${module_proj} SHARED ${_sources})
|
|
target_link_libraries(
|
|
${module_proj}
|
|
PUBLIC
|
|
pybind11::embed
|
|
spark
|
|
${_name}
|
|
)
|
|
target_include_directories(
|
|
${module_proj}
|
|
PRIVATE
|
|
$<BUILD_INTERFACE:${pybind11_INCLUDE_DIRS}>
|
|
)
|
|
target_include_directories(
|
|
${module_proj}
|
|
PUBLIC
|
|
${Python3_INCLUDE_DIRS}
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
|
)
|
|
add_custom_command(
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/stubs/${_name}.pyi
|
|
DEPENDS ${_name} ${module_proj}
|
|
COMMAND PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR} pybind11-stubgen --numpy-array-use-type-var --ignore-invalid-expressions '.*' ${_name}_module
|
|
COMMENT "Generating py stubs"
|
|
)
|
|
add_custom_target(
|
|
"${_name}_py_stubs"
|
|
ALL
|
|
DEPENDS
|
|
${CMAKE_CURRENT_BINARY_DIR}/stubs/${_name}.pyi
|
|
)
|
|
install(
|
|
TARGETS ${module_proj}
|
|
EXPORT ${module_proj}Targets
|
|
RUNTIME
|
|
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
LIBRARY
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
ARCHIVE
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
)
|
|
foreach(dir ${pybind11_INCLUDE_DIRS})
|
|
install(DIRECTORY ${dir} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
endforeach()
|
|
install(
|
|
EXPORT ${module_proj}Targets
|
|
FILE ${module_proj}Targets.cmake
|
|
NAMESPACE ${_name}::
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${_name}
|
|
)
|
|
endfunction()
|