1

I am configuring CMake/CPack to install an application which ships with a few read-only shared data files. My understanding is that according to the FHS, such files should be stored under /usr/share, ideally within an application-specific directory (e.g. /usr/share/my_project) rather than directly under /usr/share. I am using GNUInstallDirs as an attempt to stay within (my understanding of) the expectations of the FHS using the following:

#...

include(GNUInstallDirs)

# BAD: Installs files from ${CMAKE_CURRENT_SOURCE_DIR}/data
# into /usr/share
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/"
  TYPE DATA
)

# GOOD: Installs files from ${CMAKE_CURRENT_SOURCE_DIR}/data
# into /usr/share/${PROJECT_NAME}
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/"
  DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}"
)

#...

Everything works as it's documented; my questions are:

  1. Am I understanding the FHS correctly that (ideally) I should put my applications' shared read-only data under /usr/share/my_project?
  2. If that's the case, am I using TYPE DATA wrong in INSTALL(DIRECTORY ...)? That is, should I copy all my data to ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} then use INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} TYPE DATA). That seems like a waste.
  3. Otherwise, if I'm misunderstanding where this type of data should be installed, where should it go, and is TYPE DATA the right way to use install(DIRECTORY ...)? Or do I still need to use an explicitly-specified DESTINATION?

I guess this is a nice way of asking if GNUInstallDirs and TYPE DATA are fit-for-purpose and compatible with the FHS or not. My main goal is to have CMake/CPack Just Put Things Where They Are Supposed To Live without needing to explicitly specify the proper location for each platform's installer.

arclight
  • 1,608
  • 1
  • 15
  • 19
  • 1
    "Am I understanding the FHS correctly that (ideally) I should put my applications' shared read-only data under /usr/share/my_project?" - According to the FHS documentation you refer, FHS *recommends* to use subdirectory under `/usr/share` but does **not require** it to be `my_project`. For use `TYPE DATA` you may either set `CMAKE_INSTALL_DATAROOTDIR` to be subdiretory, or install the directory `${CMAKE_CURRENT_SOURCE_DIR}/my_project` (with last component named correspondingly and **without** terminating `/`). – Tsyvarev Jan 31 '20 at 20:41
  • Sounds like `set(CMAKE_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})` may be the cleanest solution; it hadn't occurred to me to change that. I understand the terminating `/` copies directory contents without copying the base directory; it's similar to `rsync` in that respect. – arclight Jan 31 '20 at 21:04

0 Answers0