How to do it

We shall start out with the C++ example before moving on to the Fortran example:

  1. In the CMakeLists.txt file, we define the now familiar minimum version, project name, and supported language:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(recipe-03 LANGUAGES CXX)
  1. We then define the executable target and its corresponding source file:
add_executable(hello-world hello-world.cpp)
  1. Then we let the preprocessor know about the compiler name and vendor by defining the following target compile definitions:
target_compile_definitions(hello-world PUBLIC "COMPILER_NAME=\"${CMAKE_CXX_COMPILER_ID}\"")if(CMAKE_CXX_COMPILER_ID MATCHES Intel)    target_compile_definitions(hello-world PUBLIC "IS_INTEL_CXX_COMPILER")endif()if(CMAKE_CXX_COMPILER_ID ...

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.