|
@@
-124,7
+124,6
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
124
|
message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading")
|
|
124
|
message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading")
|
|
125
|
endif() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
|
|
125
|
endif() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
|
|
126
|
|
|
126
|
|
|
127
|
message( CMAKE_BUILD_TYPE : ${CMAKE_BUILD_TYPE})
|
|
|
|
|
128
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
|
127
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
|
129
|
link_libraries(gcov)
|
|
128
|
link_libraries(gcov)
|
|
130
|
else()
|
|
129
|
else()
|
|
@@
-144,37
+143,32
endif()
|
|
144
|
function(SETUP_TARGET_FOR_COVERAGE)
|
|
143
|
function(SETUP_TARGET_FOR_COVERAGE)
|
|
145
|
|
|
144
|
|
|
146
|
set(options NONE)
|
|
145
|
set(options NONE)
|
|
147
|
set(oneValueArgs NAME TARGET GCNO)
|
|
146
|
set(oneValueArgs NAME TARGET OUTPUT)
|
|
148
|
set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
|
|
147
|
set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
|
|
149
|
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
148
|
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
150
|
|
|
149
|
|
|
151
|
if(NOT LCOV_PATH)
|
|
150
|
if(NOT LCOV_PATH)
|
|
152
|
# message(FATAL_ERROR "lcov not found! Aborting...")
|
|
151
|
message(FATAL_ERROR "lcov not found! Aborting...")
|
|
153
|
endif() # NOT LCOV_PATH
|
|
152
|
endif() # NOT LCOV_PATH
|
|
154
|
|
|
153
|
|
|
155
|
if(NOT GENHTML_PATH)
|
|
154
|
if(NOT GENHTML_PATH)
|
|
156
|
# message(FATAL_ERROR "genhtml not found! Aborting...")
|
|
155
|
message(FATAL_ERROR "genhtml not found! Aborting...")
|
|
157
|
endif() # NOT GENHTML_PATH
|
|
156
|
endif() # NOT GENHTML_PATH
|
|
158
|
message("Coverage target: " ${Coverage_TARGET})
|
|
|
|
|
159
|
message("Coverage name: " ${Coverage_NAME})
|
|
|
|
|
160
|
message("Coverage exe: " ${Coverage_EXECUTABLE})
|
|
|
|
|
161
|
message("Coverage gcno: " ${Coverage_GCNO})
|
|
|
|
|
162
|
|
|
157
|
|
|
163
|
# Setup target
|
|
158
|
# Setup target
|
|
164
|
add_custom_target(${Coverage_TARGET}
|
|
159
|
add_custom_target(${Coverage_TARGET}
|
|
165
|
|
|
160
|
|
|
166
|
# Cleanup lcov
|
|
161
|
# Cleanup lcov
|
|
167
|
# COMMAND ${LCOV_PATH} --directory . --zerocounters
|
|
162
|
COMMAND ${LCOV_PATH} --directory . --zerocounters
|
|
168
|
|
|
163
|
|
|
169
|
# Run tests
|
|
164
|
# Run tests
|
|
170
|
COMMAND ${Coverage_EXECUTABLE}
|
|
165
|
COMMAND ${Coverage_EXECUTABLE}
|
|
171
|
# Capturing lcov counters and generating report
|
|
|
|
|
172
|
COMMAND gcov ${Coverage_NAME} --object-file ${Coverage_GCNO}
|
|
|
|
|
173
|
|
|
166
|
|
|
174
|
# COMMAND ${LCOV_PATH} --directory . --capture --output-file ${Coverage_NAME}.info
|
|
167
|
# Capturing lcov counters and generating report
|
|
175
|
# COMMAND ${LCOV_PATH} --remove ${Coverage_NAME}.info ${COVERAGE_EXCLUDES} --output-file ${Coverage_NAME}.info.cleaned
|
|
168
|
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${Coverage_NAME}.info
|
|
176
|
# COMMAND ${GENHTML_PATH} -o ${Coverage_NAME} ${Coverage_NAME}.info.cleaned
|
|
169
|
COMMAND ${LCOV_PATH} --remove ${Coverage_NAME}.info ${COVERAGE_EXCLUDES} --output-file ${Coverage_NAME}.info.cleaned
|
|
177
|
# COMMAND ${CMAKE_COMMAND} -E remove ${Coverage_NAME}.info ${Coverage_NAME}.info.cleaned
|
|
170
|
COMMAND ${GENHTML_PATH} -o ${Coverage_OUTPUT} ${Coverage_NAME}.info.cleaned
|
|
|
|
|
171
|
COMMAND ${CMAKE_COMMAND} -E remove ${Coverage_NAME}.info ${Coverage_NAME}.info.cleaned
|
|
178
|
|
|
172
|
|
|
179
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
173
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
180
|
DEPENDS ${Coverage_DEPENDENCIES}
|
|
174
|
DEPENDS ${Coverage_DEPENDENCIES}
|
|
@@
-188,59
+182,7
function(SETUP_TARGET_FOR_COVERAGE)
|
|
188
|
# COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report."
|
|
182
|
# COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report."
|
|
189
|
# )
|
|
183
|
# )
|
|
190
|
|
|
184
|
|
|
191
|
endfunction() # SETUP_TARGET_FOR_COVERAGE
|
|
185
|
endfunction()
|
|
192
|
|
|
|
|
|
193
|
# Defines a target for running and collection code coverage information
|
|
|
|
|
194
|
# Builds dependencies, runs the given executable and outputs reports.
|
|
|
|
|
195
|
# NOTE! The executable should always have a ZERO as exit code otherwise
|
|
|
|
|
196
|
# the coverage generation will not complete.
|
|
|
|
|
197
|
#
|
|
|
|
|
198
|
# SETUP_TARGET_FOR_COVERAGE_COBERTURA(
|
|
|
|
|
199
|
# NAME ctest_coverage # New target name
|
|
|
|
|
200
|
# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
|
|
|
|
|
201
|
# DEPENDENCIES executable_target # Dependencies to build first
|
|
|
|
|
202
|
# )
|
|
|
|
|
203
|
function(SETUP_TARGET_FOR_COVERAGE_COBERTURA)
|
|
|
|
|
204
|
|
|
|
|
|
205
|
set(options NONE)
|
|
|
|
|
206
|
set(oneValueArgs NAME)
|
|
|
|
|
207
|
set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
|
|
|
|
|
208
|
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
|
|
|
209
|
|
|
|
|
|
210
|
if(NOT SIMPLE_PYTHON_EXECUTABLE)
|
|
|
|
|
211
|
message(FATAL_ERROR "python not found! Aborting...")
|
|
|
|
|
212
|
endif() # NOT SIMPLE_PYTHON_EXECUTABLE
|
|
|
|
|
213
|
|
|
|
|
|
214
|
if(NOT GCOVR_PATH)
|
|
|
|
|
215
|
message(FATAL_ERROR "gcovr not found! Aborting...")
|
|
|
|
|
216
|
endif() # NOT GCOVR_PATH
|
|
|
|
|
217
|
|
|
|
|
|
218
|
# Combine excludes to several -e arguments
|
|
|
|
|
219
|
set(COBERTURA_EXCLUDES "")
|
|
|
|
|
220
|
foreach(EXCLUDE ${COVERAGE_EXCLUDES})
|
|
|
|
|
221
|
set(COBERTURA_EXCLUDES "-e ${EXCLUDE} ${COBERTURA_EXCLUDES}")
|
|
|
|
|
222
|
endforeach()
|
|
|
|
|
223
|
|
|
|
|
|
224
|
add_custom_target(${Coverage_NAME}
|
|
|
|
|
225
|
|
|
|
|
|
226
|
# Run tests
|
|
|
|
|
227
|
${Coverage_EXECUTABLE}
|
|
|
|
|
228
|
|
|
|
|
|
229
|
# Running gcovr
|
|
|
|
|
230
|
COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} ${COBERTURA_EXCLUDES}
|
|
|
|
|
231
|
-o ${Coverage_NAME}.xml
|
|
|
|
|
232
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
|
|
|
233
|
DEPENDS ${Coverage_DEPENDENCIES}
|
|
|
|
|
234
|
COMMENT "Running gcovr to produce Cobertura code coverage report."
|
|
|
|
|
235
|
)
|
|
|
|
|
236
|
|
|
|
|
|
237
|
# Show info where to find the report
|
|
|
|
|
238
|
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
|
|
|
|
|
239
|
COMMAND ;
|
|
|
|
|
240
|
COMMENT "Cobertura code coverage report saved in ${Coverage_NAME}.xml."
|
|
|
|
|
241
|
)
|
|
|
|
|
242
|
|
|
|
|
|
243
|
endfunction() # SETUP_TARGET_FOR_COVERAGE_COBERTURA
|
|
|
|
|
244
|
|
|
186
|
|
|
245
|
function(APPEND_COVERAGE_COMPILER_FLAGS)
|
|
187
|
function(APPEND_COVERAGE_COMPILER_FLAGS)
|
|
246
|
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
|
|
188
|
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
|