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.

(cherry picked from commit 74702ee00e)
This commit is contained in:
Lasse Collin 2024-10-01 12:10:23 +03:00
parent bf518b9ba4
commit 51f6f45587
No known key found for this signature in database
GPG Key ID: 38EE757D69184620
4 changed files with 70 additions and 5 deletions

View File

@ -235,6 +235,12 @@ if(MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
endif() 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: # Definitions common to all targets:
add_compile_definitions( add_compile_definitions(
# Package info: # Package info:
@ -1284,7 +1290,7 @@ if(WIN32 OR CYGWIN)
target_sources(liblzma PRIVATE src/liblzma/liblzma_w32res.rc) target_sources(liblzma PRIVATE src/liblzma/liblzma_w32res.rc)
set_source_files_properties(src/liblzma/liblzma_w32res.rc PROPERTIES 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). # Export the public API symbols with __declspec(dllexport).
@ -1653,7 +1659,7 @@ if(HAVE_DECODERS AND (NOT MSVC OR MSVC_VERSION GREATER_EQUAL 1900))
target_sources("${XZDEC}" PRIVATE "src/xzdec/${XZDEC}_w32res.rc") target_sources("${XZDEC}" PRIVATE "src/xzdec/${XZDEC}_w32res.rc")
set_source_files_properties( set_source_files_properties(
"src/xzdec/${XZDEC}_w32res.rc" PROPERTIES "src/xzdec/${XZDEC}_w32res.rc" PROPERTIES
OBJECT_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc" OBJECT_DEPENDS "${W32RES_DEPENDENCIES}"
) )
endif() endif()
@ -1709,7 +1715,7 @@ if(HAVE_DECODERS AND (NOT MSVC OR MSVC_VERSION GREATER_EQUAL 1900))
# Add the Windows resource file for lzmainfo.exe. # Add the Windows resource file for lzmainfo.exe.
target_sources(lzmainfo PRIVATE src/lzmainfo/lzmainfo_w32res.rc) target_sources(lzmainfo PRIVATE src/lzmainfo/lzmainfo_w32res.rc)
set_source_files_properties(src/lzmainfo/lzmainfo_w32res.rc PROPERTIES 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() endif()
@ -1818,7 +1824,7 @@ if(NOT MSVC OR MSVC_VERSION GREATER_EQUAL 1900)
# Add the Windows resource file for xz.exe. # Add the Windows resource file for xz.exe.
target_sources(xz PRIVATE src/xz/xz_w32res.rc) target_sources(xz PRIVATE src/xz/xz_w32res.rc)
set_source_files_properties(src/xz/xz_w32res.rc PROPERTIES 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() endif()

View File

@ -7,6 +7,7 @@ EXTRA_DIST = \
tests.cmake \ tests.cmake \
tuktest.h \ tuktest.h \
tests.h \ tests.h \
tests_w32res.rc \
test_files.sh \ test_files.sh \
test_compress.sh \ test_compress.sh \
test_compress_generated_abc \ test_compress_generated_abc \
@ -25,6 +26,15 @@ LDADD = $(top_builddir)/src/liblzma/liblzma.la
LDADD += $(LTLIBINTL) 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 = \ check_PROGRAMS = \
create_compress_files \ create_compress_files \
test_check \ test_check \

View File

@ -16,6 +16,36 @@
include(CTest) include(CTest)
if(BUILD_TESTING) 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 # # liblzma tests #
################# #################
@ -54,7 +84,7 @@ if(BUILD_TESTING)
src/liblzma 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 # Put the test programs into their own subdirectory so they don't
# pollute the top-level dir which might contain xz and xzdec. # pollute the top-level dir which might contain xz and xzdec.
@ -156,6 +186,7 @@ if(BUILD_TESTING)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test_compress") file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test_compress")
add_executable(create_compress_files tests/create_compress_files.c) 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) target_include_directories(create_compress_files PRIVATE src/common)
set_target_properties(create_compress_files PROPERTIES set_target_properties(create_compress_files PROPERTIES
RUNTIME_OUTPUT_DIRECTORY test_compress) 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"