7

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 <support@acme.com>")
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)
mpromonet
  • 11,326
  • 43
  • 62
  • 91
DKLind
  • 71
  • 6
  • Can you share an extract of subdirectory CMakeLists.txt files? Namely, on how the `set(CPACK_... )` actually happens? – Antonio Mar 26 '15 at 14:34
  • I just edited my original post and added a snippet of what each 'child' project's CMakeLists.txt contains. – DKLind Mar 26 '15 at 16:25
  • I think that more than a CMake problem, this is a CPack problem (which I do not know, sorry). Searching for "cpack multiple packages" there are a couple of ideas... – Antonio Mar 27 '15 at 12:21

1 Answers1

1

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
Andrey G.A
  • 305
  • 4
  • 20