-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.cmake
187 lines (155 loc) · 6.91 KB
/
build.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#
# This file is supposed to run in ctest script mode:
# ctest -S <path-to-this-file>/build.cmake
#
# You can set some command line variables to change the
# behaviour of this script:
#
# -DCTEST_TOOLCHAIN_FILE:STRING=<path-to-toolchain-file>
#
# -DCTEST_CONFIGURATION_TYPE:STRING=Debug|Release|MemorySanitizer|AddressSanitizer|LeakSanitizer|UndefinedBehaviorSanitizer|Valgrind|Coverage
# -DCTEST_MODEL:STRING=Experimental|Nightly|Continuous
# -DCTEST_DOCUMENTATION:BOOL=OFF|ON
# -DCTEST_BINARY_DIRECTORY:STRING=<path/to/builddir>
# -DCTEST_ANALYZER:STRING=scan-build-<version-number>|clang-tidy-<version-number>
# -DCTEST_CMAKE_GENERATOR:STRING=Ninja|Unix Makefiles|...
# -DCTEST_BUILD_SHARED_LIBS:BOOL=YES|NO
set(CTEST_USE_LAUNCHERS 1)
if(NOT DEFINED CTEST_MODEL)
set(CTEST_MODEL "Experimental")
endif()
if(DEFINED CTEST_TOOLCHAIN_FILE)
set(CONFIGURE_OPTIONS "-DCMAKE_TOOLCHAIN_FILE=${CTEST_TOOLCHAIN_FILE}")
endif()
if(DEFINED CTEST_BUILD_SHARED_LIBS)
set(CONFIGURE_OPTIONS "-DBUILD_SHARED_LIBS=${CTEST_BUILD_SHARED_LIBS}")
endif()
if(NOT DEFINED CTEST_DOCUMENTATION)
set(CTEST_DOCUMENTATION OFF)
endif()
if(NOT DEFINED CTEST_BINARY_DIRECTORY)
set(CTEST_BINARY_DIRECTORY "/tmp/cio/")
endif()
set(CTEST_SOURCE_DIRECTORY "${CTEST_SCRIPT_DIRECTORY}")
if(NOT DEFINED CTEST_CONFIGURATION_TYPE)
set(CIO_CTEST_CONFIGURATION_TYPE "Debug")
endif()
if(NOT CTEST_MODEL STREQUAL "Experimental")
ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY})
endif()
if(CTEST_CONFIGURATION_TYPE STREQUAL "AddressSanitizer")
set(CTEST_MEMORYCHECK_TYPE "AddressSanitizer")
set(CTEST_MEMORYCHECK_SANITIZER_OPTIONS "verbosity=1:exitcode=-1:check_initialization_order=true:detect_stack_use_after_return=true:strict_init_order=true:detect_invalid_pointer_pairs=10:strict_string_checks=true")
elseif(CTEST_CONFIGURATION_TYPE STREQUAL "MemorySanitizer")
set(CTEST_MEMORYCHECK_TYPE "MemorySanitizer")
set(CTEST_MEMORYCHECK_SANITIZER_OPTIONS "verbosity=1:exitcode=-1")
elseif(CTEST_CONFIGURATION_TYPE STREQUAL "LeakSanitizer")
set(CTEST_MEMORYCHECK_TYPE "LeakSanitizer")
set(CTEST_MEMORYCHECK_SANITIZER_OPTIONS "verbosity=1:exitcode=-1")
elseif(CTEST_CONFIGURATION_TYPE STREQUAL "UndefinedBehaviorSanitizer")
set(CTEST_MEMORYCHECK_TYPE "UndefinedBehaviorSanitizer")
set(CTEST_MEMORYCHECK_SANITIZER_OPTIONS "verbosity=1:exitcode=-1:print_stacktrace=1")
elseif(CTEST_CONFIGURATION_TYPE STREQUAL "Valgrind")
find_program(CTEST_MEMORYCHECK_COMMAND NAMES valgrind)
set(CTEST_MEMORYCHECK_TYPE Valgrind)
set(CTEST_MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --errors-for-leak-kinds=all --show-leak-kinds=all --leak-check=full --error-exitcode=1")
set(CTEST_CONFIGURATION_TYPE "Debug")
#set(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE ${CTEST_SOURCE_DIRECTORY}/tests/valgrind.supp)
endif()
if(DEFINED CTEST_ANALYZER)
string(REGEX MATCH "^scan-build|^clang-tidy" ANALYZER_TYPE ${CTEST_ANALYZER})
if(ANALYZER_TYPE STREQUAL "scan-build")
set(C_COMPILER_TYPE "clang")
set(CXX_COMPILER_TYPE "clang++")
string(REPLACE ${ANALYZER_TYPE} "" COMPILER_VERSION ${CTEST_ANALYZER})
set(ENV{CCC_CC} "${C_COMPILER_TYPE}${COMPILER_VERSION}")
set(ENV{CCC_CXX} "${CXX_COMPILER_TYPE}${COMPILER_VERSION}")
set(CTEST_CONFIGURE_COMMAND "${CTEST_ANALYZER} ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Coverage ${CTEST_SOURCE_DIRECTORY}")
set(ANALYZER_REPORT_DIR "${CTEST_BINARY_DIRECTORY}analyzer-scan/")
set(CTEST_BUILD_COMMAND "${CTEST_ANALYZER} --status-bugs -o ${ANALYZER_REPORT_DIR} ${CMAKE_COMMAND} --build ${CTEST_BINARY_DIRECTORY}")
set(IS_CLANG_STATIC_ANALYZER TRUE)
elseif(ANALYZER_TYPE STREQUAL "clang-tidy")
set(CONFIGURE_OPTIONS "${CONFIGURE_OPTIONS};-DCMAKE_C_CLANG_TIDY=${CTEST_ANALYZER}")
endif()
endif()
###########
cmake_host_system_information(RESULT FQDN QUERY FQDN)
set(CTEST_BUILD_NAME "${FQDN}")
set(CTEST_SITE "${FQDN}")
include(ProcessorCount)
ProcessorCount(NUMBER_OF_CORES)
if(NUMBER_OF_CORES EQUAL 0)
set(NUMBER_OF_CORES 1)
endif()
ctest_start(${CTEST_MODEL})
# Configure step
if(NOT DEFINED CTEST_CMAKE_GENERATOR)
set(CTEST_CMAKE_GENERATOR "Ninja")
endif()
set(CONFIGURE_OPTIONS "${CONFIGURE_OPTIONS}")
ctest_configure(OPTIONS "${CONFIGURE_OPTIONS}")
ctest_configure()
# Build step
if(CTEST_CMAKE_GENERATOR STREQUAL "Unix Makefiles")
#set(CTEST_BUILD_FLAGS "${CTEST_BUILD_FLAGS} VERBOSE=1")
set(CTEST_BUILD_FLAGS "${CTEST_BUILD_FLAGS} -j${NUMBER_OF_CORES}")
endif()
ctest_build(NUMBER_ERRORS CIO_NUMBER_OF_ERRORS NUMBER_WARNINGS CIO_NUMBER_OF_WARNING)
# Test/Coverage step
find_program(GCOVR_BIN gcovr)
if(CTEST_CONFIGURATION_TYPE STREQUAL "Coverage" AND GCOVR_BIN)
string(LENGTH ${CTEST_BINARY_DIRECTORY} CTEST_BINARY_DIRECTORY_LEN)
MATH(EXPR CTEST_BINARY_DIRECTORY_LEN "${CTEST_BINARY_DIRECTORY_LEN}-1")
string(SUBSTRING ${CTEST_BINARY_DIRECTORY} 0 ${CTEST_BINARY_DIRECTORY_LEN} CIO_OBJECT_DIRECTORY)
string(TIMESTAMP CIO_CTEST_TIMESTAMP UTC)
set(CIO_CTEST_COVERAGE_DIR "${CTEST_BINARY_DIRECTORY}cov-html/${CIO_CTEST_TIMESTAMP}")
set(CTEST_CUSTOM_POST_TEST
"cmake -E make_directory ${CIO_CTEST_COVERAGE_DIR}"
"${GCOVR_BIN} --html --html-details --html-title cio -f ${CTEST_SCRIPT_DIRECTORY}/lib/\\* -e ${CTEST_SCRIPT_DIRECTORY}/lib/cio/http-parser/\\* -e ${CTEST_SCRIPT_DIRECTORY}/lib/miniz/\\* -e ${CTEST_SCRIPT_DIRECTORY}/lib/cio/sha1/\\* --exclude-directories .\\*CompilerIdC\\* -r ${CTEST_SCRIPT_DIRECTORY} --object-directory=${CIO_OBJECT_DIRECTORY} -o ${CIO_CTEST_COVERAGE_DIR}/index.html")
set(CTEST_CUSTOM_COVERAGE_EXCLUDE
${CTEST_CUSTOM_COVERAGE_EXCLUDE}
".*/tests/.*"
".*/src/http-parser/.*"
".*/src/sha1/.*"
)
endif()
if(CIO_NUMBER_OF_ERRORS OR CIO_NUMBER_OF_WARNING)
if (IS_CLANG_STATIC_ANALYZER )
message(" -- Look into ${ANALYZER_REPORT_DIR} to see clang static analyzer report!")
endif()
message(FATAL_ERROR " -- Error or warning occured while building!")
return()
endif()
if(CTEST_DOCUMENTATION)
ctest_build(TARGET docs)
message(" -- Open ${CTEST_BINARY_DIRECTORY}src/docs/html/index.html to see generated documentation")
endif()
ctest_test(RETURN_VALUE TEST_RETURN PARALLEL_LEVEL 1)
if(TEST_RETURN)
message(FATAL_ERROR " -- Error while running tests!")
return()
endif()
if(CTEST_CONFIGURATION_TYPE STREQUAL "Coverage" AND GCOVR_BIN)
ctest_coverage()
message(" -- Open ${CIO_CTEST_COVERAGE_DIR}/index.html to see collected coverage")
endif()
if(DEFINED CTEST_MEMORYCHECK_TYPE)
ctest_memcheck(RETURN_VALUE MEMCHECK_RETURN PARALLEL_LEVEL ${NUMBER_OF_CORES})
if(MEMCHECK_RETURN)
message(FATAL_ERROR " -- Error while running memcheck!")
return()
endif()
endif()
# include(CTestCoverageCollectGCOV)
# ctest_coverage_collect_gcov(
# TARBALL gcov.tar
# SOURCE ${CTEST_SOURCE_DIRECTORY}
# BUILD ${CTEST_BINARY_DIRECTORY}
# GCOV_COMMAND ${CTEST_COVERAGE_COMMAND}
# )
# if(EXISTS "${CTEST_BINARY_DIRECTORY}/gcov.tar")
# ctest_submit(CDASH_UPLOAD "${CTEST_BINARY_DIRECTORY}/gcov.tar"
# CDASH_UPLOAD_TYPE GcovTar)
# endif()
#
# ctest_submit()