How to do it

Let us go through the necessary steps in detail, as follows:

  1. The file CMakeLists.txt starts by defining a minimum supported version, project name, supported languages, and, in this case, a requirement of the C++11 standard:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(recipe-04 LANGUAGES CXX)set(CMAKE_CXX_STANDARD 11)set(CMAKE_CXX_EXTENSIONS OFF)set(CMAKE_CXX_STANDARD_REQUIRED ON)
  1. Next, we locate the Threads library, define the executable, and link it against the Threads library:
find_package(Threads REQUIRED)add_executable(example example.cpp)target_link_libraries(example  PUBLIC    Threads::Threads  )
  1. Then, we offer the option and code to compile and link with support for the ThreadSanitizer:
option(ENABLE_TSAN "Enable ...

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.