cmake_host_system_information.rst 6.3 KB

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