How to do it

The following is a breakdown of the commands in CMakeLists.txt:

  1. First, we need to define the project and detect the Python interpreter, as follows:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)  project(recipe-03 LANGUAGES CXX)set(CMAKE_CXX_STANDARD 11)set(CMAKE_CXX_EXTENSIONS OFF)set(CMAKE_CXX_STANDARD_REQUIRED ON)find_package(PythonInterp QUIET REQUIRED)
  1. We decided to place the to-be-generated code under ${CMAKE_CURRENT_BINARY_DIR}/generated, and we need to instruct CMake to create this directory:
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated)
  1. The Python script expects an upper bound for the prime numbers, and, with the following command, we can set a default:
set(MAX_NUMBER "100" CACHE STRING "Upper bound ...

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.