Search code examples
cmakecpack

cpack component install does not work


I want the cpack to take only certain components. But he takes both run and deb components. I looked at a lot of sources. including this cpack component level install . but I did not understand what I was doing wrong. Tell me please, what did I do wrong? My CMakeLists.txt

cmake_minimum_required(VERSION 3.8)
project(testProj)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)
add_executable(testProj ${SOURCE_FILES})

set(CMAKE_INSTALL_PREFIX .)

install(FILES temp.h DESTINATION someFolder
        PERMISSIONS OWNER_READ OWNER_WRITE WORLD_READ WORLD_EXECUTE COMPONENT deb
        )

install(FILES Alpha0.400000.txt DESTINATION someFolder
        PERMISSIONS OWNER_READ OWNER_WRITE WORLD_READ WORLD_EXECUTE COMPONENT run
        )

set(CPACK_TGZ_COMPONENT_INSTALL ON)
set(CPACK_COMPONENT_ALL deb)
set(CPACK_COMPONENTS_ALL deb)

include(CPack)

my steps to get an artifact

cmake . 
make 
cpack .

CPack: Create package using STGZ
CPack: Install projects
CPack: - Run preinstall target for: testProj
CPack: - Install project: testProj
CPack: Create package
CPack: - package: /home/danyal/testProj/test/testProj-0.1.1-Linux.sh generated.
CPack: Create package using TGZ
CPack: Install projects
CPack: - Run preinstall target for: testProj
CPack: - Install project: testProj
CPack: Create package
CPack: - package: /home/danyal/testProj/test/testProj-0.1.1-Linux.tar.gz generated.
CPack: Create package using TZ
CPack: Install projects
CPack: - Run preinstall target for: testProj
CPack: - Install project: testProj
CPack: Create package
CPack: - package: /home/danyal/testProj/test/testProj-0.1.1-Linux.tar.Z generated.

and testProj-0.1.1-Linux.tar.gz contains

someFolder
   -temp.h
   -Alpha0.400000.txt

Solution

  • Simply add the following to your CMakeLists.txt

    set(CPACK_ARCHIVE_COMPONENT_INSTALL 1)
    

    I ran into exactly the same problem and had to dive into the source to find the answer. The following function gives the answer:

    bool cmCPackArchiveGenerator::SupportsComponentInstallation() const
    {
      // The Component installation support should only
      // be activated if explicitly requested by the user
      // (for backward compatibility reason)
      return IsOn("CPACK_ARCHIVE_COMPONENT_INSTALL");
    }
    

    For compatibility reasons any archive packaging, i.e. ZIP and TGZ doesn't use component installations.