forked from Election-Tech-Initiative/electionguard-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.cmake
106 lines (86 loc) · 3.22 KB
/
tools.cmake
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
# ---- Options ----
option(CODE_COVERAGE "Enable code coverage" OFF)
option(USE_STATIC_ANALYSIS "use static analysis tools" OFF)
option(USE_DYNAMIC_ANALYSIS "use dynamic analysis tools" OFF)
option(USE_FORMATTING "use formatting tools" ON)
function(use_valgrind TARGET_NAME)
set(VALGRIND_LOG ${PROJECT_BINARY_DIR}/valgrind.log)
set(VALGRIND_SUPPRESS ${PROJECT_SOURCE_DIR}/valgrind-suppress.supp)
# --log-file=${VALGRIND_LOG}
set(VALGRIND_CMD ${VALGRIND_PROGRAM} --error-exitcode=1 --suppressions=${VALGRIND_SUPPRESS} ${ARGN})
add_custom_target(memcheck-${TARGET_NAME}
COMMAND
${VALGRIND_CMD} ./${TARGET_NAME}
)
endfunction()
# ---- Dependencies ----
include(cmake/CPM.cmake)
CPMAddPackage(
NAME StableCoder-cmake-scripts
GITHUB_REPOSITORY StableCoder/cmake-scripts
GIT_TAG 22.01
)
# ---- Enable Tools ----
# available values are: Address, Memory, MemoryWithOrigins, Undefined, Thread, Leak, 'Address;Undefined'
if (USE_SANITIZER)
message("++ Using Sanitizer: ${USE_SANITIZER}")
include(${StableCoder-cmake-scripts_SOURCE_DIR}/sanitizers.cmake)
endif()
if (CODE_COVERAGE)
message("++ Running with coverage")
include(${StableCoder-cmake-scripts_SOURCE_DIR}/code-coverage.cmake)
add_code_coverage()
endif()
if (USE_STATIC_ANALYSIS)
include(${StableCoder-cmake-scripts_SOURCE_DIR}/tools.cmake)
endif()
if (USE_STATIC_ANALYSIS)
message("++ Running with static analysis - clang_tidy")
set(CLANG_TIDY ON)
set(CLANG_TIDY_CHECKS *
# add checks to ignore here:
-cppcoreguidelines-avoid-magic-numbers
-cppcoreguidelines-avoid-non-const-global-variables
-cppcoreguidelines-init-variables
-cppcoreguidelines-pro-type-const-cast
-cppcoreguidelines-pro-type-reinterpret-cast
-fuchsia-default-arguments-calls
-fuchsia-default-arguments-declarations
-fuchsia-overloaded-operator
-google-readability-todo
-llvmlibc-restrict-system-libc-headers
-llvmlibc-implementation-in-namespace
-llvmlibc-callee-namespace
-misc-non-private-member-variables-in-classes
-modernize-use-trailing-return-type
-readability-avoid-const-params-in-decls
-readability-isolate-declaration
-readability-magic-numbers
-readability-non-const-parameter
)
string(REPLACE ";" "," CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS}")
clang_tidy(-checks=${CLANG_TIDY_CHECKS})
endif()
if (USE_STATIC_ANALYSIS)
message("++ Running with static analysis - cpp check")
set(CPPCHECK ON)
cppcheck()
endif()
if (USE_STATIC_ANALYSIS)
find_program(iwyu_path NAMES include-what-you-use iwyu)
if(iwyu_path)
message("++ Running with static analysis - IWYU")
set(IWYU ON)
include_what_you_use()
endif()
endif()
if (USE_DYNAMIC_ANALYSIS)
message("++ Running with dynamic analysis")
find_package(Valgrind)
if (VALGRIND_PROGRAM)
endif()
endif()
if (USE_FORMATTING)
message("++ Running with formatting")
include(${StableCoder-cmake-scripts_SOURCE_DIR}/formatting.cmake)
endif()