From 18769dd6927f16562008aee01ab1466c3035110e Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Sat, 15 Aug 2026 18:55:25 +0300 Subject: [PATCH] CMake: Don't put test binaries in a subdirectory This can matter on Windows: - MSVC puts the binaries into subdirectories based on build type (like "Debug" or "Release"), and then the test executables won't find liblzma.dll because it's not in the working directory from which the tests are run. - With mingw-w64, liblzma.dll was in the working directory so the test executables worked. However, the if the system happened to have liblzma.dll in, for example, the Windows directory, then the DLL search order might pick that instead. Putting the shared library and test executables in the same directory avoids these problems. Reported-by: Frank Fixes: https://github.com/tukaani-project/xz/pull/239 --- tests/tests.cmake | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/tests.cmake b/tests/tests.cmake index eff63d86..e60d1a2d 100644 --- a/tests/tests.cmake +++ b/tests/tests.cmake @@ -87,14 +87,12 @@ if(BUILD_TESTING) target_link_libraries("${TEST}" PRIVATE liblzma tests_w32res) - # Put the test programs into their own subdirectory so they don't - # pollute the top-level dir which might contain xz and xzdec. - set_target_properties("${TEST}" PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tests_bin" - ) - + # We used to put the test executables into their own subdirectory, + # but it can create problems on Windows when BUILD_SHARED_LIBS=ON. + # The executables and liblzma.dll should be in the same directory to + # ensure that the correct liblzma.dll file is always found and used. add_test(NAME "${TEST}" - COMMAND "${CMAKE_CURRENT_BINARY_DIR}/tests_bin/${TEST}" + COMMAND "${CMAKE_CURRENT_BINARY_DIR}/${TEST}" ) # Set srcdir environment variable so that the tests find their