diff --git a/CMakeLists.txt b/CMakeLists.txt index f5c253123c..2116a42d81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -332,7 +332,8 @@ if(AUTO_PLUGIN_DEPLOYMENT OR AIO_ZIP_TO_DIST) # deploys from copying everything every build. set(_prepare_aio_cmds) - # Ensure SKSE/Plugins dir exists and copy built plugin files + # Ensure SKSE/Plugins dir exists + # Note: DLL and PDB are copied via POST_BUILD command to avoid race conditions list( APPEND _prepare_aio_cmds @@ -342,26 +343,6 @@ if(AUTO_PLUGIN_DEPLOYMENT OR AIO_ZIP_TO_DIST) make_directory "${AIO_DIR}/SKSE/Plugins" ) - list( - APPEND - _prepare_aio_cmds - COMMAND - ${CMAKE_COMMAND} - -E - copy_if_different - $ - "${AIO_DIR}/SKSE/Plugins/$" - ) - list( - APPEND - _prepare_aio_cmds - COMMAND - ${CMAKE_COMMAND} - -E - copy_if_different - $ - "${AIO_DIR}/SKSE/Plugins/$" - ) # Copy package files file( @@ -454,6 +435,24 @@ if(AUTO_PLUGIN_DEPLOYMENT OR AIO_ZIP_TO_DIST) DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/prepare_aio.stamp ) + # Copy DLL and PDB using POST_BUILD to avoid race conditions with file locking + # This ensures the linker has fully released the files before we attempt to copy them + add_custom_command( + TARGET ${PROJECT_NAME} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory "${AIO_DIR}/SKSE/Plugins" + COMMAND + ${CMAKE_COMMAND} -E copy_if_different + "$" + "${AIO_DIR}/SKSE/Plugins/$" + COMMAND + ${CMAKE_COMMAND} -E copy_if_different + "$" + "${AIO_DIR}/SKSE/Plugins/$" + COMMENT "Copying built DLL and PDB to AIO package" + VERBATIM + ) + # Only copy shaders when HLSL files change; copy individually so unchanged # files do not get their timestamps updated. file(