Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding files to ARCHIVE packages only in CPack

Tags:

cmake

cpack

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?

like image 417
brunobg Avatar asked Oct 14 '25 18:10

brunobg


2 Answers

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()
like image 90
brunobg Avatar answered Oct 18 '25 04:10

brunobg


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)
like image 31
Mike T Avatar answered Oct 18 '25 03:10

Mike T