How to do it

Let us have a look at our CMakeLists.txt:

  1. We first declare a Fortran project:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(recipe-05 LANGUAGES Fortran)
  1. This example depends on the Python interpreter so that we can execute the helper scripts in a portable fashion:
find_package(PythonInterp REQUIRED)
  1. In this example, we default to the "Release" build type so that CMake adds optimization flags so that we have something to print later:
if(NOT CMAKE_BUILD_TYPE)  set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)endif()
  1. Now, we define the executable target:
add_executable(example "")target_sources(example  PRIVATE    example.f90  )
  1. We then define a custom command to print the link line before the example target ...

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.