diff --git a/lldb/bindings/python/CMakeLists.txt b/lldb/bindings/python/CMakeLists.txt index e48fcb35aba3b..42299064fd8f7 100644 --- a/lldb/bindings/python/CMakeLists.txt +++ b/lldb/bindings/python/CMakeLists.txt @@ -198,6 +198,24 @@ function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_tar COMMENT "Copying Python DLL to LLDB binaries directory.") endif() + # Since Python3.8 the Windows runtime loads dependent DLLs only from the directory of the binary + # itself (and not Path). Windows has no RPATHs, so we must copy all DLLs that we depend on into + # the Python package. + if (WIN32) + # TARGET_RUNTIME_DLLS is supported in CMake 3.21+ + if ("${CMAKE_VERSION}" VERSION_LESS "3.21.0") + if (LLDB_INCLUDE_TESTS) + message(SEND_ERROR + "Your CMake version is ${CMAKE_VERSION}. In order to run LLDB tests " + "on Windows please upgrade to 3.21.0 at least (or disable tests with " + "LLDB_INCLUDE_TESTS=Off)") + endif() + else() + add_custom_command(TARGET ${swig_target} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy -t ${lldb_python_target_dir} $ + COMMAND_EXPAND_LISTS) + endif() + endif() endfunction()