cmake_host_system_information.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. cmake_host_system_information
  2. -----------------------------
  3. Query various host system information.
  4. Synopsis
  5. ^^^^^^^^
  6. .. parsed-literal::
  7. `Query host system specific information`_
  8. cmake_host_system_information(RESULT <variable> QUERY <key> ...)
  9. `Query Windows registry`_
  10. cmake_host_system_information(RESULT <variable> QUERY WINDOWS_REGISTRY <key> ...)
  11. Query host system specific information
  12. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  13. .. code-block:: cmake
  14. cmake_host_system_information(RESULT <variable> QUERY <key> ...)
  15. Queries system information of the host system on which cmake runs.
  16. One or more ``<key>`` can be provided to select the information to be
  17. queried. The list of queried values is stored in ``<variable>``.
  18. ``<key>`` can be one of the following values:
  19. ``NUMBER_OF_LOGICAL_CORES``
  20. Number of logical cores
  21. ``NUMBER_OF_PHYSICAL_CORES``
  22. Number of physical cores
  23. ``HOSTNAME``
  24. Hostname
  25. ``FQDN``
  26. Fully qualified domain name
  27. ``TOTAL_VIRTUAL_MEMORY``
  28. Total virtual memory in MiB [#mebibytes]_
  29. ``AVAILABLE_VIRTUAL_MEMORY``
  30. Available virtual memory in MiB [#mebibytes]_
  31. ``TOTAL_PHYSICAL_MEMORY``
  32. Total physical memory in MiB [#mebibytes]_
  33. ``AVAILABLE_PHYSICAL_MEMORY``
  34. Available physical memory in MiB [#mebibytes]_
  35. ``IS_64BIT``
  36. .. versionadded:: 3.10
  37. One if processor is 64Bit
  38. ``HAS_FPU``
  39. .. versionadded:: 3.10
  40. One if processor has floating point unit
  41. ``HAS_MMX``
  42. .. versionadded:: 3.10
  43. One if processor supports MMX instructions
  44. ``HAS_MMX_PLUS``
  45. .. versionadded:: 3.10
  46. One if processor supports Ext. MMX instructions
  47. ``HAS_SSE``
  48. .. versionadded:: 3.10
  49. One if processor supports SSE instructions
  50. ``HAS_SSE2``
  51. .. versionadded:: 3.10
  52. One if processor supports SSE2 instructions
  53. ``HAS_SSE_FP``
  54. .. versionadded:: 3.10
  55. One if processor supports SSE FP instructions
  56. ``HAS_SSE_MMX``
  57. .. versionadded:: 3.10
  58. One if processor supports SSE MMX instructions
  59. ``HAS_AMD_3DNOW``
  60. .. versionadded:: 3.10
  61. One if processor supports 3DNow instructions
  62. ``HAS_AMD_3DNOW_PLUS``
  63. .. versionadded:: 3.10
  64. One if processor supports 3DNow+ instructions
  65. ``HAS_IA64``
  66. .. versionadded:: 3.10
  67. One if IA64 processor emulating x86
  68. ``HAS_SERIAL_NUMBER``
  69. .. versionadded:: 3.10
  70. One if processor has serial number
  71. ``PROCESSOR_SERIAL_NUMBER``
  72. .. versionadded:: 3.10
  73. Processor serial number
  74. ``PROCESSOR_NAME``
  75. .. versionadded:: 3.10
  76. Human readable processor name
  77. ``PROCESSOR_DESCRIPTION``
  78. .. versionadded:: 3.10
  79. Human readable full processor description
  80. ``OS_NAME``
  81. .. versionadded:: 3.10
  82. See :variable:`CMAKE_HOST_SYSTEM_NAME`
  83. ``OS_RELEASE``
  84. .. versionadded:: 3.10
  85. The OS sub-type e.g. on Windows ``Professional``
  86. ``OS_VERSION``
  87. .. versionadded:: 3.10
  88. The OS build ID
  89. ``OS_PLATFORM``
  90. .. versionadded:: 3.10
  91. See :variable:`CMAKE_HOST_SYSTEM_PROCESSOR`
  92. ``DISTRIB_INFO``
  93. .. versionadded:: 3.22
  94. Read :file:`/etc/os-release` file and define the given ``<variable>``
  95. into a list of read variables
  96. ``DISTRIB_<name>``
  97. .. versionadded:: 3.22
  98. Get the ``<name>`` variable (see `man 5 os-release`_) if it exists in the
  99. :file:`/etc/os-release` file
  100. Example:
  101. .. code-block:: cmake
  102. cmake_host_system_information(RESULT PRETTY_NAME QUERY DISTRIB_PRETTY_NAME)
  103. message(STATUS "${PRETTY_NAME}")
  104. cmake_host_system_information(RESULT DISTRO QUERY DISTRIB_INFO)
  105. foreach(VAR IN LISTS DISTRO)
  106. message(STATUS "${VAR}=`${${VAR}}`")
  107. endforeach()
  108. Output::
  109. -- Ubuntu 20.04.2 LTS
  110. -- DISTRO_BUG_REPORT_URL=`https://bugs.launchpad.net/ubuntu/`
  111. -- DISTRO_HOME_URL=`https://www.ubuntu.com/`
  112. -- DISTRO_ID=`ubuntu`
  113. -- DISTRO_ID_LIKE=`debian`
  114. -- DISTRO_NAME=`Ubuntu`
  115. -- DISTRO_PRETTY_NAME=`Ubuntu 20.04.2 LTS`
  116. -- DISTRO_PRIVACY_POLICY_URL=`https://www.ubuntu.com/legal/terms-and-policies/privacy-policy`
  117. -- DISTRO_SUPPORT_URL=`https://help.ubuntu.com/`
  118. -- DISTRO_UBUNTU_CODENAME=`focal`
  119. -- DISTRO_VERSION=`20.04.2 LTS (Focal Fossa)`
  120. -- DISTRO_VERSION_CODENAME=`focal`
  121. -- DISTRO_VERSION_ID=`20.04`
  122. If :file:`/etc/os-release` file is not found, the command tries to gather OS
  123. identification via fallback scripts. The fallback script can use `various
  124. distribution-specific files`_ to collect OS identification data and map it
  125. into `man 5 os-release`_ variables.
  126. Fallback Interface Variables
  127. """"""""""""""""""""""""""""
  128. .. variable:: CMAKE_GET_OS_RELEASE_FALLBACK_SCRIPTS
  129. In addition to the scripts shipped with CMake, a user may append full
  130. paths to his script(s) to the this list. The script filename has the
  131. following format: ``NNN-<name>.cmake``, where ``NNN`` is three digits
  132. used to apply collected scripts in a specific order.
  133. .. variable:: CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_<varname>
  134. Variables collected by the user provided fallback script
  135. ought to be assigned to CMake variables using this naming
  136. convention. Example, the ``ID`` variable from the manual becomes
  137. ``CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_ID``.
  138. .. variable:: CMAKE_GET_OS_RELEASE_FALLBACK_RESULT
  139. The fallback script ought to store names of all assigned
  140. ``CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_<varname>`` variables in this list.
  141. Example:
  142. .. code-block:: cmake
  143. # Try to detect some old distribution
  144. # See also
  145. # - http://linuxmafia.com/faq/Admin/release-files.html
  146. #
  147. if(NOT EXISTS "${CMAKE_SYSROOT}/etc/foobar-release")
  148. return()
  149. endif()
  150. # Get the first string only
  151. file(
  152. STRINGS "${CMAKE_SYSROOT}/etc/foobar-release" CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT
  153. LIMIT_COUNT 1
  154. )
  155. #
  156. # Example:
  157. #
  158. # Foobar distribution release 1.2.3 (server)
  159. #
  160. if(CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT MATCHES "Foobar distribution release ([0-9\.]+) .*")
  161. set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_NAME Foobar)
  162. set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_PRETTY_NAME "${CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT}")
  163. set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_ID foobar)
  164. set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION ${CMAKE_MATCH_1})
  165. set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION_ID ${CMAKE_MATCH_1})
  166. list(
  167. APPEND CMAKE_GET_OS_RELEASE_FALLBACK_RESULT
  168. CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_NAME
  169. CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_PRETTY_NAME
  170. CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_ID
  171. CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION
  172. CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION_ID
  173. )
  174. endif()
  175. unset(CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT)
  176. .. rubric:: Footnotes
  177. .. [#mebibytes] One MiB (mebibyte) is equal to 1024x1024 bytes.
  178. .. _man 5 os-release: https://www.freedesktop.org/software/systemd/man/os-release.html
  179. .. _various distribution-specific files: http://linuxmafia.com/faq/Admin/release-files.html
  180. .. _Query Windows registry:
  181. Query Windows registry
  182. ^^^^^^^^^^^^^^^^^^^^^^
  183. .. versionadded:: 3.24
  184. ::
  185. cmake_host_system_information(RESULT <variable>
  186. QUERY WINDOWS_REGISTRY <key> [VALUE_NAMES|SUBKEYS|VALUE <name>]
  187. [VIEW (64|32|64_32|32_64|HOST|TARGET|BOTH)]
  188. [SEPARATOR <separator>]
  189. [ERROR_VARIABLE <result>])
  190. Performs query operations on local computer registry subkey. Returns a list of
  191. subkeys or value names that are located under the specified subkey in the
  192. registry or the data of the specified value name. The result of the queried
  193. entity is stored in ``<variable>``.
  194. .. note::
  195. Querying registry for any other platforms than ``Windows``, including
  196. ``CYGWIN``, will always returns an empty string and sets an error message in
  197. the variable specified with sub-option ``ERROR_VARIABLE``.
  198. ``<key>`` specify the full path of a subkey on the local computer. The
  199. ``<key>`` must include a valid root key. Valid root keys for the local computer
  200. are:
  201. * ``HKLM`` or ``HKEY_LOCAL_MACHINE``
  202. * ``HKCU`` or ``HKEY_CURRENT_USER``
  203. * ``HKCR`` or ``HKEY_CLASSES_ROOT``
  204. * ``HKU`` or ``HKEY_USERS``
  205. * ``HKCC`` or ``HKEY_CURRENT_CONFIG``
  206. And, optionally, the path to a subkey under the specified root key. The path
  207. separator can be the slash or the backslash. ``<key>`` is not case sensitive.
  208. For example:
  209. .. code-block:: cmake
  210. cmake_host_system_information(RESULT result QUERY WINDOWS_REGISTRY "HKLM")
  211. cmake_host_system_information(RESULT result QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Kitware")
  212. cmake_host_system_information(RESULT result QUERY WINDOWS_REGISTRY "HKCU\\SOFTWARE\\Kitware")
  213. ``VALUE_NAMES``
  214. Request the list of value names defined under ``<key>``. If a default value
  215. is defined, it will be identified with the special name ``(default)``.
  216. ``SUBKEYS``
  217. Request the list of subkeys defined under ``<key>``.
  218. ``VALUE <name>``
  219. Request the data stored in value named ``<name>``. If ``VALUE`` is not
  220. specified or argument is the special name ``(default)``, the content of the
  221. default value, if any, will be returned.
  222. .. code-block:: cmake
  223. # query default value for HKLM/SOFTWARE/Kitware key
  224. cmake_host_system_information(RESULT result
  225. QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Kitware")
  226. # query default value for HKLM/SOFTWARE/Kitware key using special value name
  227. cmake_host_system_information(RESULT result
  228. QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Kitware"
  229. VALUE "(default)")
  230. Supported types are:
  231. * ``REG_SZ``.
  232. * ``REG_EXPAND_SZ``. The returned data is expanded.
  233. * ``REG_MULTI_SZ``. The returned is expressed as a CMake list. See also
  234. ``SEPARATOR`` sub-option.
  235. * ``REG_DWORD``.
  236. * ``REG_QWORD``.
  237. For all other types, an empty string is returned.
  238. ``VIEW``
  239. Specify which registry views must be queried. When not specified, ``BOTH``
  240. view is used.
  241. ``64``
  242. Query the 64bit registry. On ``32bit Windows``, returns always an empty
  243. string.
  244. ``32``
  245. Query the 32bit registry.
  246. ``64_32``
  247. For ``VALUE`` sub-option or default value, query the registry using view
  248. ``64``, and if the request failed, query the registry using view ``32``.
  249. For ``VALUE_NAMES`` and ``SUBKEYS`` sub-options, query both views (``64``
  250. and ``32``) and merge the results (sorted and duplicates removed).
  251. ``32_64``
  252. For ``VALUE`` sub-option or default value, query the registry using view
  253. ``32``, and if the request failed, query the registry using view ``64``.
  254. For ``VALUE_NAMES`` and ``SUBKEYS`` sub-options, query both views (``32``
  255. and ``64``) and merge the results (sorted and duplicates removed).
  256. ``HOST``
  257. Query the registry matching the architecture of the host: ``64`` on ``64bit
  258. Windows`` and ``32`` on ``32bit Windows``.
  259. ``TARGET``
  260. Query the registry matching the architecture specified by
  261. :variable:`CMAKE_SIZEOF_VOID_P` variable. If not defined, fallback to
  262. ``HOST`` view.
  263. ``BOTH``
  264. Query both views (``32`` and ``64``). The order depends of the following
  265. rules: If :variable:`CMAKE_SIZEOF_VOID_P` variable is defined. Use the
  266. following view depending of the content of this variable:
  267. * ``8``: ``64_32``
  268. * ``4``: ``32_64``
  269. If :variable:`CMAKE_SIZEOF_VOID_P` variable is not defined, rely on
  270. architecture of the host:
  271. * ``64bit``: ``64_32``
  272. * ``32bit``: ``32``
  273. ``SEPARATOR``
  274. Specify the separator character for ``REG_MULTI_SZ`` type. When not
  275. specified, the character ``\0`` is used.
  276. ``ERROR_VARIABLE <result>``
  277. Returns any error raised during query operation. In case of success, the
  278. variable holds an empty string.