How to do it

Let us follow the required steps:

  1. The top-level CMakeLists.txt defines the minimum CMake version, project name, and supported language, and requires the C++11 standard:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)  project(recipe-01 LANGUAGES CXX)set(CMAKE_CXX_STANDARD 11)set(CMAKE_CXX_EXTENSIONS OFF)set(CMAKE_CXX_STANDARD_REQUIRED ON)
  1. We further define binary and library paths according to GNU standards:
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})
  1. And finally, we use add_subdirectory calls to structure our ...

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.