1
0
mirror of https://git.tukaani.org/xz.git synced 2026-10-31 03:14:56 +00:00

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 <mail@franku.nl>
Fixes: https://github.com/tukaani-project/xz/pull/239
This commit is contained in:
Lasse Collin 2026-08-15 18:55:25 +03:00
parent c8b8ab2ef1
commit 18769dd692
No known key found for this signature in database
GPG Key ID: 38EE757D69184620

View File

@ -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