cmake_host_system_information.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. ``MSYSTEM_PREFIX``
  93. .. versionadded:: 3.28
  94. Available only on Windows hosts. In a MSYS or MinGW development
  95. environment that sets the ``MSYSTEM`` environment variable, this
  96. is its installation prefix. Otherwise, this is the empty string.
  97. ``DISTRIB_INFO``
  98. .. versionadded:: 3.22
  99. Read :file:`/etc/os-release` file and define the given ``<variable>``
  100. into a list of read variables
  101. ``DISTRIB_<name>``
  102. .. versionadded:: 3.22
  103. Get the ``<name>`` variable (see `man 5 os-release`_) if it exists in the
  104. :file:`/etc/os-release` file
  105. Example:
  106. .. code-block:: cmake
  107. cmake_host_system_information(RESULT PRETTY_NAME QUERY DISTRIB_PRETTY_NAME)
  108. message(STATUS "${PRETTY_NAME}")
  109. cmake_host_system_information(RESULT DISTRO QUERY DISTRIB_INFO)
  110. foreach(VAR IN LISTS DISTRO)
  111. message(STATUS "${VAR}=`${${VAR}}`")
  112. endforeach()
  113. Output::
  114. -- Ubuntu 20.04.2 LTS
  115. -- DISTRO_BUG_REPORT_URL=`https://bugs.launchpad.net/ubuntu/`
  116. -- DISTRO_HOME_URL=`https://www.ubuntu.com/`
  117. -- DISTRO_ID=`ubuntu`
  118. -- DISTRO_ID_LIKE=`debian`
  119. -- DISTRO_NAME=`Ubuntu`
  120. -- DISTRO_PRETTY_NAME=`Ubuntu 20.04.2 LTS`
  121. -- DISTRO_PRIVACY_POLICY_URL=`https://www.ubuntu.com/legal/terms-and-policies/privacy-policy`
  122. -- DISTRO_SUPPORT_URL=`https://help.ubuntu.com/`
  123. -- DISTRO_UBUNTU_CODENAME=`focal`
  124. -- DISTRO_VERSION=`20.04.2 LTS (Focal Fossa)`
  125. -- DISTRO_VERSION_CODENAME=`focal`
  126. -- DISTRO_VERSION_ID=`20.04`
  127. If :file:`/etc/os-release` file is not found, the command tries to gather OS
  128. identification via fallback scripts. The fallback script can use `various
  129. distribution-specific files`_ to collect OS identification data and map it
  130. into `man 5 os-release`_ variables.
  131. Fallback Interface Variables
  132. """"""""""""""""""""""""""""
  133. .. variable:: CMAKE_GET_OS_RELEASE_FALLBACK_SCRIPTS
  134. In addition to the scripts shipped with CMake, a user may append full
  135. paths to his script(s) to the this list. The script filename has the
  136. following format: ``NNN-<name>.cmake``, where ``NNN`` is three digits
  137. used to apply collected scripts in a specific order.
  138. .. variable:: CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_<varname>
  139. Variables collected by the user provided fallback script
  140. ought to be assigned to CMake variables using this naming
  141. convention. Example, the ``ID`` variable from the manual becomes
  142. ``CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_ID``.
  143. .. variable:: CMAKE_GET_OS_RELEASE_FALLBACK_RESULT
  144. The fallback script ought to store names of all assigned
  145. ``CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_<varname>`` variables in this list.
  146. Example:
  147. .. code-block:: cmake
  148. # Try to detect some old distribution
  149. # See also
  150. # - http://linuxmafia.com/faq/Admin/release-files.html
  151. #
  152. if(NOT EXISTS "${CMAKE_SYSROOT}/etc/foobar-release")
  153. return()
  154. endif()
  155. # Get the first string only
  156. file(
  157. STRINGS "${CMAKE_SYSROOT}/etc/foobar-release" CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT
  158. LIMIT_COUNT 1
  159. )
  160. #
  161. # Example:
  162. #
  163. # Foobar distribution release 1.2.3 (server)
  164. #
  165. if(CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT MATCHES "Foobar distribution release ([0-9\.]+) .*")
  166. set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_NAME Foobar)
  167. set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_PRETTY_NAME "${CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT}")
  168. set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_ID foobar)
  169. set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION ${CMAKE_MATCH_1})
  170. set(CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION_ID ${CMAKE_MATCH_1})
  171. list(
  172. APPEND CMAKE_GET_OS_RELEASE_FALLBACK_RESULT
  173. CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_NAME
  174. CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_PRETTY_NAME
  175. CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_ID
  176. CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION
  177. CMAKE_GET_OS_RELEASE_FALLBACK_RESULT_VERSION_ID
  178. )
  179. endif()
  180. unset(CMAKE_GET_OS_RELEASE_FALLBACK_CONTENT)
  181. .. rubric:: Footnotes
  182. .. [#mebibytes] One MiB (mebibyte) is equal to 1024x1024 bytes.
  183. .. _man 5 os-release: https://www.freedesktop.org/software/systemd/man/os-release.html
  184. .. _various distribution-specific files: http://linuxmafia.com/faq/Admin/release-files.html
  185. .. _Query Windows registry:
  186. Query Windows registry
  187. ^^^^^^^^^^^^^^^^^^^^^^
  188. .. versionadded:: 3.24
  189. ::
  190. cmake_host_system_information(RESULT <variable>
  191. QUERY WINDOWS_REGISTRY <key> [VALUE_NAMES|SUBKEYS|VALUE <name>]
  192. [VIEW (64|32|64_32|32_64|HOST|TARGET|BOTH)]
  193. [SEPARATOR <separator>]
  194. [ERROR_VARIABLE <result>])
  195. Performs query operations on local computer registry subkey. Returns a list of
  196. subkeys or value names that are located under the specified subkey in the
  197. registry or the data of the specified value name. The result of the queried
  198. entity is stored in ``<variable>``.
  199. .. note::
  200. Querying registry for any other platforms than ``Windows``, including
  201. ``CYGWIN``, will always returns an empty string and sets an error message in
  202. the variable specified with sub-option ``ERROR_VARIABLE``.
  203. ``<key>`` specify the full path of a subkey on the local computer. The
  204. ``<key>`` must include a valid root key. Valid root keys for the local computer
  205. are:
  206. * ``HKLM`` or ``HKEY_LOCAL_MACHINE``
  207. * ``HKCU`` or ``HKEY_CURRENT_USER``
  208. * ``HKCR`` or ``HKEY_CLASSES_ROOT``
  209. * ``HKU`` or ``HKEY_USERS``
  210. * ``HKCC`` or ``HKEY_CURRENT_CONFIG``
  211. And, optionally, the path to a subkey under the specified root key. The path
  212. separator can be the slash or the backslash. ``<key>`` is not case sensitive.
  213. For example:
  214. .. code-block:: cmake
  215. cmake_host_system_information(RESULT result QUERY WINDOWS_REGISTRY "HKLM")
  216. cmake_host_system_information(RESULT result QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Kitware")
  217. cmake_host_system_information(RESULT result QUERY WINDOWS_REGISTRY "HKCU\\SOFTWARE\\Kitware")
  218. ``VALUE_NAMES``
  219. Request the list of value names defined under ``<key>``. If a default value
  220. is defined, it will be identified with the special name ``(default)``.
  221. ``SUBKEYS``
  222. Request the list of subkeys defined under ``<key>``.
  223. ``VALUE <name>``
  224. Request the data stored in value named ``<name>``. If ``VALUE`` is not
  225. specified or argument is the special name ``(default)``, the content of the
  226. default value, if any, will be returned.
  227. .. code-block:: cmake
  228. # query default value for HKLM/SOFTWARE/Kitware key
  229. cmake_host_system_information(RESULT result
  230. QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Kitware")
  231. # query default value for HKLM/SOFTWARE/Kitware key using special value name
  232. cmake_host_system_information(RESULT result
  233. QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Kitware"
  234. VALUE "(default)")
  235. Supported types are:
  236. * ``REG_SZ``.
  237. * ``REG_EXPAND_SZ``. The returned data is expanded.
  238. * ``REG_MULTI_SZ``. The returned is expressed as a CMake list. See also
  239. ``SEPARATOR`` sub-option.
  240. * ``REG_DWORD``.
  241. * ``REG_QWORD``.
  242. For all other types, an empty string is returned.
  243. ``VIEW``
  244. Specify which registry views must be queried. When not specified, ``BOTH``
  245. view is used.
  246. ``64``
  247. Query the 64bit registry. On ``32bit Windows``, returns always an empty
  248. string.
  249. ``32``
  250. Query the 32bit registry.
  251. ``64_32``
  252. For ``VALUE`` sub-option or default value, query the registry using view
  253. ``64``, and if the request failed, query the registry using view ``32``.
  254. For ``VALUE_NAMES`` and ``SUBKEYS`` sub-options, query both views (``64``
  255. and ``32``) and merge the results (sorted and duplicates removed).
  256. ``32_64``
  257. For ``VALUE`` sub-option or default value, query the registry using view
  258. ``32``, and if the request failed, query the registry using view ``64``.
  259. For ``VALUE_NAMES`` and ``SUBKEYS`` sub-options, query both views (``32``
  260. and ``64``) and merge the results (sorted and duplicates removed).
  261. ``HOST``
  262. Query the registry matching the architecture of the host: ``64`` on ``64bit
  263. Windows`` and ``32`` on ``32bit Windows``.
  264. ``TARGET``
  265. Query the registry matching the architecture specified by
  266. :variable:`CMAKE_SIZEOF_VOID_P` variable. If not defined, fallback to
  267. ``HOST`` view.
  268. ``BOTH``
  269. Query both views (``32`` and ``64``). The order depends of the following
  270. rules: If :variable:`CMAKE_SIZEOF_VOID_P` variable is defined. Use the
  271. following view depending of the content of this variable:
  272. * ``8``: ``64_32``
  273. * ``4``: ``32_64``
  274. If :variable:`CMAKE_SIZEOF_VOID_P` variable is not defined, rely on
  275. architecture of the host:
  276. * ``64bit``: ``64_32``
  277. * ``32bit``: ``32``
  278. ``SEPARATOR``
  279. Specify the separator character for ``REG_MULTI_SZ`` type. When not
  280. specified, the character ``\0`` is used.
  281. ``ERROR_VARIABLE <result>``
  282. Returns any error raised during query operation. In case of success, the
  283. variable holds an empty string.