cmake_host_system_information¶
Query various host system information.
Synopsis¶
Query host system specific information cmake_host_system_information(RESULT <variable> QUERY <key> ...) Query Windows registry cmake_host_system_information(RESULT <variable> QUERY WINDOWS_REGISTRY <key> ...)
Query host system specific information¶
cmake_host_system_information(RESULT <variable> QUERY <key> ...)
Queries system information of the host system on which cmake runs.
One or more <key> can be provided to select the information to be
queried. The list of queried values is stored in <variable>.
<key> can be one of the following values:
NUMBER_OF_LOGICAL_CORESNumber of logical cores
NUMBER_OF_PHYSICAL_CORESNumber of physical cores
HOSTNAMEHostname
FQDNFully qualified domain name
TOTAL_VIRTUAL_MEMORYTotal virtual memory in MiB [1]
AVAILABLE_VIRTUAL_MEMORYAvailable virtual memory in MiB [1]
TOTAL_PHYSICAL_MEMORYTotal physical memory in MiB [1]
AVAILABLE_PHYSICAL_MEMORYAvailable physical memory in MiB [1]
IS_64BITNew in version 3.10.
One if processor is 64Bit
HAS_FPUNew in version 3.10.
One if processor has floating point unit
HAS_MMXNew in version 3.10.
One if processor supports MMX instructions
HAS_MMX_PLUSNew in version 3.10.
One if processor supports Ext. MMX instructions
HAS_SSENew in version 3.10.
One if processor supports SSE instructions
HAS_SSE2New in version 3.10.
One if processor supports SSE2 instructions
HAS_SSE_FPNew in version 3.10.
One if processor supports SSE FP instructions
HAS_SSE_MMXNew in version 3.10.
One if processor supports SSE MMX instructions
HAS_AMD_3DNOWNew in version 3.10.
One if processor supports 3DNow instructions
HAS_AMD_3DNOW_PLUSNew in version 3.10.
One if processor supports 3DNow+ instructions
HAS_IA64New in version 3.10.
One if IA64 processor emulating x86
HAS_SERIAL_NUMBERNew in version 3.10.
One if processor has serial number
PROCESSOR_SERIAL_NUMBERNew in version 3.10.
Processor serial number
PROCESSOR_NAMENew in version 3.10.
Human readable processor name
PROCESSOR_DESCRIPTIONNew in version 3.10.
Human readable full processor description
OS_NAMENew in version 3.10.
OS_RELEASENew in version 3.10.
The OS sub-type e.g. on Windows
ProfessionalOS_VERSIONNew in version 3.10.
The OS build ID
OS_PLATFORMNew in version 3.10.
DISTRIB_INFONew in version 3.22.
Read
/etc/os-releasefile and define the given<variable>into a list of read variablesDISTRIB_<name>New in version 3.22.
Get the
<name>variable (see man 5 os-release) if it exists in the/etc/os-releasefileExample:
cmake_host_system_information(RESULT PRETTY_NAME QUERY DISTRIB_PRETTY_NAME) message(STATUS "${PRETTY_NAME}") cmake_host_system_information(RESULT DISTRO QUERY DISTRIB_INFO) foreach(VAR IN LISTS DISTRO) message(STATUS "${VAR}=`${${VAR}}`") endforeach()
Output:
-- Ubuntu 20.04.2 LTS -- DISTRO_BUG_REPORT_URL=`https://bugs.launchpad.net/ubuntu/` -- DISTRO_HOME_URL=`https://www.ubuntu.com/` -- DISTRO_ID=`ubuntu` -- DISTRO_ID_LIKE=`debian` -- DISTRO_NAME=`Ubuntu` -- DISTRO_PRETTY_NAME=`Ubuntu 20.04.2 LTS` -- DISTRO_PRIVACY_POLICY_URL=`https://www.ubuntu.com/legal/terms-and-policies/privacy-policy` -- DISTRO_SUPPORT_URL=`https://help.ubuntu.com/` -- DISTRO_UBUNTU_CODENAME=`focal` -- DISTRO_VERSION=`20.04.2 LTS (Focal Fossa)` -- DISTRO_VERSION_CODENAME=`focal` -- DISTRO_VERSION_ID=`20.04`
If /etc/os-release file is not found, the command tries to gather OS
identification via fallback scripts. The fallback script can use various
distribution-specific files to collect OS identification data and map it
into man 5 os-release variables.
Fallback Interface Variables¶
- CMAKE_GET_OS_RELEASE_FALLBACK_SCRIPTS¶
In addition to the scripts shipped with CMake, a user may append full paths to his script(s) to the this list. The script filename has the following format:
NNN-<name>.cmake, whereNNNis three digits used to apply collected scripts in a specific order.
- CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_<varname>¶
Variables collected by the user provided fallback script ought to be assigned to CMake variables using this naming convention. Example, the
IDvariable from the manual becomesCMAKE_GET_OS_RELEASE_FALLBACK_RESULT_ID.
- CMAKE_GET_OS_RELEASE_FALLBACK_RESULT¶
The fallback script ought to store names of all assigned
CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_<varname>variables in this list.
Example:
# Try to detect some old distribution
# See also
# - http://linuxmafia.com/faq/Admin/release-files.html
#
if(NOT EXISTS "${CMAKE_SYSROOT}/etc/foobar-release")
return()
endif()
# Get the first string only
file(
STRINGS "${CMAKE_SYSROOT}/etc/foobar-release" CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT
LIMIT_COUNT 1
)
#
# Example:
#
# Foobar distribution release 1.2.3 (server)
#
if(CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT MATCHES "Foobar distribution release ([0-9\.]+) .*")
set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_NAME Foobar)
set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_PRETTY_NAME "${CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT}")
set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_ID foobar)
set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION ${CMAKE_MATCH_1})
set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION_ID ${CMAKE_MATCH_1})
list(
APPEND CMAKE_GET_OS_RELEASE_FALLBACK_RESULT
CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_NAME
CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_PRETTY_NAME
CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_ID
CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION
CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION_ID
)
endif()
unset(CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT)
Footnotes
Query Windows registry¶
New in version 3.24.
cmake_host_system_information(RESULT <variable>
QUERY WINDOWS_REGISTRY <key> [VALUE_NAMES|SUBKEYS|VALUE <name>]
[VIEW (64|32|64_32|32_64|HOST|TARGET|BOTH)]
[SEPARATOR <separator>]
[ERROR_VARIABLE <result>])
Performs query operations on local computer registry subkey. Returns a list of
subkeys or value names that are located under the specified subkey in the
registry or the data of the specified value name. The result of the queried
entity is stored in <variable>.
Note
Querying registry for any other platforms than Windows, including
CYGWIN, will always returns an empty string and sets an error message in
the variable specified with sub-option ERROR_VARIABLE.
<key> specify the full path of a subkey on the local computer. The
<key> must include a valid root key. Valid root keys for the local computer
are:
HKLMorHKEY_LOCAL_MACHINEHKCUorHKEY_CURRENT_USERHKCRorHKEY_CLASSES_ROOTHKUorHKEY_USERSHKCCorHKEY_CURRENT_CONFIG
And, optionally, the path to a subkey under the specified root key. The path
separator can be the slash or the backslash. <key> is not case sensitive.
For example:
cmake_host_system_information(RESULT result QUERY WINDOWS_REGISTRY "HKLM")
cmake_host_system_information(RESULT result QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Kitware")
cmake_host_system_information(RESULT result QUERY WINDOWS_REGISTRY "HKCU\\SOFTWARE\\Kitware")
VALUE_NAMESRequest the list of value names defined under
<key>. If a default value is defined, it will be identified with the special name(default).SUBKEYSRequest the list of subkeys defined under
<key>.VALUE <name>Request the data stored in value named
<name>. IfVALUEis not specified or argument is the special name(default), the content of the default value, if any, will be returned.# query default value for HKLM/SOFTWARE/Kitware key cmake_host_system_information(RESULT result QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Kitware") # query default value for HKLM/SOFTWARE/Kitware key using special value name cmake_host_system_information(RESULT result QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Kitware" VALUE "(default)")
Supported types are:
REG_SZ.REG_EXPAND_SZ. The returned data is expanded.REG_MULTI_SZ. The returned is expressed as a CMake list. See alsoSEPARATORsub-option.REG_DWORD.REG_QWORD.
For all other types, an empty string is returned.
VIEWSpecify which registry views must be queried. When not specified,
BOTHview is used.64Query the 64bit registry. On
32bit Windows, returns always an empty string.32Query the 32bit registry.
64_32For
VALUEsub-option or default value, query the registry using view64, and if the request failed, query the registry using view32. ForVALUE_NAMESandSUBKEYSsub-options, query both views (64and32) and merge the results (sorted and duplicates removed).32_64For
VALUEsub-option or default value, query the registry using view32, and if the request failed, query the registry using view64. ForVALUE_NAMESandSUBKEYSsub-options, query both views (32and64) and merge the results (sorted and duplicates removed).HOSTQuery the registry matching the architecture of the host:
64on64bit Windowsand32on32bit Windows.TARGETQuery the registry matching the architecture specified by
CMAKE_SIZEOF_VOID_Pvariable. If not defined, fallback toHOSTview.BOTHQuery both views (
32and64). The order depends of the following rules: IfCMAKE_SIZEOF_VOID_Pvariable is defined. Use the following view depending of the content of this variable:8:64_324:32_64
If
CMAKE_SIZEOF_VOID_Pvariable is not defined, rely on architecture of the host:64bit:64_3232bit:32
SEPARATORSpecify the separator character for
REG_MULTI_SZtype. When not specified, the character\0is used.ERROR_VARIABLE <result>Returns any error raised during query operation. In case of success, the variable holds an empty string.