Skip to content

Instantly share code, notes, and snippets.

@v3c70r
Created January 10, 2017 21:48
Show Gist options
  • Save v3c70r/badc7284cd40da5ffce14e60a84fac39 to your computer and use it in GitHub Desktop.
Save v3c70r/badc7284cd40da5ffce14e60a84fac39 to your computer and use it in GitHub Desktop.
CodeCoverage using cmake
# An example of how to use gcov/lcov with cmake.
cmake_minimum_required (VERSION 2.8.11)
project(testing)
set (CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
set (CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
add_executable(exe test.cpp)
enable_testing()
add_test( NAME case1
COMMAND exe)
add_test( NAME case2
COMMAND exe 1)
add_test( NAME case3
COMMAND exe 2)
if (DEFINED PARAM)
add_test( NAME customizedCase
COMMAND exe ${PARAM})
endif()
# need the following coverage module
# https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
if(CMAKE_COMPILER_IS_GNUCXX)
include(CodeCoverage)
setup_target_for_coverage(${PROJECT_NAME}_coverage "exe 1" coverage)
endif()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment