Skip to content

Commit e576dcf

Browse files
committed
Add cmake configs for ASAN, TSAN, UBSAN and gperftools CPU Profiler
1 parent 23e95f3 commit e576dcf

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
cmake_minimum_required(VERSION 3.15.5)
22
project(duplo)
3+
4+
if(CMAKE_CONFIGURATION_TYPES)
5+
list(APPEND CMAKE_CONFIGURATION_TYPES ASAN TSAN UBSAN PROFILE)
6+
list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
7+
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
8+
"Add the configurations that we need"
9+
FORCE)
10+
endif()
11+
12+
313
file(GLOB SOURCES src/*.cpp)
414

515
SET(DUPLO_VERSION "\"v1.0.1\"" CACHE STRING "Duplo version")
@@ -28,4 +38,16 @@ target_link_libraries(duplo PRIVATE nlohmann_json::nlohmann_json)
2838

2939
if(NOT MSVC)
3040
target_compile_options(duplo PRIVATE -Wall -Wextra -pedantic -Werror)
41+
# https://clang.llvm.org/docs/AddressSanitizer.html
42+
target_compile_options(duplo PRIVATE $<$<CONFIG:ASAN>:-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -O1>)
43+
target_link_options(duplo PRIVATE $<$<CONFIG:ASAN>:-fsanitize=address>)
44+
# https://clang.llvm.org/docs/ThreadSanitizer.html
45+
target_compile_options(duplo PRIVATE $<$<CONFIG:TSAN>:-fsanitize=thread -g -O1>)
46+
target_link_options(duplo PRIVATE $<$<CONFIG:TSAN>:-fsanitize=thread>)
47+
# https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
48+
target_compile_options(duplo PRIVATE $<$<CONFIG:UBSAN>:-fsanitize=undefined,bounds -g -O1>)
49+
target_link_options(duplo PRIVATE $<$<CONFIG:UBSAN>:-fsanitize=undefined,bounds>)
50+
# gperftools CPU Profiler https://github.com/gperftools/gperftools
51+
target_compile_options(duplo PRIVATE $<$<CONFIG:PROFILE>:-g -O1>)
52+
target_link_options(duplo PRIVATE $<$<CONFIG:PROFILE>:-lprofiler>)
3153
endif()

0 commit comments

Comments
 (0)