Cmake命令之cmake_host_system_inform

2022-04-08  本文已影响0人  Domibaba

一、命令格式

cmake_host_system_information(RESULT <variable> QUERY <key> ...)

  查询CMake运行环境的系统信息,<key>指定待查询的信息,可以有多个,查询结果存放在<variable>中。

  <key>可以是主机名称、内存信息、CPU信息等等,<key>的所有取值可以参考本文的第三章节更多细节

二、示例

# CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(host_info)

cmake_host_system_information(RESULT var QUERY HOSTNAME)
message("hostname: ${var}")

cmake_host_system_information(RESULT var QUERY NUMBER_OF_LOGICAL_CORES NUMBER_OF_PHYSICAL_CORES)
message("cores: ${var}")

cmake_host_system_information(RESULT var QUERY TOTAL_VIRTUAL_MEMORY TOTAL_PHYSICAL_MEMORY)
message("memory(MB): ${var}")

cmake_host_system_information(RESULT var QUERY PROCESSOR_NAME)
message("processor name: ${var}")

cmake_host_system_information(RESULT var QUERY OS_NAME OS_RELEASE OS_VERSION OS_PLATFORM)
message("os information: ${var}")

  我的是macOS,执行结果如下:

hostname: myBookAir
cores: 4;2
memory(MB): 5120;4096
processor name: Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz
os information: Mac OS X;10.13.6;17G14019;x86_64

三、更多细节

  <key>的取值如下:


附录:参考文档

  1. https://cmake.org/cmake/help/latest/command/cmake_host_system_information.html
上一篇下一篇

猜你喜欢

热点阅读