cmake_host_system_information.rst 12 KB

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