How to do it

The corresponding CMakeLists.txt contains the following building blocks:

  1. We define the minimum CMake version, the project name and supported languages:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(recipe-04 LANGUAGES CXX C Fortran)
  1. We require the C++11 standard:
set(CMAKE_CXX_STANDARD 11)set(CMAKE_CXX_EXTENSIONS OFF)set(CMAKE_CXX_STANDARD_REQUIRED ON)
  1. Further, we verify whether Fortran and C/C++ compilers work together and generate the header file which will take care of name mangling. Both functions are provided by the FortranCInterface module:
include(FortranCInterface)FortranCInterface_VERIFY(CXX)FortranCInterface_HEADER( fc_mangle.h MACRO_NAMESPACE "FC_" SYMBOLS DSCAL DGESV )
  1. We then ask CMake to find BLAS ...

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.