-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
65 lines (51 loc) · 2.39 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.12)
# ------------------------------------------------------------------------------------------------
project(ut_exe CXX) # as early as possible, eg must before CMAKE_CXX_FLAGS
if(ci STREQUAL "cov")
message("!!! coverage & valgrind(only need -g -fno-omit-frame-pointer)")
set(CMAKE_CXX_STANDARD 20) # if gtest fix bug, try c++20/23 to see cov rate inc or not
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") # gcov req (=-fprofile-arcs -ftest-coverage & -lgcov)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") # gcov req
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0") # gcov req
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-abs-path") # gcc 8
add_compile_definitions(SMART_LOG)
add_compile_definitions(WITH_HID_LOG) # more info to debug ci
elseif(ci STREQUAL "asan")
set(CMAKE_CXX_STANDARD 17) # low c++ version for wide usage; 17 since "if constexpr()"
message("!!! asan+lsan+ubsan for: use-after-free, double-free, out-of-bound, leak, undef behavior")
add_compile_options(-g -fno-omit-frame-pointer)
add_compile_options(-fsanitize=address,undefined)
add_link_options (-fsanitize=address,undefined)
elseif(ci STREQUAL "tsan") # asan/lsan/msan cover by valgrind(memcheck)
set(CMAKE_CXX_STANDARD 17)
message("!!! SANITIZE for: thread")
add_compile_options(-g -fno-omit-frame-pointer)
add_compile_options(-fsanitize=thread)
add_link_options (-fsanitize=thread)
else()
message("!!! UT only - no cov, no SANITIZE check etc")
set(CMAKE_CXX_STANDARD 17)
add_compile_options(-O1) # fastest build+ut (1-cpp-change=5s, vs 45s of -g)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") # inc branch coverage
add_executable(ut_exe)
set(gtest_dir ${CMAKE_CURRENT_SOURCE_DIR}/../googletest)
add_subdirectory(${gtest_dir}
${CMAKE_BINARY_DIR}/googletest) # must specify where to build since gtest out domino root
add_subdirectory(src)
add_subdirectory(ut)
target_link_libraries(ut_exe PRIVATE
lib_domino
lib_ut
gtest_main
)
# make run-ut_exe
add_custom_target(run
COMMAND ./ut_exe --gtest_brief=0
DEPENDS ut_exe
)
# simplify "make help"
set(CMAKE_SKIP_PREPROCESSED_SOURCE_RULES true)
set(CMAKE_SKIP_ASSEMBLY_SOURCE_RULES true)