How to handle multiarch headers?

GNUInstallDirs can automatically set up CMAKE_INSTALL_LIBDIR to point to an architecture-specific directory, e.g. /usr/lib/x86_64-linux-gnu. It does this based on CMAKE_LIBRARY_ARCHITECTURE as well as other factors.

In some cases, not only libraries, but headers are architecture-specific as well. What is the recommended way to handle this case?

See multiarch support: config headers in a per-architecture location by jgmbenoit · Pull Request #2372 · igraph/igraph · GitHub for the motivation.

While we can adjust the value of CMAKE_INSTALL_INCLUDEDIR ourselves, this would need to be done in a way that mirrors GNUInstallDirs’s behaviour with CMAKE_INSTALL_LIBDIR, and that behaviour is complex and not well documented. See https://gitlab.kitware.com/cmake/cmake/-/issues/20565 It is also unclear to me whether there are differences between Linux distros in where they install arch-specific headers. Therefore I was hoping that GNUInstallDirs already has features that can help us here.

I can see a few ways of doing this:

  • install headers with archful names and include them based on the architecture.
  • use DESTINATION "${CMAKE_INSTALL_LIBDIR}/${CMAKE_PROJECT_NAME}/${CMAKE_INSTALL_INCLUDEDIR}"

I suspect that FILE_SET source listings would make it easy to install the archful bits into the LIBDIR and the arch-independent headers into INCLUDEDIR. I don’t think that GNUInstallDirs has anything for this.