• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1cmake_host_system_information
2-----------------------------
3
4Query host system specific information.
5
6.. code-block:: cmake
7
8  cmake_host_system_information(RESULT <variable> QUERY <key> ...)
9
10Queries system information of the host system on which cmake runs.
11One or more ``<key>`` can be provided to select the information to be
12queried.  The list of queried values is stored in ``<variable>``.
13
14``<key>`` can be one of the following values:
15
16``NUMBER_OF_LOGICAL_CORES``
17  Number of logical cores
18
19``NUMBER_OF_PHYSICAL_CORES``
20  Number of physical cores
21
22``HOSTNAME``
23  Hostname
24
25``FQDN``
26  Fully qualified domain name
27
28``TOTAL_VIRTUAL_MEMORY``
29  Total virtual memory in MiB [#mebibytes]_
30
31``AVAILABLE_VIRTUAL_MEMORY``
32  Available virtual memory in MiB [#mebibytes]_
33
34``TOTAL_PHYSICAL_MEMORY``
35  Total physical memory in MiB [#mebibytes]_
36
37``AVAILABLE_PHYSICAL_MEMORY``
38  Available physical memory in MiB [#mebibytes]_
39
40``IS_64BIT``
41  .. versionadded:: 3.10
42
43  One if processor is 64Bit
44
45``HAS_FPU``
46  .. versionadded:: 3.10
47
48  One if processor has floating point unit
49
50``HAS_MMX``
51  .. versionadded:: 3.10
52
53  One if processor supports MMX instructions
54
55``HAS_MMX_PLUS``
56  .. versionadded:: 3.10
57
58  One if processor supports Ext. MMX instructions
59
60``HAS_SSE``
61  .. versionadded:: 3.10
62
63  One if processor supports SSE instructions
64
65``HAS_SSE2``
66  .. versionadded:: 3.10
67
68  One if processor supports SSE2 instructions
69
70``HAS_SSE_FP``
71  .. versionadded:: 3.10
72
73  One if processor supports SSE FP instructions
74
75``HAS_SSE_MMX``
76  .. versionadded:: 3.10
77
78  One if processor supports SSE MMX instructions
79
80``HAS_AMD_3DNOW``
81  .. versionadded:: 3.10
82
83  One if processor supports 3DNow instructions
84
85``HAS_AMD_3DNOW_PLUS``
86  .. versionadded:: 3.10
87
88  One if processor supports 3DNow+ instructions
89
90``HAS_IA64``
91  .. versionadded:: 3.10
92
93  One if IA64 processor emulating x86
94
95``HAS_SERIAL_NUMBER``
96  .. versionadded:: 3.10
97
98  One if processor has serial number
99
100``PROCESSOR_SERIAL_NUMBER``
101  .. versionadded:: 3.10
102
103  Processor serial number
104
105``PROCESSOR_NAME``
106  .. versionadded:: 3.10
107
108  Human readable processor name
109
110``PROCESSOR_DESCRIPTION``
111  .. versionadded:: 3.10
112
113  Human readable full processor description
114
115``OS_NAME``
116  .. versionadded:: 3.10
117
118  See :variable:`CMAKE_HOST_SYSTEM_NAME`
119
120``OS_RELEASE``
121  .. versionadded:: 3.10
122
123  The OS sub-type e.g. on Windows ``Professional``
124
125``OS_VERSION``
126  .. versionadded:: 3.10
127
128  The OS build ID
129
130``OS_PLATFORM``
131  .. versionadded:: 3.10
132
133  See :variable:`CMAKE_HOST_SYSTEM_PROCESSOR`
134
135``DISTRIB_INFO``
136  .. versionadded:: 3.22
137
138  Read :file:`/etc/os-release` file and define the given ``<variable>``
139  into a list of read variables
140
141``DISTRIB_<name>``
142  .. versionadded:: 3.22
143
144  Get the ``<name>`` variable (see `man 5 os-release`_) if it exists in the
145  :file:`/etc/os-release` file
146
147  Example:
148
149  .. code-block:: cmake
150
151      cmake_host_system_information(RESULT PRETTY_NAME QUERY DISTRIB_PRETTY_NAME)
152      message(STATUS "${PRETTY_NAME}")
153
154      cmake_host_system_information(RESULT DISTRO QUERY DISTRIB_INFO)
155
156      foreach(VAR IN LISTS DISTRO)
157        message(STATUS "${VAR}=`${${VAR}}`")
158      endforeach()
159
160
161  Output::
162
163    -- Ubuntu 20.04.2 LTS
164    -- DISTRO_BUG_REPORT_URL=`https://bugs.launchpad.net/ubuntu/`
165    -- DISTRO_HOME_URL=`https://www.ubuntu.com/`
166    -- DISTRO_ID=`ubuntu`
167    -- DISTRO_ID_LIKE=`debian`
168    -- DISTRO_NAME=`Ubuntu`
169    -- DISTRO_PRETTY_NAME=`Ubuntu 20.04.2 LTS`
170    -- DISTRO_PRIVACY_POLICY_URL=`https://www.ubuntu.com/legal/terms-and-policies/privacy-policy`
171    -- DISTRO_SUPPORT_URL=`https://help.ubuntu.com/`
172    -- DISTRO_UBUNTU_CODENAME=`focal`
173    -- DISTRO_VERSION=`20.04.2 LTS (Focal Fossa)`
174    -- DISTRO_VERSION_CODENAME=`focal`
175    -- DISTRO_VERSION_ID=`20.04`
176
177If :file:`/etc/os-release` file is not found, the command tries to gather OS
178identification via fallback scripts.  The fallback script can use `various
179distribution-specific files`_ to collect OS identification data and map it
180into `man 5 os-release`_ variables.
181
182Fallback Interface Variables
183^^^^^^^^^^^^^^^^^^^^^^^^^^^^
184
185.. variable:: CMAKE_GET_OS_RELEASE_FALLBACK_SCRIPTS
186
187  In addition to the scripts shipped with CMake, a user may append full
188  paths to his script(s) to the this list.  The script filename has the
189  following format: ``NNN-<name>.cmake``, where ``NNN`` is three digits
190  used to apply collected scripts in a specific order.
191
192.. variable:: CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_<varname>
193
194  Variables collected by the user provided fallback script
195  ought to be assigned to CMake variables using this naming
196  convention.  Example, the ``ID`` variable from the manual becomes
197  ``CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_ID``.
198
199.. variable:: CMAKE_GET_OS_RELEASE_FALLBACK_RESULT
200
201  The fallback script ought to store names of all assigned
202  ``CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_<varname>`` variables in this list.
203
204Example:
205
206.. code-block:: cmake
207
208  # Try to detect some old distribution
209  # See also
210  # - http://linuxmafia.com/faq/Admin/release-files.html
211  #
212  if(NOT EXISTS "${CMAKE_SYSROOT}/etc/foobar-release")
213    return()
214  endif()
215  # Get the first string only
216  file(
217      STRINGS "${CMAKE_SYSROOT}/etc/foobar-release" CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT
218      LIMIT_COUNT 1
219    )
220  #
221  # Example:
222  #
223  #   Foobar distribution release 1.2.3 (server)
224  #
225  if(CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT MATCHES "Foobar distribution release ([0-9\.]+) .*")
226    set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_NAME Foobar)
227    set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_PRETTY_NAME "${CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT}")
228    set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_ID foobar)
229    set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION ${CMAKE_MATCH_1})
230    set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION_ID ${CMAKE_MATCH_1})
231    list(
232        APPEND CMAKE_GET_OS_RELEASE_FALLBACK_RESULT
233        CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_NAME
234        CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_PRETTY_NAME
235        CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_ID
236        CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION
237        CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION_ID
238      )
239  endif()
240  unset(CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT)
241
242
243.. rubric:: Footnotes
244
245.. [#mebibytes] One MiB (mebibyte) is equal to 1024x1024 bytes.
246
247.. _man 5 os-release: https://www.freedesktop.org/software/systemd/man/os-release.html
248.. _various distribution-specific files: http://linuxmafia.com/faq/Admin/release-files.html
249