0

I have one CMake project which looks something like:

-Project
|--ApplicationA
|     |---main.cpp
|     |---CMakeLists.txt
|--ApplicationB
|     |---main.cpp
|     |---CMakeLists.txt
|--CMakeLists.txt

Is there any possibility that I can run "make packages" (CPack) and it will create one Debian package for ApplicationA and one for ApplicationB?

usr1234567
  • 21,601
  • 16
  • 108
  • 128
unikat
  • 341
  • 2
  • 5
  • 14

2 Answers2

0

You can specify components to the install command. CMake Components

David Marquant
  • 2,039
  • 14
  • 12
0

I was also looking into this, but it was difficult to find information, so for other people that are looking for such a solution, this is how I did it using components, also with the structure above of one main CMakeLists.txt and two other CMakeLists.txt in the subdirectories. For these Debian packages, it was only meant to get the dependencies right (so no specific cpp files to build).

For my solution, this is the content of the CMakeLists.txt in the main directory:

cmake_minimum_required(VERSION 3.7.2)

project(EVSE-PACKAGE-GENERATOR VERSION 3.0.0)

set(CPACK_COMPONENTS_ALL <COMPONENT_1> <COMPONENT_2>)
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Maintainer")
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "...")

add_subdirectory(subdirectory1) #In this case "ApplicationA"

add_subdirectory(subdirectory2) #In this case "ApplicationB"

include(CPack)

And these the CMakeLists.txt for component1 (ApplicationA):

cmake_minimum_required(VERSION a.b.c)

project(<COMPONENT_1> VERSION x.y.z)

set(CPACK_COMPONENT_<COMPONENT_1>_DESCRIPTION "Component 1 description" PARENT_SCOPE)
set(CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_FILE_NAME "comp1name")
set(CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_NAME "prefix-${CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_FILE_NAME}" PARENT_SCOPE)
set(CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_DEPENDS "..." PARENT_SCOPE)

set(CPACK_<COMPONENT_1>_PACKAGE_VERSION "${PROJECT_VERSION}${PROJECT_VERSION_PRERELEASE}")
set(CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_ARCHITECTURE "...")

string(TOLOWER "prefix-${CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_FILE_NAME}_${CPACK_<COMPONENT_1>_PACKAGE_VERSION}_${CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_ARCHITECTURE}.deb" DEBIAN_<COMPONENT_1>_FILENAME_STRING )
set(CPACK_DEBIAN_<COMPONENT_1>_FILE_NAME ${DEBIAN_<COMPONENT_1>_FILENAME_STRING} PARENT_SCOPE )
set(CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_CONTROL_STRICT_PERMISSION TRUE PARENT_SCOPE)

and component 2 (Application B):

cmake_minimum_required(VERSION a.b.c)

project(<COMPONENT_2> VERSION x.y.z)

set(CPACK_COMPONENT_<COMPONENT_2>_DESCRIPTION "Component 2 description" PARENT_SCOPE)
set(CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_FILE_NAME "comp2name")
set(CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_NAME "prefix-${CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_FILE_NAME}" PARENT_SCOPE)
set(CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_DEPENDS "..." PARENT_SCOPE)

set(CPACK_<COMPONENT_2>_PACKAGE_VERSION "${PROJECT_VERSION}${PROJECT_VERSION_PRERELEASE}" )
set(CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_ARCHITECTURE "..." )

string(TOLOWER "prefix-${CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_FILE_NAME}_${CPACK_<COMPONENT_2>_PACKAGE_VERSION}_${CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_ARCHITECTURE}.deb" DEBIAN_<COMPONENT_2>_FILENAME_STRING )
set(CPACK_DEBIAN_<COMPONENT_2>_FILE_NAME ${DEBIAN_<COMPONENT_2>_FILENAME_STRING} PARENT_SCOPE )
set(CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_CONTROL_STRICT_PERMISSION_PACKAGE_CONTROL_STRICT_PERMISSION TRUE PARENT_SCOPE)

Hopefully, this will help someone in the future. Also, I have got some other sources that might be helpful for anyone looking into this or similar problems:

The Ultimate guide to modern CMake

StackOverflow - Name and description of multiple debian packages with CMake and CPack

CPack: Create debian packge for each sub-project