0

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 was done using CMake 3.25.2 and a simple "Hello World" executable..

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.

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)

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.

2
  • Not sure how setting CPACK_ARCHIVE_COMPONENT_INSTALL variable should treat files created by install(CODE): those files do not correspond to any component, so it is unclear which component-specific archive should contain them. If you want the archive to contain all your files, why do you ever set this variable? Commented Mar 6, 2023 at 15:39
  • This is an illustration of the actual project and the issues it has. The full solution has multiple components. The goal isn't to have one archive with everything, but to have each component archive have all the files necessary for it to run. Which does happen when CPack is ran to generate an installer, but not when it's ran to generate an archive. Commented Mar 7, 2023 at 7:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.