GNUInstallDirs¶
This module defines the installation directory variables according to the GNU Coding Standards and provides a command to compute installation-related absolute paths.
Load this module in a CMake project with:
include(GNUInstallDirs)
Result Variables¶
Inclusion of this module defines the following variables:
CMAKE_INSTALL_<dir>Destination for files of a given type. This value may be passed to the
DESTINATIONoptions ofinstall()commands for the corresponding file type. It should be a path relative to the installation prefix so that it can be converted to an absolute path in a relocatable way. However, there are some special cases as documented below.While absolute paths are allowed, they are not recommended as they do not work with the
cmake --installcommand's--prefixoption, or with thecpackinstaller generators. In particular, there is no need to make paths absolute by prependingCMAKE_INSTALL_PREFIX; this prefix is used by default if the DESTINATION is a relative path.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 theCMAKE_INSTALL_PREFIXvariable, except in special cases as documented below.These variables shouldn't be used in
install()commands as they do not work with thecmake --installcommand's--prefixoption, or with thecpackinstaller generators.
where <dir> is one of:
BINDIRuser executables (
bin)SBINDIRsystem admin executables (
sbin)LIBEXECDIRprogram executables (
libexec)SYSCONFDIRread-only single-machine data (
etc)Changed in version 4.1: If the
CMAKE_INSTALL_PREFIXfalls into the special cases, the default paths for are the absolute path variants as described there. See policyCMP0192.SHAREDSTATEDIRmodifiable architecture-independent data (
com)LOCALSTATEDIRmodifiable single-machine data (
var)Changed in version 4.1: If the
CMAKE_INSTALL_PREFIXfalls into the special cases, the default paths for are the absolute path variants as described there. See policyCMP0192.RUNSTATEDIRrun-time variable data (
LOCALSTATEDIR/run)Added in version 3.9.
Changed in version 4.1: If the
CMAKE_INSTALL_PREFIXfalls into the special cases, the default paths for are the absolute path variants as described there. See policyCMP0192.LIBDIRobject code libraries (
liborlib64)On Linux, when not cross-compiling, the default is the distro's arch-specific library directory, such as
liborlib64. On Debian, this may belib/<multiarch-tuple>whenCMAKE_INSTALL_PREFIXis/usr. When cross-compiling, the default islib.In projects that enable no languages, e.g.,
project(... LANGUAGES NONE), no target architecture information is available, so the default islib.Note
When an alternative installation prefix is specified with the
--prefixoption at install time, the special case with multi-architecture tuple is evaluated based on the configuration-timeCMAKE_INSTALL_PREFIX, not on the alternative prefix value.INCLUDEDIRC header files (
include)OLDINCLUDEDIRC header files for non-gcc (
/usr/include)DATAROOTDIRread-only architecture-independent data root (
share)DATADIRread-only architecture-independent data (
DATAROOTDIR)The
DATADIRandDATAROOTDIRare treated separately so thatDATADIRcan be customized for project-specific data files, whileDATAROOTDIRremains unchanged for standard architecture-independent locationsINFODIR,LOCALEDIR,MANDIR, andDOCDIR.INFODIRinfo documentation (
DATAROOTDIR/info)LOCALEDIRlocale-dependent data (
DATAROOTDIR/locale)MANDIRman documentation (
DATAROOTDIR/man)DOCDIRdocumentation root (
DATAROOTDIR/doc/PROJECT_NAME)
If the includer does not define a value the above-shown default will be used and the value will appear in the cache for editing by the user.
If a default value for the CMAKE_INSTALL_<dir> is used and the
CMAKE_INSTALL_PREFIX is changed, the new default value will
be used calculated on the new CMAKE_INSTALL_PREFIX value.
Using --prefix in cmake --install
will not alter these values.
Special Cases¶
Added in version 3.4.
The following values of CMAKE_INSTALL_PREFIX are special:
/
For
<dir>other than theSYSCONFDIR,LOCALSTATEDIRandRUNSTATEDIR, the value ofCMAKE_INSTALL_<dir>is prefixed withusr/if it is not user-specified as an absolute path. For example, theINCLUDEDIRvalueincludebecomesusr/include. This is required by the GNU Coding Standards, which state:When building the complete GNU system, the prefix will be empty and
/usrwill be a symbolic link to/.Changed in version 4.1: The
CMAKE_INSTALL_<dir>variables are cached with theusr/prefix. See policyCMP0193.
/usr
For
<dir>equal toSYSCONFDIR,LOCALSTATEDIRorRUNSTATEDIR, theCMAKE_INSTALL_FULL_<dir>is computed by prepending just/to the value ofCMAKE_INSTALL_<dir>if it is not already an absolute path. For example, theSYSCONFDIRvalueetcbecomes/etc. This is required by the GNU Coding Standards.Changed in version 4.1: The default values of
CMAKE_INSTALL_<dir>for<dir>equal toSYSCONFDIR,LOCALSTATEDIRandRUNSTATEDIRare the absolute paths/etc,/varand/var/runrespectively. See policyCMP0192.
/opt/...
For
<dir>equal toSYSCONFDIR,LOCALSTATEDIRorRUNSTATEDIR, theCMAKE_INSTALL_FULL_<dir>is computed by appending the prefix to the value ofCMAKE_INSTALL_<dir>if it is not already an absolute path. For example, theSYSCONFDIRvalueetcbecomes/etc/opt/.... This is defined by the Filesystem Hierarchy Standard.This behavior does not apply to paths under
/opt/homebrew/....Changed in version 4.1: The default values of
CMAKE_INSTALL_<dir>for<dir>equal toSYSCONFDIR,LOCALSTATEDIRandRUNSTATEDIRare the absolute paths/etc/opt/...,/var/opt/...and/var/run/opt/...respectively. See policyCMP0192.
Note
When an alternative installation prefix is specified with the
--prefix option at install time,
these special cases are evaluated based on the configuration-time
CMAKE_INSTALL_PREFIX, not on the alternative prefix value.
Commands¶
This module provides the following command:
- GNUInstallDirs_get_absolute_install_dir¶
Added in version 3.7.
Computes an absolute installation path from a given relative path:
GNUInstallDirs_get_absolute_install_dir(<result-var> <input-var> <dir>)
This command takes the value from the variable
<input-var>and computes its absolute path according to GNU standard installation directories. If the input path is relative, it is prepended withCMAKE_INSTALL_PREFIXand may be adjusted for the special cases described above.The arguments are:
<result-var>Name of the variable in which to store the computed absolute path.
<input-var>Name of the variable containing the path that will be used to compute its associated absolute installation path.
Changed in version 4.1: This variable is no longer altered. See policy
CMP0193. In previous CMake versions, this command modified the<input-var>variable value based on the special cases.<dir>Added in version 3.20.
The directory type name, e.g.,
SYSCONFDIR,LOCALSTATEDIR,RUNSTATEDIR, etc. This argument determines whether special cases apply when computing the absolute path.Changed in version 3.20: Before the
<dir>argument was introduced, the directory type could be specified by setting thedirvariable prior to calling this command. As of CMake 3.20, if the<dir>argument is provided explicitly, thedirvariable is ignored.
While this command is used internally by this module to compute the
CMAKE_INSTALL_FULL_<dir>variables, it is also exposed publicly for users to create additional custom installation path variables and compute absolute paths where necessary, using the same logic.
See Also¶
The
install()command.