How to do it

To use the Catch2 library, we will modify CMakeLists.txt from the previous recipe, to perform the following steps:

  1. We can keep most of CMakeLists.txt unchanged:
# set minimum cmake versioncmake_minimum_required(VERSION 3.5 FATAL_ERROR)# project name and languageproject(recipe-02 LANGUAGES CXX)# require C++11set(CMAKE_CXX_STANDARD 11)set(CMAKE_CXX_EXTENSIONS OFF)set(CMAKE_CXX_STANDARD_REQUIRED ON)# example libraryadd_library(sum_integers sum_integers.cpp)# main codeadd_executable(sum_up main.cpp)target_link_libraries(sum_up sum_integers)# testing binaryadd_executable(cpp_test test.cpp)target_link_libraries(cpp_test sum_integers)
  1. The only change, with respect to the previous recipe, is to remove all of the tests except for one, ...

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.