@@ -14,6 +14,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeInc
1414include ("create_source_groups_macro" )
1515include ("eval_condition_macro" )
1616
17+ # --------------------------- Options --------------------------- #
18+ option (ENABLE_COVERAGE "Enable code coverage reporting" OFF )
1719option (GA_SHARED_LIB "Build GA as a shared library" OFF )
1820option (GA_UWP_BUILD "Build GA for UWP (if targeting windows)" OFF )
1921option (GA_BUILD_SAMPLE "Builds the GA Sample app" ON )
@@ -242,87 +244,87 @@ target_link_libraries(${UT_PROJECT_NAME} gtest gtest_main gmock_main)
242244target_link_libraries (${UT_PROJECT_NAME} ${PROJECT_NAME} )
243245
244246########################################
245-
246247add_test (NAME ${UT_PROJECT_NAME} COMMAND GameAnalyticsUnitTests)
247248
248- # --------------------------- Google Test Setup --------------------------- #
249-
250- find_program (GCOV_PATH gcov)
251- if (NOT GCOV_PATH)
252- message (WARNING "program gcov not found" )
253- endif ()
254-
255- find_program (LCOV_PATH lcov)
256- if (NOT LCOV_PATH)
257- message (WARNING "program lcov not found" )
258- endif ()
259-
260- find_program (GENHTML_PATH genhtml)
261- if (NOT GENHTML_PATH)
262- message (WARNING "program genhtml not found" )
263- endif ()
264-
265- if (LCOV_PATH AND GCOV_PATH)
249+ # --------------------------- Code Coverage Setup --------------------------- #
266250
267- target_compile_options (
268- GameAnalytics
269- PRIVATE
270- -g -O0 -fprofile-arcs -ftest-coverage
271- )
251+ if (ENABLE_COVERAGE)
252+ find_program (GCOV_PATH gcov)
253+ if ( NOT GCOV_PATH)
254+ message (WARNING "program gcov not found" )
255+ endif ( )
272256
273- target_link_libraries (
274- GameAnalytics
275- PRIVATE
276- --coverage
277- )
257+ find_program (LCOV_PATH lcov)
258+ if (NOT LCOV_PATH)
259+ message (WARNING "program lcov not found" )
260+ endif ()
278261
279- set (covname cov)
262+ find_program (GENHTML_PATH genhtml)
263+ if (NOT GENHTML_PATH)
264+ message (WARNING "program genhtml not found" )
265+ endif ()
280266
281- add_custom_target (cov_data
282- # Cleanup lcov
283- COMMENT "Resetting code coverage counters to zero."
284- ${LCOV_PATH} --directory . --zerocounters
267+ if (LCOV_PATH AND GCOV_PATH)
285268
286- # Run tests
287- COMMAND GameAnalyticsUnitTests
269+ target_compile_options (
270+ GameAnalytics
271+ PRIVATE
272+ -g -O0 -fprofile-arcs -ftest-coverage
273+ )
288274
289- # Capturing lcov counters and generating report
290- COMMAND ${LCOV_PATH} --directory . --capture --output -file ${covname} .info
291- COMMAND ${LCOV_PATH} --remove ${covname} .info
292- '${CMAKE_SOURCE_DIR} /source /dependencies/*'
293- '${CMAKE_SOURCE_DIR} /test /*'
294- '/usr/*'
295- '/Applications/Xcode.app/*'
296- --output -file ${covname} .info.cleaned
297- )
275+ target_link_libraries (
276+ GameAnalytics
277+ PRIVATE
278+ --coverage
279+ )
298280
299- if (GENHTML_PATH)
300- add_custom_target (cov
281+ set (covname cov)
301282
283+ add_custom_target (cov_data
302284 # Cleanup lcov
285+ COMMENT "Resetting code coverage counters to zero."
303286 ${LCOV_PATH} --directory . --zerocounters
304287
305288 # Run tests
306289 COMMAND GameAnalyticsUnitTests
307290
308291 # Capturing lcov counters and generating report
309- COMMAND ${LCOV_PATH} --directory . --capture --output -file ${covname} .info --rc lcov_branch_coverage=1 --rc derive_function_end_line=0
292+ COMMAND ${LCOV_PATH} --directory . --capture --output -file ${covname} .info
310293 COMMAND ${LCOV_PATH} --remove ${covname} .info
311- '${CMAKE_SOURCE_DIR} /source /dependencies/*'
312- '/usr/*'
313- --output -file ${covname} .info.cleaned
314- --rc lcov_branch_coverage=1
315- --rc derive_function_end_line=0
316- COMMAND ${GENHTML_PATH} -o ${covname} ${covname} .info.cleaned --rc lcov_branch_coverage=1 --rc derive_function_end_line=0
317- COMMAND ${CMAKE_COMMAND} -E remove ${covname} .info ${covname} .info.cleaned
318-
319- COMMENT "Resetting code coverage counters to zero.\n Processing code coverage counters and generating report."
294+ '${CMAKE_SOURCE_DIR} /source /dependencies/*'
295+ '${CMAKE_SOURCE_DIR} /test /*'
296+ '/usr/*'
297+ '/Applications/Xcode.app/*'
298+ --output -file ${covname} .info.cleaned
320299 )
300+
301+ if (GENHTML_PATH)
302+ add_custom_target (cov
303+
304+ # Cleanup lcov
305+ ${LCOV_PATH} --directory . --zerocounters
306+
307+ # Run tests
308+ COMMAND GameAnalyticsUnitTests
309+
310+ # Capturing lcov counters and generating report
311+ COMMAND ${LCOV_PATH} --directory . --capture --output -file ${covname} .info --rc lcov_branch_coverage=1 --rc derive_function_end_line=0
312+ COMMAND ${LCOV_PATH} --remove ${covname} .info
313+ '${CMAKE_SOURCE_DIR} /source /dependencies/*'
314+ '/usr/*'
315+ --output -file ${covname} .info.cleaned
316+ --rc lcov_branch_coverage=1
317+ --rc derive_function_end_line=0
318+ COMMAND ${GENHTML_PATH} -o ${covname} ${covname} .info.cleaned --rc lcov_branch_coverage=1 --rc derive_function_end_line=0
319+ COMMAND ${CMAKE_COMMAND} -E remove ${covname} .info ${covname} .info.cleaned
320+
321+ COMMENT "Resetting code coverage counters to zero.\n Processing code coverage counters and generating report."
322+ )
323+ else ()
324+ message (WARNING "unable to generate coverage report: missing genhtml" )
325+ endif ()
326+
321327 else ()
322- message (WARNING "unable to generate coverage report : missing genhtml " )
328+ message (WARNING "unable to add coverage targets : missing coverage tools " )
323329 endif ()
324-
325- else ()
326- message (WARNING "unable to add coverage targets: missing coverage tools" )
327330endif ()
328-
0 commit comments