]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Tests/Windows: Add the application manifest to the test programs
authorLasse Collin <lasse.collin@tukaani.org>
Tue, 1 Oct 2024 09:10:23 +0000 (12:10 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Tue, 1 Oct 2024 09:16:29 +0000 (12:16 +0300)
This ensures that the test programs get executed the same way as
the binaries that are installed.

(cherry picked from commit 74702ee00ecfd080d8ab11118cd25dbe6c437ec0)

CMakeLists.txt
tests/Makefile.am
tests/tests.cmake
tests/tests_w32res.rc [new file with mode: 0644]

index bff6015e53f8a318088507fba7ec5bcf58d601a9..ea1674b008b6fdcb32fe5cae6bb8acbedc9c8153 100644 (file)
@@ -235,6 +235,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:
@@ -1284,7 +1290,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).
@@ -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")
             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()
 
@@ -1709,7 +1715,7 @@ if(HAVE_DECODERS AND (NOT MSVC OR MSVC_VERSION GREATER_EQUAL 1900))
         # 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()
 
@@ -1818,7 +1824,7 @@ if(NOT MSVC OR MSVC_VERSION GREATER_EQUAL 1900)
         # 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()
 
index d85328dddaaef4474d680bb3f0f9d79a085cec3f..15dc16a8ea68c26bd89b2355d976f61902a63122 100644 (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 \
index 62c546ced3e65c7ca62465ad9278a29833845b68..9174251dab9df5ca1a00523dedd2cfce74236ca6 100644 (file)
 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.
@@ -156,6 +186,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)
diff --git a/tests/tests_w32res.rc b/tests/tests_w32res.rc
new file mode 100644 (file)
index 0000000..0b6c525
--- /dev/null
@@ -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"