Search code examples
cmakecpack

CMake + CPack: Install entire directory (including subfolders)


I'm trying to create an installation package with CMake and CPack. Everything works fine, but I would like to reduce the amount of code drastically by copying my resources folder entirely with one call instead of one for every subfolder.

So far, I do component wise installation the following way:

set(RESOURCES_CALIBRATION_DIR resources/calibration)
file(GLOB RESOURCES_CALIBRATION "${CMAKE_SOURCE_DIR}/${RESOURCES_CALIBRATION_DIR}/*")
install(FILES ${RESOURCES_CALIBRATION} DESTINATION ${RESOURCES_CALIBRATION_DIR} COMPONENT ResourcesCalibration)

set(RESOURCES_CURSORS_DIR resources/cursors)
file(GLOB RESOURCES_CURSORS "${CMAKE_SOURCE_DIR}/${RESOURCES_CURSORS_DIR}/*")
install(FILES ${RESOURCES_CURSORS} DESTINATION ${RESOURCES_CURSORS_DIR} COMPONENT ResourcesCursors)

...
    ... (repeat for every folder of my resources folder)

set(CPACK_COMPONENTS_ALL applications ResourcesCalibration ResourcesCursors ...)
set(CPACK_COMPONENT_RESOURCESCALIBRATION_GROUP "resources")
set(CPACK_COMPONENT_RESOURCESCURSORS_GROUP "resources")
...
    ...

Is there a clean way to copy / install the entire resources folder including all subfolders?


Solution

  • Command flow install(DIRECTORY) exists specifically for installing directory with its subdirectories and files.

    install(DIRECTORY ${CMAKE_SOURCE_DIR}/resources/
            DESTINATION resources
            COMPONENT ResourcesCursors)
    

    or even

    install(DIRECTORY ${CMAKE_SOURCE_DIR}/resources
            DESTINATION .
            COMPONENT ResourcesCursors)
    

    will copy resource directory in the source tree to the installation directory. See documentation on install for more info.