Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake top level project with multiple child projects creating packages

Tags:

cmake

cpack

I have multiple CMake projects that each create a debian package. I have been trying to create a top level project that calls add_subdirectory() on each 'child' project. All child projects build but 'make project' creates a project with the last child project's specifications and includes the files from all of the other projects.

Basically, each set(CPACK_...) is being overwritten by the next project until that last one and the 'install()' calls are being accumulated. How can I separate package creation when using a top level project?

Edit: Added snippet. All of the 'child' projects are similar.

# build a CPack driven installer package
if(CMAKE_BUILD_TYPE STREQUAL "release")
    set(CPACK_STRIP_FILES TRUE)
endif()
set(CPACK_GENERATOR DEB)
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VENDOR Acme)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "acme <[email protected]>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Acme daemon")
message(STATUS "CPACK_PACKAGE_DESCRIPTION_SUMMARY: " ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
    set(SYSTEM_PROCESSOR amd64)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
    set(SYSTEM_PROCESSOR armhf)
else()
    message(FATAL_ERROR "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR})
endif()
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${SYSTEM_PROCESSOR})
message(STATUS "CPACK_DEBIAN_PACKAGE_ARCHITECTURE: " ${CPACK_DEBIAN_PACKAGE_ARCHITECTURE})
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_VERSION_MAJOR ${${PROJECT_NAME}_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${${PROJECT_NAME}_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${${PROJECT_NAME}_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_NAME}-${SYSTEM_PROCESSOR})
message(STATUS "CPACK_PACKAGE_FILE_NAME: " ${CPACK_PACKAGE_FILE_NAME})
set(CPACK_DEBIAN_PACKAGE_PRIORITY optional)
include(CPack)
like image 277
DKLind Avatar asked Mar 25 '15 03:03

DKLind


1 Answers

In a CMakeLists.txt of each child project, you can set the CPACK_OUTPUT_CONFIG_FILE variable. For example, for the Child_1 project, in it's cmake file you specify:

set(CPACK_OUTPUT_CONFIG_FILE "${CMAKE_BINARY_DIR}/CPackConfigChild_1.cmake")

Then, after building the top level project, you can do:

cpack -G DEB --config CPackConfigChild_1.cmake
# the same for all other child projects
like image 94
Andrey G.A Avatar answered Sep 21 '22 07:09

Andrey G.A