How to do it

We will now discuss the corresponding CMake structure:

  1. The top-level CMakeLists.txt is similar to Recipe 7; we only exchange CXX for Fortran and remove the C++11 requirement:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(recipe-09 LANGUAGES Fortran)include(GNUInstallDirs)set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY  ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})set(CMAKE_LIBRARY_OUTPUT_DIRECTORY  ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})set(CMAKE_RUNTIME_OUTPUT_DIRECTORY  ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})# defines targets and sourcesadd_subdirectory(src)# contains an "external" library we will link toadd_subdirectory(external)# enable testing and define testsenable_testing()add_subdirectory(tests)
  1. Targets and sources ...

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.