File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -83,6 +83,40 @@ if(PAHO_BUILD_SHARED)
8383 endif ()
8484endif ()
8585
86+ # On Windows with shared libraries, copy DLLs next to the test binary so that
87+ # it can run (both for catch_discover_tests and when running ctest directly).
88+ if (WIN32 AND PAHO_BUILD_SHARED)
89+ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.21" )
90+ add_custom_command (TARGET unit_tests POST_BUILD
91+ COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR :unit_tests >
92+ $<TARGET_RUNTIME_DLLS :unit_tests >
93+ COMMAND_EXPAND_LISTS
94+ )
95+ else ()
96+ # Fallback for CMake < 3.21: copy known DLL targets manually.
97+ set (_paho_dlls $<TARGET_FILE :paho -mqttpp3 -shared >)
98+ if (PAHO_WITH_MQTT_C)
99+ if (PAHO_WITH_SSL)
100+ list (APPEND _paho_dlls $<TARGET_FILE :paho -mqtt3as >)
101+ else ()
102+ list (APPEND _paho_dlls $<TARGET_FILE :paho -mqtt3a >)
103+ endif ()
104+ else ()
105+ message (WARNING
106+ "CMake 3.21+ is recommended to automatically copy all runtime "
107+ "DLL dependencies for unit tests. With CMake ${CMAKE_VERSION} , "
108+ "only the paho-mqttpp3 DLL will be copied automatically. "
109+ "Ensure the paho MQTT C DLLs are in PATH for tests to run."
110+ )
111+ endif ()
112+ add_custom_command (TARGET unit_tests POST_BUILD
113+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
114+ ${_paho_dlls}
115+ $<TARGET_FILE_DIR :unit_tests >
116+ )
117+ endif ()
118+ endif ()
119+
86120include (CTest )
87121include (Catch )
88122
You can’t perform that action at this time.
0 commit comments