file(GET_RUNTIME_DEPENDENCIES) can not resolve soft links on Windows
We have attempted to resolve dependencies by creating soft links instead of copying them next to the executables. In the process we have experienced that the solution worked fine in the build directory but during install, we received the following error:
CMake Error at build/cmake_install.cmake:123 (file):
file INSTALL cannot find
"\??\C:\temp\playground\thirdparties\bin\some_function.dll": No error
You'll find an example project in the attachments playground.zip and the main CmakeLists.txt is provided below:
cmake_minimum_required(VERSION 3.25)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
project(DUMMY_PROJECT VERSION 1.0.0 DESCRIPTION "Demonstrate symlinks on Windows" LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
add_subdirectory("modules")
add_executable(DummyMain main.cpp)
target_link_libraries(DummyMain PUBLIC dummy_lib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/thirdparties/lib/some_function.lib")
target_include_directories(DummyMain PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/thirdparties/include")
# In this section only soft-links are created for dlls instead of copying them
# aside the executables
add_custom_command(TARGET DummyMain POST_BUILD
COMMAND ${CMAKE_COMMAND} -D OBJECT_DEPENDENCY_LIST="$<TARGET_RUNTIME_DLLS:DummyMain>" -D TARGET_DIR_FOR_DEP=$<TARGET_FILE_DIR:DummyMain> -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/soft_linker.cmake"
COMMENT "Running soft linker script for project dependencies"
COMMAND_EXPAND_LISTS
)
add_custom_command(TARGET DummyMain POST_BUILD
COMMAND ${CMAKE_COMMAND} -D OBJECT_DEPENDENCY_LIST="${CMAKE_CURRENT_SOURCE_DIR}/thirdparties/bin/some_function.dll" -D TARGET_DIR_FOR_DEP=$<TARGET_FILE_DIR:DummyMain> -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/soft_linker.cmake"
COMMENT "Running soft linker script for precompiled dependencies"
COMMAND_EXPAND_LISTS
)
# This is the command that results in the following error:
# CMake Error at build/cmake_install.cmake:123 (file):
# file INSTALL cannot find
# "\??\C:\temp\playground\thirdparties\bin\some_function.dll": No error.
install(TARGETS DummyMain
RUNTIME_DEPENDENCIES
PRE_EXCLUDE_REGEXES "^api-ms-win.*" "^ext-ms.*
POST_EXCLUDE_REGEXES "^/lib.*" "[Ss][Yy][Ss][Tt][Ee][Mm]32.*"
RUNTIME DESTINATION "bin")