How to do it

Let us first look at CMakeLists.txt in the root folder:

  1. We declare a C++11 project, with a minimum required CMake version:
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 set the EP_BASE directory property for the current and any underlying directories. This will be discussed shortly:
set_property(DIRECTORY PROPERTY EP_BASE ${CMAKE_BINARY_DIR}/subprojects)
  1. We include the ExternalProject.cmake standard module. This module provides the ExternalProject_Add function:
include(ExternalProject)
  1. The source code for our "Hello, World" example is added as an external project by invoking the ExternalProject_Add ...

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.