Tests/Windows: Add the application manifest to the test programs

This ensures that the test programs get executed the same way as
the binaries that are installed.
This commit is contained in:
Lasse Collin 2024-10-01 12:10:23 +03:00
parent 7ddf2273e0
commit 74702ee00e
4 changed files with 70 additions and 5 deletions

View File

@ -221,6 +221,12 @@ if(MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
endif()
# Dependencies for all Windows resource files:
set(W32RES_DEPENDENCIES
"${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
"${CMAKE_CURRENT_SOURCE_DIR}/src/common/w32_application.manifest"
)
# Definitions common to all targets:
add_compile_definitions(
# Package info:
@ -1394,7 +1400,7 @@ if(WIN32 OR CYGWIN)
target_sources(liblzma PRIVATE src/liblzma/liblzma_w32res.rc)
set_source_files_properties(src/liblzma/liblzma_w32res.rc PROPERTIES
OBJECT_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
OBJECT_DEPENDS "${W32RES_DEPENDENCIES}"
)
# Export the public API symbols with __declspec(dllexport).
@ -1875,7 +1881,7 @@ if(HAVE_DECODERS)
target_sources("${XZDEC}" PRIVATE "src/xzdec/${XZDEC}_w32res.rc")
set_source_files_properties(
"src/xzdec/${XZDEC}_w32res.rc" PROPERTIES
OBJECT_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
OBJECT_DEPENDS "${W32RES_DEPENDENCIES}"
)
endif()
@ -1943,7 +1949,7 @@ if(XZ_TOOL_LZMAINFO AND HAVE_DECODERS)
# Add the Windows resource file for lzmainfo.exe.
target_sources(lzmainfo PRIVATE src/lzmainfo/lzmainfo_w32res.rc)
set_source_files_properties(src/lzmainfo/lzmainfo_w32res.rc PROPERTIES
OBJECT_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
OBJECT_DEPENDS "${W32RES_DEPENDENCIES}"
)
endif()
@ -2056,7 +2062,7 @@ this many MiB of RAM if xz cannot determine the amount at runtime")
# Add the Windows resource file for xz.exe.
target_sources(xz PRIVATE src/xz/xz_w32res.rc)
set_source_files_properties(src/xz/xz_w32res.rc PROPERTIES
OBJECT_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
OBJECT_DEPENDS "${W32RES_DEPENDENCIES}"
)
endif()

View File

@ -7,6 +7,7 @@ EXTRA_DIST = \
tests.cmake \
tuktest.h \
tests.h \
tests_w32res.rc \
test_files.sh \
test_compress.sh \
test_compress_generated_abc \
@ -25,6 +26,15 @@ LDADD = $(top_builddir)/src/liblzma/liblzma.la
LDADD += $(LTLIBINTL)
# Windows resource compiler support
.rc.o:
$(RC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(RCFLAGS) -i $< -o $@
if COND_W32
LDADD += tests_w32res.o
endif
check_PROGRAMS = \
create_compress_files \
test_check \

View File

@ -16,6 +16,36 @@
include(CTest)
if(BUILD_TESTING)
################################
# Windows Application Manifest #
################################
# On Windows (but not on Cygwin or MSYS2) we want to add the
# application manifest to the test programs so that they are
# run in the same configuration as the programs that are installed.
# The same object file can be used for all test programs.
add_library(tests_w32res OBJECT)
# CMake requires that even an object library must have at least once
# source file. Give it a header file that results in no output files.
target_sources(tests_w32res PRIVATE tests/tests.h)
# The Ninja Generator requires setting the linker language since it
# cannot guess the programming language of a header file.
set_target_properties(tests_w32res PROPERTIES LINKER_LANGUAGE C)
target_include_directories(tests_w32res PRIVATE src/common
src/common
src/liblzma/api
)
if(WIN32)
target_sources(tests_w32res PRIVATE tests/tests_w32res.rc)
set_source_files_properties(tests/tests_w32res.rc PROPERTIES
OBJECT_DEPENDS "${W32RES_DEPENDENCIES}"
)
endif()
#################
# liblzma tests #
#################
@ -54,7 +84,7 @@ if(BUILD_TESTING)
src/liblzma
)
target_link_libraries("${TEST}" PRIVATE liblzma)
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.
@ -155,6 +185,7 @@ if(BUILD_TESTING)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test_compress")
add_executable(create_compress_files tests/create_compress_files.c)
target_link_libraries(create_compress_files PRIVATE tests_w32res)
target_include_directories(create_compress_files PRIVATE src/common)
set_target_properties(create_compress_files PROPERTIES
RUNTIME_OUTPUT_DIRECTORY test_compress)

18
tests/tests_w32res.rc Normal file
View File

@ -0,0 +1,18 @@
/* SPDX-License-Identifier: 0BSD */
/*
* Author: Lasse Collin
*/
/*
* It's silly to add version info to test programs but GNU windres fails
* if there are no resources to build, which happens with Autotools on
* Cygwin and MSYS2 because otherwise one more Automake conditional would
* be needed.
*/
#define MY_TYPE VFT_APP
#define MY_NAME "test"
#define MY_SUFFIX ".exe"
#define MY_DESC "Test program"
#include "common_w32res.rc"