If I install the same CMake-based package (cxxopts) with the same compiler (gcc12) on two different Unix machines (CentOS & MacOS), one time I get a prefix/lib and the other a prefix/lib64 directory.
Is there a way to predict what the lib directory is going to be?
How does CMake decide to make a lib or lib64 directory for installations?
It's not so much up to CMake as it is up to the maintainers of a project where a target gets installed to (see the DESTINATION parameter of the install(...) command).
cxxopts uses GNUInstallDirs, which is a helper module provided by CMake defining conventional installation locations for different types of things. See its CMakeLists.txt (include(GNUInstallDirs)) and its cxxopts.cmake file (install(TARGETS cxxopts EXPORT ${targets_export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})).
From the GNUInstallDirs docs:
LIBDIR
object code libraries (lib or lib64)
Is there a way to predict what the lib directory is going to be?
If the project uses GNUInstallDirs, yes. From the CMake source code:
Override this default 'lib' with 'lib64' iff:
- we are on Linux system but NOT cross-compiling
- we are NOT on debian
- we are NOT building for conda
- we are on a 64 bits system
reason is: amd64 ABI: https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI For Debian with multiarch, use
lib/${CMAKE_LIBRARY_ARCHITECTURE}ifCMAKE_LIBRARY_ARCHITECTUREis set (which contains e.g. "i386-linux-gnu" andCMAKE_INSTALL_PREFIXis "/usr". See http://wiki.debian.org/Multiarch
If you want to do a check at configure time of what this is, then check the CMAKE_INSTALL_LIBDIR variable. Ex. if("${CMAKE_INSTALL_LIBDIR}" STREQUAL "lib64") ....
The installation directory is determined from two parts.
CMAKE_INSTALL_PREFIX. This variable can be set by the user when configuring the build and projects should respect that choice. The default on Linux for this is usually /usr/local, but you can set it to instead install to, say, a subfolder within your home directory.lib or lib64 subdirectory therefore depends on the individual project and there is no hard rule for predicting the directory layout from the outside.The exact directory structure within the install directory is determined by the INSTALL commands given to CMake, in particular the DESTINATION field. Most projects follow common conventions here, but you will need to consult a project's documentation or its CMake files to figure out the exact layout.
The relevant INSTALL command for cxxopts can be found here.
Note that cxxopts uses CMake's GNUInstallDirs module to configure the directories, which follows the common GNU/Linux conventions. That module is also responsible for the distinction between lib and lib64 here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With