How to do it

We will use CMake to fill the definitions in config.h with sensible values for our platform and to compile our sample source file into an executable:

  1. First, we define the minimum CMake version, project name, and project language:
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)project(recipe-05 CXX)
  1. We then define the target executable, its source file, and include directories:
add_executable(processor-info "")target_sources(processor-info  PRIVATE    processor-info.cpp  )target_include_directories(processor-info  PRIVATE    ${PROJECT_BINARY_DIR}  )
  1. We then go on to query the host system information for a number of keys:
foreach(key  IN ITEMS    NUMBER_OF_LOGICAL_CORES    NUMBER_OF_PHYSICAL_CORES    TOTAL_VIRTUAL_MEMORY AVAILABLE_VIRTUAL_MEMORY ...

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.