I have a CMake (3.14) C++ (11) application that I build both on (native) Windows and Linux. It has many external dependencies. On both systems, it compiles without any problems.
On Windows, if I just launch the unit tests after a clean build, I get a "The code execution cannot proceed because *.dll was not found" for all my dependencies. To solve the problem, I copy them all by hand to the build folder. I find that I have to copy them by hand because the generator expression TARGET_RUNTIME_DLLS does not find all dependencies post-build (for example, it doesn't find Boost):
if (${WIN32})
add_custom_command( TARGET mytests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_RUNTIME_DLLS:mytests>
$<TARGET_FILE_DIR:mytests>
COMMAND_EXPAND_LISTS)
endif()
Is there a better approach to be able to run Windows executables created with CMake? Am I missing something?
Is there a way to propagate the dll paths used during compile time to the exe so that it can find them during runtime (without adding individual library dependency dll folders to environment path)?
I tried playing around with VS_DEBUGGER:
set_target_properties(myapp PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "$<TARGET_FILE_DIR:myapp>"
VS_DEBUGGER_COMMAND "$<TARGET_FILE:myapp>"
VS_DEBUGGER_ENVIRONMENT "PATH=%PATH%;${CMAKE_BINARY_DIR}/$<CONFIG>")
but that made no difference. I still had to copy all the dependency dlls to the build folder.
Is there any way to not have to copy dlls to the build folder?