diff --git a/CMakeLists.txt b/CMakeLists.txt
index a34fd2a9cd..a31ea9237e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -373,6 +373,11 @@ if (MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL Clang)
# clang-cl can interpret SYSTEM header paths if -imsvc is used
set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-imsvc")
+
+ # Thin archives reference the objects instead of copying them; only lld-link reads them.
+ if (NOT CMAKE_GENERATOR MATCHES "Visual Studio" AND CMAKE_AR MATCHES "llvm-lib" AND CMAKE_LINKER MATCHES "lld-link")
+ string(APPEND CMAKE_STATIC_LINKER_FLAGS " /llvmlibthin")
+ endif ()
else ()
set(IS_CLANG_CL FALSE)
endif ()
diff --git a/cmake/modules/StagePythonRuntime.cmake b/cmake/modules/StagePythonRuntime.cmake
new file mode 100644
index 0000000000..b48ef9a600
--- /dev/null
+++ b/cmake/modules/StagePythonRuntime.cmake
@@ -0,0 +1,32 @@
+# cmake -DSOURCE=
-DDESTINATION= -DSTAMP= -P StagePythonRuntime.cmake
+# Copies only when SOURCE's files or their times changed since the copy STAMP records.
+foreach (_var SOURCE DESTINATION STAMP)
+ if (NOT DEFINED ${_var})
+ message(FATAL_ERROR "StagePythonRuntime.cmake: ${_var} is not set")
+ endif ()
+endforeach ()
+
+file(GLOB_RECURSE _files LIST_DIRECTORIES false RELATIVE "${SOURCE}" "${SOURCE}/*")
+list(SORT _files)
+set(_signature "${SOURCE}\n")
+foreach (_file IN LISTS _files)
+ file(TIMESTAMP "${SOURCE}/${_file}" _time "%Y%m%d%H%M%S" UTC)
+ string(APPEND _signature "${_file} ${_time}\n")
+endforeach ()
+string(SHA256 _signature "${_signature}")
+
+if (IS_DIRECTORY "${DESTINATION}" AND EXISTS "${STAMP}")
+ file(READ "${STAMP}" _copied)
+ if (_copied STREQUAL _signature)
+ return()
+ endif ()
+endif ()
+
+file(REMOVE "${STAMP}")
+file(REMOVE_RECURSE "${DESTINATION}")
+execute_process(COMMAND "${CMAKE_COMMAND}" -E copy_directory "${SOURCE}" "${DESTINATION}"
+ RESULT_VARIABLE _result)
+if (NOT _result EQUAL 0)
+ message(FATAL_ERROR "Copying ${SOURCE} to ${DESTINATION} failed")
+endif ()
+file(WRITE "${STAMP}" "${_signature}")
diff --git a/scripts/run_unit_tests.sh b/scripts/run_unit_tests.sh
index 5d2bd2b31d..1ad6c13c50 100755
--- a/scripts/run_unit_tests.sh
+++ b/scripts/run_unit_tests.sh
@@ -24,7 +24,7 @@ BUILD_CONFIG="${2:-}"
# Install it with the uv staged beside that runtime -- the tool the app installs plugin
# dependencies with -- straight into the interpreter's own site-packages: no pip needed
# in the runtime, no PYTHONPATH. Re-checked every run because a rebuild of the test
-# target re-copies the runtime; needs network whenever it installs. Pinned so a numpy
+# target can re-copy the runtime; needs network whenever it installs. Pinned so a numpy
# release cannot change results on its own.
NUMPY_VERSION="2.5.3"
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c8d882f291..b5d866304e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -282,9 +282,11 @@ if (WIN32)
endif ()
# copy libpython to the bin folder for Windows
add_custom_command(TARGET OrcaSlicer POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E rm -rf "$/python"
- COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_PREFIX_PATH}/libpython" "$/python"
- COMMENT "Copying Python runtime into the build tree"
+ COMMAND ${CMAKE_COMMAND} "-DSOURCE=${CMAKE_PREFIX_PATH}/libpython"
+ "-DDESTINATION=$/python"
+ "-DSTAMP=${CMAKE_CURRENT_BINARY_DIR}/python_runtime_$.stamp"
+ -P "${CMAKE_SOURCE_DIR}/cmake/modules/StagePythonRuntime.cmake"
+ COMMENT "Updating the Python runtime in the build tree"
VERBATIM)
if (CMAKE_CONFIGURATION_TYPES)
diff --git a/tests/slic3rutils/CMakeLists.txt b/tests/slic3rutils/CMakeLists.txt
index 5765cc8207..18eec0f42d 100644
--- a/tests/slic3rutils/CMakeLists.txt
+++ b/tests/slic3rutils/CMakeLists.txt
@@ -90,8 +90,10 @@ orcaslicer_copy_test_dlls(${_TEST_NAME}_tests)
if (WIN32)
add_custom_command(TARGET ${_TEST_NAME}_tests POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E make_directory "$/python"
- COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_PREFIX_PATH}/libpython" "$/python"
+ COMMAND ${CMAKE_COMMAND} "-DSOURCE=${CMAKE_PREFIX_PATH}/libpython"
+ "-DDESTINATION=$/python"
+ "-DSTAMP=${CMAKE_CURRENT_BINARY_DIR}/python_runtime_$.stamp"
+ -P "${CMAKE_SOURCE_DIR}/cmake/modules/StagePythonRuntime.cmake"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_PREFIX_PATH}/libpython/python${_bundled_python_abi}.dll"
"${CMAKE_PREFIX_PATH}/libpython/vcruntime140.dll"