@@ -9,6 +9,12 @@ if(NOT WIN32)
99 set (HUNTER_CONFIGURATION_TYPES "Release" CACHE STRING "Hunter dependencies list of build configurations" )
1010endif ()
1111
12+ # Specify path separator
13+ set (SYS_PATH_SEPARATOR ";" )
14+ if (UNIX )
15+ set (SYS_PATH_SEPARATOR ":" )
16+ endif ()
17+
1218# Generate combined Hunter config
1319file (READ depthai-core/cmake/Hunter/config.cmake depthai_core_hunter_config )
1420file (READ cmake/Hunter/config.cmake hunter_config )
@@ -97,6 +103,23 @@ pybind11_add_module(${TARGET_NAME}
97103 src/log/LogBindings.cpp
98104)
99105
106+ if (WIN32 )
107+ # Copy dlls to target directory - Windows only
108+ # TARGET_RUNTIME_DLLS generator expression available since CMake 3.21
109+ if (CMAKE_VERSION VERSION_LESS "3.21" )
110+ file (GLOB depthai_dll_libraries "${HUNTER_INSTALL_PREFIX} /bin/*.dll" )
111+ else ()
112+ set (depthai_dll_libraries "$<TARGET_RUNTIME_DLLS :${TARGET_NAME} >" )
113+ endif ()
114+ add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND
115+ ${CMAKE_COMMAND} -E copy ${depthai_dll_libraries} $<TARGET_FILE_DIR :${TARGET_NAME} >
116+ COMMAND_EXPAND_LISTS
117+ )
118+
119+ # Disable "d" postfix, so python can import the library as is
120+ set_target_properties (${TARGET_NAME} PROPERTIES DEBUG_POSTFIX "" )
121+ endif ()
122+
100123# Add stubs (pyi) generation step after building bindings
101124execute_process (COMMAND "${PYTHON_EXECUTABLE} " "-c" "from mypy import api" RESULT_VARIABLE error OUTPUT_QUIET ERROR_QUIET )
102125if (error)
@@ -108,7 +131,12 @@ else()
108131 endif ()
109132 message (STATUS "Mypy available, creating and checking stubs. Running with generate_stubs.py ${TARGET_NAME} ${bindings_directory} " )
110133 add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND
111- ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_LIST_DIR} /generate_stubs.py" "${TARGET_NAME} " "${bindings_directory} "
134+ ${CMAKE_COMMAND} -E env
135+ # PATH (dlls)
136+ "PATH=${HUNTER_INSTALL_PREFIX} /bin${SYS_PATH_SEPARATOR} $ENV{PATH} "
137+ # Python path (to find compiled module)
138+ "PYTHONPATH=$<TARGET_FILE_DIR :${TARGET_NAME} >${SYS_PATH_SEPARATOR} $ENV{PYTHONPATH} "
139+ ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_LIST_DIR} /generate_stubs.py" "${TARGET_NAME} " "$<TARGET_FILE_DIR :${TARGET_NAME} >"
112140 DEPENDS "${CMAKE_CURRENT_LIST_DIR} /generate_stubs.py"
113141 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} "
114142 )
0 commit comments