Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
49 lines (42 loc) · 1.73 KB
/
Copy pathCMakeLists.txt
File metadata and controls
49 lines (42 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
cmake_minimum_required(VERSION 3.14)
project(cpp14-thread-toolkit VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
option(THREADKIT_BUILD_TESTS "Build the GoogleTest suite" ON)
option(THREADKIT_TSAN "Build with ThreadSanitizer" OFF)
find_package(Threads REQUIRED)
add_library(threadkit STATIC src/thread.cpp)
add_library(threadkit::threadkit ALIAS threadkit)
target_include_directories(threadkit PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_link_libraries(threadkit PUBLIC Threads::Threads)
target_compile_options(threadkit PRIVATE -Wall -Wextra -Wpedantic)
if(THREADKIT_TSAN)
add_compile_options(-fsanitize=thread -g -O1)
add_link_options(-fsanitize=thread)
endif()
install(DIRECTORY include/ DESTINATION include)
install(TARGETS threadkit ARCHIVE DESTINATION lib)
if(THREADKIT_BUILD_TESTS)
enable_testing()
find_package(GTest REQUIRED)
add_executable(threadkit_tests
tests/locks_test.cpp
tests/pc_sem_test.cpp
tests/thread_test.cpp
tests/thread_registry_test.cpp
tests/pc_queue_test.cpp
tests/circ_buff_test.cpp)
target_link_libraries(threadkit_tests PRIVATE threadkit GTest::gtest GTest::gtest_main)
target_compile_options(threadkit_tests PRIVATE -Wall -Wextra)
if(THREADKIT_TSAN)
# gtest_discover_tests runs the binary at build time; under TSAN on
# kernels with 32-bit mmap randomisation that needs `setarch -R`.
add_test(NAME threadkit_tests COMMAND setarch ${CMAKE_SYSTEM_PROCESSOR} -R $<TARGET_FILE:threadkit_tests>)
else()
include(GoogleTest)
gtest_discover_tests(threadkit_tests)
endif()
endif()