4

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
  • Which CPack generator do you use (that is, what kind of package is created - `.tgz`, `.rpm`, etc.)? See [wiki](https://cmake.org/Wiki/CMake:Component_Install_With_CPack) about enabling component packaging for specific generator. – Tsyvarev Nov 02 '17 at 17:41
  • Yes, I tried write in my CMakeLists set(CPACK_TGZ_COMPONENT_INSTALL ON) but it also does not work – Danyal Mugutdinov Nov 03 '17 at 08:21
  • So you use `TGZ` package generator, and it produces single `testProj.tgz` file, which includes both `temp.h` and `Alpha0.400000.txt`. Do I correctly understand what you have now? – Tsyvarev Nov 03 '17 at 09:01
  • yes, but it generates tar.gz `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.` – Danyal Mugutdinov Nov 03 '17 at 09:17
  • Add these messages generated by CPack into the question post (via [edit]). – Tsyvarev Nov 03 '17 at 09:20

2 Answers2

4

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.

Twan Spil
  • 56
  • 4
1

In this scenario, I think you should call make on the package target created by Cmake and not call cpack directly, i.e. call make package instead of cpack ..

Alternatively, if you do call cpack directly you can pass the component(s) you want to package as a command line argument. e.g. cpack -D CPACK_COMPONENTS_ALL="deb" (separated by ';' for multiple components)

(Note the proper variable is CPACK_COMPONENTS_ALL not CPACK_COMPONENT_ALL)

AndrewJC
  • 1,318
  • 12
  • 11