How to do it

This project mixes C++, which is the language of the main program, Fortran, because this is the language the libraries are written in, and C, which is needed to wrap the Fortran subroutines. In the root CMakeLists.txt file, we need to do the following:

  1. Declare the project as mixed-language and set the C++ standard:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(recipe-02 LANGUAGES CXX C Fortran)set(CMAKE_CXX_STANDARD 11)set(CMAKE_CXX_EXTENSIONS OFF)set(CMAKE_CXX_STANDARD_REQUIRED ON)
  1. We use the GNUInstallDirs module to direct CMake to save static and shared libraries and the executable into standard directories. We also instruct CMake to place Fortran compiled module files under modules:
include(GNUInstallDirs)set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ...

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.