Let us go through the necessary steps in detail, as follows:
- 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)
- 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 )
- Then, we offer the option and code to compile and link with support for the ThreadSanitizer:
option(ENABLE_TSAN "Enable ...