Skip to content

fix installing example graphs during CPack; rewrite 'SMYRNA_PATH' discovery

This one requires a bit of an essay to explain and I don't fully understand all the moving parts.


CMake: fix installing example graphs during CPack

When running cpack, instead of staging the Smyrna auxiliary files (share/**) and the example graphs (graphs/**) in build-local directories, they would be incorrectly staged into their final install paths. This was quite unexpected as it would result in errors if you did not have permission to write to the install directories or deleting+replacing files from a previous Graphviz installation if you did.

This bug was introduced in 67f88eb8 as an accidental side effect of enabling Smyrna in the CMake build system. A close re-reading of the CPack¹ and GNUInstallDirs² docs suggests that absolute paths should never be used in install rules:

  `CMAKE_INSTALL_<dir>`
    Destination for files of a given type. This value may be passed to the
    `DESTINATION` options of `install()` commands for the corresponding file
    type. It should typically be a path relative to the installation prefix so
    that it can be converted to an absolute path in a relocatable way (see
    `CMAKE_INSTALL_FULL_<dir>`). However, an absolute path is also allowed.

  `CMAKE_INSTALL_FULL_<dir>`
    The absolute path generated from the corresponding `CMAKE_INSTALL_<dir>`
    value. If the value is not already an absolute path, an absolute path is
    constructed typically by prepending the value of the `CMAKE_INSTALL_PREFIX`
    variable. However, there are some special cases as documented below.

This change brings the behavior on Linux in line with how CPack operates on other platforms – the default value of CMAKE_INSTALL_DATAROOTDIR is share which is the hard coded value set on non-Linux platforms.


smyrna: rewrite 'SMYRNA_PATH' discovery

This aligns Smyrna on other platforms with how Smyrna on Windows locates its templates, examples etc. This resolves a problem where a build time path was being baked into the Smyrna binary, preventing it from being relocatable.

The code for locating our own executable in this MR is adapted from public domain source.³

This change also lifts the 1024 character limit on path discovery in the Windows branch of this logic. It now dynamically expands the target buffer until the current executable name will fit.

Gitlab: fixes #2232 (closed)
Reported-by: Magnus Jacobsson magnus.jacobsson@berotec.se

¹ https://cmake.org/cmake/help/book/mastering-cmake/chapter/Packaging%20With%20CPack.html
² https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
³ https://github.com/Smattr/clink/blob/main/clink/src/find_me.c as of commit 8cadfc49a74e429fa69afdc460cb2b0662d81260

Edited by Magnus Jacobsson

Merge request reports

Loading