How to do it

We will begin with the root CMakeLists.txt:

  1. We declare a C++11 project as usual:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(recipe-02 LANGUAGES CXX)set(CMAKE_CXX_STANDARD 11)set(CMAKE_CXX_EXTENSIONS OFF)set(CMAKE_CXX_STANDARD_REQUIRED ON)
  1. We set the EP_BASE directory property:
set_property(DIRECTORY PROPERTY EP_BASE ${CMAKE_BINARY_DIR}/subprojects)
  1. We set the STAGED_INSTALL_PREFIX variable. This directory will be used to install the dependencies within our build tree:
set(STAGED_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/stage)message(STATUS "${PROJECT_NAME} staged install: ${STAGED_INSTALL_PREFIX}")
  1. Our project needs the filesystem and system components of the Boost libraries. We declare a list variable to hold this ...

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.