Skip to content

Commit

Permalink
Make stub generation optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ManifoldFR committed Aug 8, 2024
1 parent eacf0ea commit d4b4f6e
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
include(${JRL_CMAKE_MODULES}/python.cmake)
include(${JRL_CMAKE_MODULES}/python-helpers.cmake)

option(GENERATE_PYTHON_STUBS "Generate Python stubs" OFF)

findpython(REQUIRED Development.Module)
set(Python_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS})

Expand Down Expand Up @@ -46,22 +48,24 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
set_target_properties(instructionset PROPERTIES INSTALL_RPATH
"\$ORIGIN/../../..")
endif()
nanobind_add_stub(
instructionset_stub
MODULE
instructionset
OUTPUT
instructionset.pyi
PYTHON_PATH
$<TARGET_FILE_DIR:instructionset>
DEPENDS
instructionset)
install(
TARGETS instructionset
EXPORT ${TARGETS_EXPORT_NAME}
DESTINATION ${${PYWRAP}_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/instructionset.pyi
DESTINATION ${${PYWRAP}_INSTALL_DIR})
if(GENERATE_PYTHON_STUBS)
nanobind_add_stub(
instructionset_stub
MODULE
instructionset
OUTPUT
instructionset.pyi
PYTHON_PATH
$<TARGET_FILE_DIR:instructionset>
DEPENDS
instructionset)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/instructionset.pyi
DESTINATION ${${PYWRAP}_INSTALL_DIR})
endif()
endif()

function(list_filter list regular_expression dest_list)
Expand Down Expand Up @@ -127,20 +131,21 @@ function(CREATE_PYTHON_TARGET target_name COMPILE_OPTIONS dependencies)
"\$ORIGIN/../../..")
endif()

nanobind_add_stub(
${target_name}_stub
MODULE
${target_name}
OUTPUT
${target_name}.pyi
PYTHON_PATH
$<TARGET_FILE_DIR:${target_name}>
DEPENDS
${target_name})

install(TARGETS ${target_name} DESTINATION ${${PYWRAP}_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${target_name}.pyi
DESTINATION ${${PYWRAP}_INSTALL_DIR})
if(GENERATE_PYTHON_STUBS)
nanobind_add_stub(
${target_name}_stub
MODULE
${target_name}
OUTPUT
${target_name}.pyi
PYTHON_PATH
$<TARGET_FILE_DIR:${target_name}>
DEPENDS
${target_name})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${target_name}.pyi
DESTINATION ${${PYWRAP}_INSTALL_DIR})
endif()
endfunction()

if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
Expand Down

0 comments on commit d4b4f6e

Please sign in to comment.