]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/prometheus-cpp/3rdparty/civetweb/unittest/CMakeLists.txt
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / third_party / prometheus-cpp / 3rdparty / civetweb / unittest / CMakeLists.txt
1 # Determine if we should print to the output
2 if (CIVETWEB_ENABLE_THIRD_PARTY_OUTPUT)
3 set(THIRD_PARTY_LOGGING 0)
4 else()
5 set(THIRD_PARTY_LOGGING 1)
6 endif()
7
8 # We use the check unit testing framework for our C unit tests
9 include(ExternalProject)
10 if(NOT WIN32)
11 # Apply the patch to check to fix CMake building on OS X
12 set(CHECK_PATCH_COMMAND patch
13 ${CIVETWEB_THIRD_PARTY_DIR}/src/check-unit-test-framework/src/check_run.c
14 ${CMAKE_SOURCE_DIR}/cmake/check/check_run.patch
15 )
16 else()
17 set(CHECK_PATCH_COMMAND "")
18 endif()
19
20 IF (DEFINED ENV{CHECK_URL})
21 SET (CHECK_URL $ENV{CHECK_URL})
22 ELSE()
23 SET (CHECK_URL "https://github.com/civetweb/check/archive/master.zip")
24 ENDIF()
25
26
27 ExternalProject_Add(check-unit-test-framework
28 DEPENDS civetweb-c-library
29
30 ## Use an official, released check version:
31 # URL "https://codeload.github.com/libcheck/check/zip/${CIVETWEB_CHECK_VERSION}"
32 # DOWNLOAD_NAME "${CIVETWEB_CHECK_VERSION}.zip"
33 # URL_MD5 ${CIVETWEB_CHECK_MD5_HASH}
34
35 ## Use a civetweb specific patched version
36
37 URL ${CHECK_URL}
38 DOWNLOAD_NAME "master.zip"
39
40 PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
41 BUILD_IN_SOURCE 1
42 PATCH_COMMAND ${CHECK_PATCH_COMMAND}
43 CMAKE_ARGS
44 "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
45 "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
46 "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
47 LOG_DOWNLOAD ${THIRD_PARTY_LOGGING}
48 LOG_UPDATE ${THIRD_PARTY_LOGGING}
49 LOG_CONFIGURE ${THIRD_PARTY_LOGGING}
50 LOG_BUILD ${THIRD_PARTY_LOGGING}
51 LOG_TEST ${THIRD_PARTY_LOGGING}
52 LOG_INSTALL ${THIRD_PARTY_LOGGING})
53
54 ExternalProject_Get_Property(check-unit-test-framework INSTALL_DIR)
55 set(CHECK_INSTALL_DIR ${INSTALL_DIR})
56 unset(INSTALL_DIR)
57 link_directories("${CHECK_INSTALL_DIR}/lib")
58 include_directories("${CHECK_INSTALL_DIR}/include")
59 if ((WIN32 AND MINGW) OR APPLE)
60 set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/libcheck.a")
61 set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/libcompat.a")
62 elseif (WIN32)
63 set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/check.lib")
64 set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/compat.lib")
65 else()
66 set(CHECK_LIBRARIES "${CHECK_INSTALL_DIR}/lib/libcheck.a")
67 endif()
68 find_package(LibM)
69 if (LIBM_FOUND)
70 set(CHECK_LIBRARIES "${CHECK_LIBRARIES};LIBM::LIBM")
71 endif()
72 find_package(LibRt)
73 if (LIBRT_FOUND)
74 set(CHECK_LIBRARIES "${CHECK_LIBRARIES};LIBRT::LIBRT")
75 endif()
76
77 # Build the C unit tests
78 add_library(shared-c-unit-tests STATIC shared.c)
79 target_include_directories(
80 shared-c-unit-tests PUBLIC
81 ${PROJECT_SOURCE_DIR}/include)
82
83 add_library(public-func-c-unit-tests STATIC public_func.c)
84 if (BUILD_SHARED_LIBS)
85 target_compile_definitions(public-func-c-unit-tests PRIVATE CIVETWEB_DLL_IMPORTS)
86 endif()
87 target_include_directories(
88 public-func-c-unit-tests PUBLIC
89 ${PROJECT_SOURCE_DIR}/include)
90 target_link_libraries(public-func-c-unit-tests civetweb-c-library ${CHECK_LIBRARIES})
91 add_dependencies(public-func-c-unit-tests check-unit-test-framework)
92
93 add_library(public-server-c-unit-tests STATIC public_server.c)
94 if (BUILD_SHARED_LIBS)
95 target_compile_definitions(public-server-c-unit-tests PRIVATE CIVETWEB_DLL_IMPORTS)
96 endif()
97 target_include_directories(
98 public-server-c-unit-tests PUBLIC
99 ${PROJECT_SOURCE_DIR}/include)
100 target_link_libraries(public-server-c-unit-tests civetweb-c-library ${CHECK_LIBRARIES})
101 add_dependencies(public-server-c-unit-tests check-unit-test-framework)
102
103 add_library(private-c-unit-tests STATIC private.c)
104 target_include_directories(
105 private-c-unit-tests PUBLIC
106 ${PROJECT_SOURCE_DIR}/include)
107 target_link_libraries(private-c-unit-tests ${CHECK_LIBRARIES})
108 add_dependencies(private-c-unit-tests check-unit-test-framework)
109
110 add_library(timer-c-unit-tests STATIC timertest.c)
111 target_include_directories(
112 timer-c-unit-tests PUBLIC
113 ${PROJECT_SOURCE_DIR}/include)
114 target_link_libraries(timer-c-unit-tests ${CHECK_LIBRARIES})
115 add_dependencies(timer-c-unit-tests check-unit-test-framework)
116
117 add_library(exe-c-unit-tests STATIC private_exe.c)
118 if (BUILD_SHARED_LIBS)
119 target_compile_definitions(exe-c-unit-tests PRIVATE)
120 endif()
121 target_include_directories(
122 exe-c-unit-tests PUBLIC
123 ${PROJECT_SOURCE_DIR}/include)
124 target_link_libraries(exe-c-unit-tests civetweb-c-library ${CHECK_LIBRARIES})
125 add_dependencies(exe-c-unit-tests check-unit-test-framework)
126
127 add_executable(main-c-unit-test main.c)
128 target_link_libraries(main-c-unit-test
129 shared-c-unit-tests
130 public-func-c-unit-tests
131 public-server-c-unit-tests
132 private-c-unit-tests
133 timer-c-unit-tests
134 exe-c-unit-tests
135 ${CHECK_LIBRARIES})
136 add_dependencies(main-c-unit-test check-unit-test-framework)
137
138 # Add a check command that builds the dependent test program
139 add_custom_target(check
140 COMMAND ${CMAKE_CTEST_COMMAND}
141 DEPENDS main-c-unit-test)
142
143 # A macro for adding tests
144 macro(civetweb_add_test suite test_case)
145 set(test "test-${suite}-${test_case}")
146 string(TOLOWER "${test}" test)
147 string(REGEX REPLACE "[^-A-Za-z0-9]" "-" test "${test}")
148 add_test(
149 NAME ${test}
150 COMMAND main-c-unit-test "--test-dir=${CMAKE_CURRENT_SOURCE_DIR}" "--suite=${suite}" "--test-case=${test_case}")
151 if (WIN32)
152 string(REPLACE ";" "\\;" test_path "$ENV{PATH}")
153 set_tests_properties(${test} PROPERTIES
154 ENVIRONMENT "PATH=${test_path}\\;$<TARGET_FILE_DIR:civetweb-c-library>")
155 endif()
156 endmacro(civetweb_add_test)
157
158
159 # Tests of private functions
160 civetweb_add_test(Private "HTTP Message")
161 civetweb_add_test(Private "HTTP Keep Alive")
162 civetweb_add_test(Private "URL Parsing 1")
163 civetweb_add_test(Private "URL Parsing 2")
164 civetweb_add_test(Private "URL Parsing 3")
165 civetweb_add_test(Private "Internal Parsing 1")
166 civetweb_add_test(Private "Internal Parsing 2")
167 civetweb_add_test(Private "Internal Parsing 3")
168 civetweb_add_test(Private "Internal Parsing 4")
169 civetweb_add_test(Private "Internal Parsing 5")
170 civetweb_add_test(Private "Internal Parsing 6")
171 civetweb_add_test(Private "Internal Parsing 7")
172 civetweb_add_test(Private "Encode Decode")
173 civetweb_add_test(Private "Mask Data")
174 civetweb_add_test(Private "Date Parsing")
175 civetweb_add_test(Private "SHA1")
176 civetweb_add_test(Private "Config Options")
177
178 # Public API function tests
179 civetweb_add_test(PublicFunc "Version")
180 civetweb_add_test(PublicFunc "Options")
181 civetweb_add_test(PublicFunc "MIME types")
182 civetweb_add_test(PublicFunc "strcasecmp")
183 civetweb_add_test(PublicFunc "URL encoding decoding")
184 civetweb_add_test(PublicFunc "Cookies and variables")
185 civetweb_add_test(PublicFunc "MD5")
186 civetweb_add_test(PublicFunc "Aux functions")
187
188 # Public API server tests
189 civetweb_add_test(PublicServer "Check test environment")
190 civetweb_add_test(PublicServer "Init library")
191 civetweb_add_test(PublicServer "Start threads")
192 civetweb_add_test(PublicServer "Minimal HTTP Server")
193 civetweb_add_test(PublicServer "Minimal HTTPS Server")
194 civetweb_add_test(PublicServer "Minimal HTTP Client")
195 civetweb_add_test(PublicServer "Minimal HTTPS Client")
196 civetweb_add_test(PublicServer "Start Stop HTTP Server")
197 civetweb_add_test(PublicServer "Start Stop HTTP Server IPv6")
198 civetweb_add_test(PublicServer "Start Stop HTTPS Server")
199 civetweb_add_test(PublicServer "TLS Server Client")
200 civetweb_add_test(PublicServer "Server Requests")
201 civetweb_add_test(PublicServer "Store Body")
202 civetweb_add_test(PublicServer "Handle Form")
203 civetweb_add_test(PublicServer "HTTP Authentication")
204 civetweb_add_test(PublicServer "HTTP Keep Alive")
205 civetweb_add_test(PublicServer "Error handling")
206 civetweb_add_test(PublicServer "Error logging")
207 civetweb_add_test(PublicServer "Limit speed")
208 civetweb_add_test(PublicServer "Large file")
209 civetweb_add_test(PublicServer "File in memory")
210
211 # Timer tests
212 civetweb_add_test(Timer "Timer Single Shot")
213 civetweb_add_test(Timer "Timer Periodic")
214 civetweb_add_test(Timer "Timer Mixed")
215
216 # Tests with main.c
217 civetweb_add_test(EXE "Helper funcs")
218
219
220 # Add the coverage command(s)
221 if (${CMAKE_BUILD_TYPE} MATCHES "[Cc]overage")
222 find_program(GCOV_EXECUTABLE gcov)
223 find_program(LCOV_EXECUTABLE lcov)
224 find_program(GENHTML_EXECUTABLE genhtml)
225 find_program(CTEST_EXECUTABLE ctest)
226 if (GCOV_EXECUTABLE AND LCOV_EXECUTABLE AND GENHTML_EXECUTABLE AND CTEST_EXECUTABLE AND HAVE_C_FLAG_COVERAGE)
227 add_custom_command(
228 OUTPUT ${CMAKE_BINARY_DIR}/lcov/index.html
229 COMMAND ${LCOV_EXECUTABLE} -q -z -d .
230 COMMAND ${LCOV_EXECUTABLE} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o before.lcov -i
231 COMMAND ${CTEST_EXECUTABLE} --force-new-ctest-process
232 COMMAND ${LCOV_EXECUTABLE} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o after.lcov
233 COMMAND ${LCOV_EXECUTABLE} -q -a before.lcov -a after.lcov --output-file final.lcov
234 COMMAND ${LCOV_EXECUTABLE} -q -r final.lcov "'${CMAKE_SOURCE_DIR}/unittest/*'" -o final.lcov
235 COMMAND ${GENHTML_EXECUTABLE} final.lcov -o lcov --demangle-cpp --sort -p "${CMAKE_SOURCE_DIR}" -t benchmark
236 DEPENDS main-c-unit-test
237 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
238 COMMENT "Running LCOV"
239 )
240 add_custom_target(coverage
241 DEPENDS ${CMAKE_BINARY_DIR}/lcov/index.html
242 COMMENT "LCOV report at lcov/index.html"
243 )
244 message(STATUS "Coverage command added")
245 else()
246 if (HAVE_C_FLAG_COVERAGE)
247 set(C_FLAG_COVERAGE_MESSAGE supported)
248 else()
249 set(C_FLAG_COVERAGE_MESSAGE unavailable)
250 endif()
251 message(WARNING
252 "Coverage command not available:\n"
253 " gcov: ${GCOV_EXECUTABLE}\n"
254 " lcov: ${LCOV_EXECUTABLE}\n"
255 " genhtml: ${GENHTML_EXECUTABLE}\n"
256 " ctest: ${CTEST_EXECUTABLE}\n"
257 " --coverage flag: ${C_FLAG_COVERAGE_MESSAGE}")
258 endif()
259 endif()
260