How to do it

Let us analyze in detail the contents of the various CMakeLists.txt files in this project:

  1. The root CMakeLists.txt file contains the familiar header:
# define minimum cmake versioncmake_minimum_required(VERSION 3.11 FATAL_ERROR)# project name and supported languageproject(recipe-05 LANGUAGES CXX)# require C++11set(CMAKE_CXX_STANDARD 11)set(CMAKE_CXX_EXTENSIONS OFF)set(CMAKE_CXX_STANDARD_REQUIRED ON)
  1. In this file, we also query the Python interpreter that will be used for testing:
find_package(PythonInterp REQUIRED)
  1. We then include the account subdirectory:
add_subdirectory(account)
  1. After that, we define the unit test:
# turn on testingenable_testing()# define testadd_test(  NAME    python_test  COMMAND ${CMAKE_COMMAND} -E ...

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.