Search code examples
cmakeinstallationpackagingcpack

Why CPack generates an empty package?


There are exists one cmake project that creates one console application. I add the ability of package generation to that cmake project:

# ... above cmake code for one console application creation
# below code that I add:

#install
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "C:/Apps/Consolas" COMPONENT applications)

# pack
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VENDOR "MyOrg")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "CPack Component Installation Example")
set(CPACK_PACKAGE_VERSION "1.0.0")

set(CPACK_GENERATOR "ZIP")

include(CPack)

The package creation passes without any errors, (!) but the package is empty.

Why it happens and how to fix this issue? (I used cmake 3.12.0)


Solution

  • DESTINATION should be a relative directory within the package.

    Consider the following instead:

    install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "bin" COMPONENT applications)
    

    Explanation: CPack will create the ZIP file after installing the project into a subdirectory of <build-dir>/_CPack_Packages. By specifying an absolute path, no file will be installed in the expected subdirectory and the package will be empty.