Skip to content

Commit 5db156d

Browse files
ISSOtmvulcandth
andcommitted
Copy DLLs to appropriate dir for install-less Windows testing
Co-authored-by: vulcandth <6394873+vulcandth@users.noreply.github.com>
1 parent ea7fea9 commit 5db156d

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ set_target_properties(rgbasm rgblink rgbfix rgbgfx PROPERTIES
108108
# The generator expression (even if a no-op) stops muti-config generators using a of "per-configuration subdirectory".
109109
RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}>)
110110
target_link_libraries(rgbgfx PRIVATE PNG::PNG)
111+
# Copy the DLLs in the output directory so the program can be run for testing without having to `install`.
112+
# From https://cmake.org/cmake/help/v4.3/manual/cmake-generator-expressions.7.html#genex:TARGET_RUNTIME_DLLS.
113+
add_custom_command(TARGET rgbgfx POST_BUILD COMMENT "Copying rgbgfx's DLLs"
114+
# It would be nice to symlink instead, but that only supports one file at a time.
115+
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:rgbgfx> $<TARGET_RUNTIME_DLLS:rgbgfx>
116+
# FIXME: this would be nice (so DLLs get removed by `make clean`), but CMake complains about the target not existing...
117+
#BYPRODUCTS $<LIST:TRANSFORM,$<PATH:GET_FILENAME,$<TARGET_RUNTIME_DLLS:rgbgfx>>,PREPEND,$<TARGET_FILE_DIR:rgbgfx>/>
118+
COMMAND_EXPAND_LISTS VERBATIM)
111119

112120
# On Windows, you don't link against DLLs directly, but against an import library for that DLL.
113121
# This leads to, sometimes, the DLL being stored in a directory far away from the import library itself!

test/CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ add_executable(rgbgfx_test gfx/rgbgfx_test.cpp)
99
set_target_properties(randtilegen rgbgfx_test PROPERTIES
1010
# hack for MSVC: no-op generator expression to stop generation of "per-configuration subdirectory"
1111
RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_CURRENT_SOURCE_DIR}/gfx>)
12-
target_link_libraries(randtilegen PRIVATE PNG::PNG)
13-
target_link_libraries(rgbgfx_test PRIVATE PNG::PNG)
12+
foreach(prog "randtilegen" "rgbgfx_test")
13+
target_link_libraries(${prog} PRIVATE PNG::PNG)
14+
# Copy the DLLs in the output directory so the program can be run for testing without having to `install`.
15+
# From https://cmake.org/cmake/help/v4.3/manual/cmake-generator-expressions.7.html#genex:TARGET_RUNTIME_DLLS.
16+
add_custom_command(TARGET ${prog} POST_BUILD COMMENT "Copying ${prog}'s DLLs"
17+
# It would be nice to symlink instead, but that only supports one file at a time.
18+
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:${prog}> $<TARGET_RUNTIME_DLLS:${prog}>
19+
COMMAND_EXPAND_LISTS VERBATIM)
20+
endforeach()
1421

1522
set(ONLY_FREE)
1623
if(NOT TESTS_RUN_NONFREE)
@@ -31,5 +38,4 @@ configure_file(CTestCustom.cmake.in ${CMAKE_BINARY_DIR}/CTestCustom.cmake @ONLY)
3138

3239
add_test(NAME all
3340
COMMAND ./run-tests.sh ${ONLY_FREE} ${ONLY_INTERNAL} ${OS_NAME}
34-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
35-
)
41+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

0 commit comments

Comments
 (0)