Installer Has Qt Deploy Fixes But Archive Does Not

I have a Qt application that runs the deploy command during installation and packaging. This works
correctly when generating a Wix installer. However, when trying to create an archive, e.g. 7z,
command is ran but the files placed there do not appear in the archive. Those files do correctly
appear in the installer.

Below is a small illustration of the CMake file exhibiting this behaviour this is using
CMake 3.25.2.

The install directory in all cases contains the executable and the file deployed-files.true.
The directory when using the Wix installer contains the executable and the file
deployed-files.true.

The archive file only contains the executable, but does not contain the file deployed-files.true.
Looking at the directory inside _CPack_Packages it contains the executable and the file deployed-files.true.

What I would expect is that the archive file match the contents found in the _CPack_Packages
directory. So that one could just extract the generated archive and have all files.

cmake_minimum_required(VERSION 3.25)
 
project(CMakePackageIssue VERSION 1.0.0 LANGUAGES CXX)
 
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
macro (installAnyQtDependencies componentName destinationDirectory)
    file(GENERATE
        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/qt-library-deploy.bat
        CONTENT "@echo off
echo \"Qt Deploy called\" > \"%1\"\\deployed-files.true
exit /b %errorlevel
"
    )
    install(
        CODE "
message(DEBUG \"Running the package command.\")
execute_process(
    COMMAND \"${CMAKE_CURRENT_BINARY_DIR}/qt-library-deploy.bat\" \"${CMAKE_INSTALL_PREFIX}/${destinationDirectory}\"
    COMMAND_ERROR_IS_FATAL ANY
)
"
        COMPONENT ${componentName}
    )
endmacro()
 
add_executable(CMakePackageIssue main.cpp)
 
install(TARGETS CMakePackageIssue)
 
installAnyQtDependencies(${PROJECT_NAME} ".")
 
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_VERBATIM_VARIABLES TRUE)
 
option(
    PACKAGE_ONLY
    "A flag to enable only archive packaging."
    OFF
)
 
if (PACKAGE_ONLY)
    set(CPACK_GENERATOR "7Z")
else ()
    set(CPACK_GENERATOR "WIX")
endif ()
 
 
file(GENERATE
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/package.cmake
    CONTENT "
execute_process(
    COMMAND \"${CMAKE_CURRENT_BINARY_DIR}/qt-library-deploy.bat\" \"${CMAKE_BINARY_DIR}/_CPack_Packages/win64/${CPACK_GENERATOR}/${PROJECT_NAME}-${${PROJECT_NAME}_VERSION}-win64/Unspecified\"
    COMMAND_ERROR_IS_FATAL ANY
)
"
    )
 
list(APPEND CPACK_PRE_BUILD_SCRIPTS "${CMAKE_BINARY_DIR}/package.cmake")
include(CPack)

I have tried using other archive generators, e.g. zip, but it results in the same behaviour.

While I’m not privy to the inner-workings of CPack to know what is happening here, and agree with you that it seems like that test file should be included in the package, I can at least note that the convenience method for handling Qt dependencies introduced in Qt 6.3 does result in the installed files ending up in the CPack package when using the ZIP generator:

qt_generate_deploy_app_script(
    TARGET "${_TARGET_NAME}"
    FILENAME_VARIABLE qt_runtime_deploy_script
    NO_UNSUPPORTED_PLATFORM_ERROR
)

install(SCRIPT ${qt_runtime_deploy_script}
    COMPONENT ${_TARGET_NAME}
)