diff --git a/ngsolve_addon.cmake b/ngsolve_addon.cmake index 1db6b35..fb64641 100644 --- a/ngsolve_addon.cmake +++ b/ngsolve_addon.cmake @@ -95,9 +95,25 @@ endif() macro(ngsolve_generate_stub_files module_name) set(stubgen_generation_code "execute_process(WORKING_DIRECTORY ${stubgen_working_dir} COMMAND ${Python3_EXECUTABLE} -m pybind11_stubgen --ignore-all-errors -o ${CMAKE_CURRENT_BINARY_DIR}/stubs ${module_name})") set(stubgen_directory "${CMAKE_CURRENT_BINARY_DIR}/stubs/${module_name}/") + set(stubgen_file "${CMAKE_CURRENT_BINARY_DIR}/stubs/${module_name}.pyi") + set(stubgen_install_destination ${ADDON_INSTALL_DIR_PYTHON}/${module_name}/) install(CODE ${stubgen_generation_code}) - install(DIRECTORY ${stubgen_directory} DESTINATION ${ADDON_INSTALL_DIR_PYTHON}/${module_name}) + + if(NOT IS_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${stubgen_install_destination}) + message( + FATAL_ERROR + "stub files cannot be installed to ${CMAKE_INSTALL_PREFIX}/${stubgen_install_destination}, the folder does not exist." + ) + endif() + + if(EXISTS ${stubgen_file}) + install(FILES ${stubgen_file} DESTINATION ${stubgen_install_destination}) + elseif(IS_DIRECTORY ${stubgen_directory}) + install(DIRECTORY ${stubgen_directory} DESTINATION ${stubgen_install_destination}) + else() + message(FATAL_ERROR "Unable to locate and install stub files.") + endif() endmacro() message(STATUS "Install dir: ${CMAKE_INSTALL_PREFIX}")