From a5be1d886e072266cc3bba084189e2cee3f5cf94 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Fri, 3 Apr 2026 21:08:24 +0200 Subject: [PATCH] Copy DLLs to appropriate dir for install-less Windows testing Co-authored-by: vulcandth <6394873+vulcandth@users.noreply.github.com> --- src/CMakeLists.txt | 6 ++++++ test/CMakeLists.txt | 14 ++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 635b3d2e..1e1fae62 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -108,6 +108,12 @@ set_target_properties(rgbasm rgblink rgbfix rgbgfx PROPERTIES # The generator expression (even if a no-op) stops muti-config generators using a of "per-configuration subdirectory". RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}>) target_link_libraries(rgbgfx PRIVATE PNG::PNG) +# Copy the DLLs in the output directory so the program can be run for testing without having to `install`. +# From https://cmake.org/cmake/help/v4.3/manual/cmake-generator-expressions.7.html#genex:TARGET_RUNTIME_DLLS. +add_custom_command(TARGET rgbgfx POST_BUILD COMMENT "Copying rgbgfx's DLLs" + # It would be nice to symlink instead, but that only supports one file at a time. + COMMAND ${CMAKE_COMMAND} -E copy -t $ $ + COMMAND_EXPAND_LISTS VERBATIM) # On Windows, you don't link against DLLs directly, but against an import library for that DLL. # This leads to, sometimes, the DLL being stored in a directory far away from the import library itself! diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3cb70062..fbd3de28 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,8 +9,15 @@ add_executable(rgbgfx_test gfx/rgbgfx_test.cpp) set_target_properties(randtilegen rgbgfx_test PROPERTIES # hack for MSVC: no-op generator expression to stop generation of "per-configuration subdirectory" RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_CURRENT_SOURCE_DIR}/gfx>) -target_link_libraries(randtilegen PRIVATE PNG::PNG) -target_link_libraries(rgbgfx_test PRIVATE PNG::PNG) +foreach(prog "randtilegen" "rgbgfx_test") + target_link_libraries(${prog} PRIVATE PNG::PNG) + # Copy the DLLs in the output directory so the program can be run for testing without having to `install`. + # From https://cmake.org/cmake/help/v4.3/manual/cmake-generator-expressions.7.html#genex:TARGET_RUNTIME_DLLS. + add_custom_command(TARGET ${prog} POST_BUILD COMMENT "Copying ${prog}'s DLLs" + # It would be nice to symlink instead, but that only supports one file at a time. + COMMAND ${CMAKE_COMMAND} -E copy -t $ $ + COMMAND_EXPAND_LISTS VERBATIM) +endforeach() set(ONLY_FREE) if(NOT TESTS_RUN_NONFREE) @@ -31,5 +38,4 @@ configure_file(CTestCustom.cmake.in ${CMAKE_BINARY_DIR}/CTestCustom.cmake @ONLY) add_test(NAME all COMMAND ./run-tests.sh ${ONLY_FREE} ${ONLY_INTERNAL} ${OS_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -) + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})