How to do it

In our CMakeLists.txt, we first have to collect the configuration options, and can then substitute their values for the corresponding placeholders in print_info.c.in; we compile both the Fortran and C sources into one executable:

  1. We create a mixed Fortran-C project, as follows:
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)  project(recipe-01 LANGUAGES Fortran C)
  1. We obtain the username for the user configuring the project by using execute_process:
execute_process(  COMMAND    whoami  TIMEOUT    1  OUTPUT_VARIABLE    _user_name  OUTPUT_STRIP_TRAILING_WHITESPACE  )
  1. Using the cmake_host_system_information() function (which we already encountered in Chapter 2, Detecting the Environment, Recipe 5, Discovering the host processor instruction ...

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.