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?
2
Answers
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
orlib64
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 theDESTINATION
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 betweenlib
andlib64
here.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 theinstall(...)
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:
If the project uses GNUInstallDirs, yes. From the CMake source code:
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") ...
.