Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
114 lines (103 loc) · 5.19 KB
/
Copy pathCMakeLists.txt
File metadata and controls
114 lines (103 loc) · 5.19 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# SPDX-License-Identifier: MIT
# Copyright (C) 2026 PinPoint Golf
cmake_minimum_required(VERSION 3.16)
project(libbuffer
VERSION 0.1.2
DESCRIPTION "Lock-free multi-source capture buffer: per-source seqlock rings merged onto one timeline"
LANGUAGES CXX)
# ---------------------------------------------------------------------------
# Top level, or embedded?
#
# ⚠ THE CACHE IS NOT DIRECTORY-SCOPED: one cache per build tree, so anything below that could reach into a
# consumer's build is gated on this. Embedding libbuffer must change nothing about the consumer: not its build type,
# its test registry or its install manifest. Spelled as a CMAKE_SOURCE_DIR comparison rather than
# PROJECT_IS_TOP_LEVEL because that variable is CMake 3.21+ and this project promises 3.16.
# ---------------------------------------------------------------------------
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(LIBBUFFER_IS_TOP_LEVEL ON)
else()
set(LIBBUFFER_IS_TOP_LEVEL OFF)
endif()
option(LIBBUFFER_BUILD_TESTS "Build the automated test suite and the latency benchmark" ${LIBBUFFER_IS_TOP_LEVEL})
option(LIBBUFFER_ENABLE_ASAN "Build with AddressSanitizer" OFF)
option(LIBBUFFER_ENABLE_UBSAN "Build with UndefinedBehaviorSanitizer" OFF)
option(LIBBUFFER_ENABLE_TSAN "Build with ThreadSanitizer" OFF)
option(LIBBUFFER_ENABLE_COVERAGE "Build with gcov coverage instrumentation" OFF)
# ⚠ -Werror is a CI gate, not a property of the code: a consumer's newer compiler must not break their build over
# a warning they cannot fix.
option(LIBBUFFER_WERROR "Treat warnings as errors" ${LIBBUFFER_IS_TOP_LEVEL})
option(LIBBUFFER_INSTALL "Generate the install rules" ${LIBBUFFER_IS_TOP_LEVEL})
# Directory-scoped, so these reach no further than this subtree.
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(LIBBUFFER_IS_TOP_LEVEL AND NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
endif()
find_package(Threads REQUIRED)
# ---------------------------------------------------------------------------
# Warning and instrumentation flags, behind an INTERFACE target so nothing leaks to a consumer. The library and its
# tests link it, so a sanitizer instruments both (a consumer that instruments its own code turns the same option on).
# ---------------------------------------------------------------------------
add_library(libbuffer_build_flags INTERFACE)
if(MSVC)
target_compile_options(libbuffer_build_flags INTERFACE /W4 /permissive-)
if(LIBBUFFER_WERROR)
target_compile_options(libbuffer_build_flags INTERFACE /WX)
endif()
else()
target_compile_options(libbuffer_build_flags INTERFACE -Wall -Wextra -Wpedantic)
if(LIBBUFFER_WERROR)
target_compile_options(libbuffer_build_flags INTERFACE -Werror)
endif()
if(LIBBUFFER_ENABLE_ASAN)
target_compile_options(libbuffer_build_flags INTERFACE -fsanitize=address -fno-omit-frame-pointer)
target_link_options(libbuffer_build_flags INTERFACE -fsanitize=address)
endif()
if(LIBBUFFER_ENABLE_UBSAN)
target_compile_options(libbuffer_build_flags INTERFACE -fsanitize=undefined -fno-sanitize-recover=all)
target_link_options(libbuffer_build_flags INTERFACE -fsanitize=undefined)
endif()
# ⚠ ThreadSanitizer cannot be combined with AddressSanitizer: turn on one or the other.
if(LIBBUFFER_ENABLE_TSAN)
target_compile_options(libbuffer_build_flags INTERFACE -fsanitize=thread)
target_link_options(libbuffer_build_flags INTERFACE -fsanitize=thread)
endif()
if(LIBBUFFER_ENABLE_COVERAGE)
target_compile_options(libbuffer_build_flags INTERFACE --coverage -O0 -g)
target_link_options(libbuffer_build_flags INTERFACE --coverage)
endif()
endif()
add_library(libbuffer STATIC
src/source_ring.cpp
src/timeline_index.cpp
src/wait_flag.cpp
src/thread_policy.cpp
src/event_buffer.cpp
src/capture_window.cpp
src/device_clock_mapper.cpp
)
add_library(libbuffer::libbuffer ALIAS libbuffer)
target_include_directories(libbuffer PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_features(libbuffer PUBLIC cxx_std_20)
target_link_libraries(libbuffer
PUBLIC Threads::Threads
PRIVATE $<BUILD_INTERFACE:libbuffer_build_flags>)
if(WIN32)
# The merger raises the timer resolution while capturing (timeBeginPeriod).
target_link_libraries(libbuffer PRIVATE winmm)
endif()
set_target_properties(libbuffer PROPERTIES POSITION_INDEPENDENT_CODE ON)
if(LIBBUFFER_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
if(LIBBUFFER_INSTALL)
include(GNUInstallDirs)
install(TARGETS libbuffer EXPORT libbuffer-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY include/libbuffer DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT libbuffer-targets NAMESPACE libbuffer:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libbuffer)
endif()