Issue
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?
Solution
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_ARCHITECTURE
is set (which contains e.g. "i386-linux-gnu" andCMAKE_INSTALL_PREFIX
is "/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") ...
.
Answered By - starball Answer Checked By - Dawn Plyler (WPSolving Volunteer)