# SPDX-License-Identifier: MIT # # The `install-help-user` target's body. Copies the Mallard help set into the user's XDG data # directory -- where `help:` resolves without root -- and prints every path it wrote. # # `$XDG_DATA_HOME` is honoured when it is set, and `$HOME/.local/share` is the fallback when it # is not: that is the XDG Base Directory Specification's own stated default for the variable, and # it is the default `help_installed_path()` falls back to as well, so the manual lands where the # application and the desktop viewer look for it. The variable names a *data directory*, not a # prefix -- its `share/` is not appended -- so the set goes to `/help/C//`. An # arbitrary `$XDG_DATA_HOME` need not end in `share`, which is exactly why this copies the tree # rather than deferring to `cmake --install --prefix`, whose datadir is always `/share`. # # Like the desktop-entry target, this runs only when it is named: `cmake --build build` never # touches the user's data directory. # # Expects -DHELP_SRC= and -DHELP_NAME= on the command line. if(DEFINED ENV{XDG_DATA_HOME} AND NOT "$ENV{XDG_DATA_HOME}" STREQUAL "") set(data_home "$ENV{XDG_DATA_HOME}") elseif(DEFINED ENV{HOME} AND NOT "$ENV{HOME}" STREQUAL "") set(data_home "$ENV{HOME}/.local/share") else() message(FATAL_ERROR "XDG_DATA_HOME and HOME are both unset or empty; cannot determine the user data directory") endif() if(NOT DEFINED HELP_SRC OR NOT DEFINED HELP_NAME) message(FATAL_ERROR "HELP_SRC and HELP_NAME are both required") endif() set(dest "${data_home}/help/C/${HELP_NAME}") # The same filter as the install() rule, so both destinations carry the same tree: the pages and # the figures, and nothing an editor left behind. file(COPY "${HELP_SRC}/" DESTINATION "${dest}" FILES_MATCHING PATTERN "*.page" PATTERN "*.png" PATTERN "*.jpg") # Printed because there is no uninstall target: undoing this is these paths. file(GLOB_RECURSE installed LIST_DIRECTORIES FALSE RELATIVE "${dest}" "${dest}/*") list(SORT installed) foreach(path IN LISTS installed) message(STATUS "wrote ${dest}/${path}") endforeach()