4

Is it possible to add some files only to the ARCHIVE generators with CMake/CPack? Apparently components do that, but I can't figure how to say "only add component X to generator Y". I did something like this:

INSTALL(FILES somefile DESTINATION "." COMPONENT static)

But how to add the static component only to ARCHIVEs and not to other generators like DEB and RPM?

brunobg
  • 786
  • 6
  • 27

2 Answers2

4

Eventually found this with some help from the CMake list. In your CMakeLists.txt do something like this:

install(PROGRAMS basic.sh DESTINATION "." COMPONENT basic)
install(PROGRAMS optional.sh DESTINATION "." COMPONENT optional)

set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/CPackOptions.cmake")

CPackOptions.cmake should handle the ifs. Notice that you must turn on CPACK_*_COMPONENT_INSTALL for any other generator you might want:

SET(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
SET(CPACK_DEB_COMPONENT_INSTALL ON)
SET(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)

IF ("${CPACK_GENERATOR}" MATCHES "TGZ")
   SET(CPACK_COMPONENTS_ALL basic optional)
ELSEIF ("${CPACK_GENERATOR}" MATCHES "TBZ2")
   SET(CPACK_COMPONENTS_ALL basic optional)
ELSE()
   SET(CPACK_COMPONENTS_ALL basic)
ENDIF()
brunobg
  • 786
  • 6
  • 27
1

This is how I solved this question, where I wanted to install README and LICENCE files to the CPack archive outputs (ZIP, TGZ, etc.):

...
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt")
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE ON)
install(FILES
  ${CPACK_RESOURCE_FILE_README}
  ${CPACK_RESOURCE_FILE_LICENSE}
  DESTINATION .
  COMPONENT Metadata
  EXCLUDE_FROM_ALL
)
include(CPack)
Mike T
  • 41,085
  • 18
  • 152
  • 203