From 65309d5db8a982ef163b248515e97b33b8767fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rombauts?= Date: Wed, 7 Oct 2015 22:24:18 +0200 Subject: [PATCH] Enable GCov instrumentation in Debug build mode and upload results to coveralls --- .travis.yml | 9 ++++++++- CMakeLists.txt | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 65bca81..f403201 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,13 +14,20 @@ addons: packages: - cppcheck +before_install: + - pip install --user cpp-coveralls + # scripts to run before build before_script: - mkdir build - cd build - - cmake -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON -DSQLITECPP_RUN_DOXYGEN=OFF .. + - cmake -DCMAKE_BUILD_TYPE=Debug -DSQLITECPP_USE_GCOV=ON -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON -DSQLITECPP_RUN_DOXYGEN=OFF .. # build examples, and run tests (ie make & make test) script: - cmake --build . - ctest --output-on-failure + +# publish GCov coveralls results +after_success: + - coveralls -e build/CMakeFiles -e examples -e googletest -e sqlite3 -e tests \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b50c9c..3e198ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,15 @@ else (MSVC) # GCC flags #add_compile_options() is not supported with CMake 2.8.7 of Ubuntu 12.04 on Travis-CI add_definitions(-rdynamic -fstack-protector-all -Wall -Wextra -pedantic -Wformat-security -Winit-self -Wswitch-default -Wswitch-enum -Wfloat-equal -Wshadow -Wcast-qual -Wconversion -Wlogical-op -Winline) + if (SQLITECPP_USE_GCOV AND CMAKE_COMPILER_IS_GNUCXX) + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + message (STATUS "Using GCov instrumentation") + else () + message (WARNING "GCov instrumentation works best in Debug mode") + endif () + add_definitions (-fprofile-arcs -ftest-coverage) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") + endif () elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # Clang flags add_definitions(-fstack-protector-all -Wall -Wextra -pedantic -Wformat-security -Winit-self -Wswitch-default -Wswitch-enum -Wfloat-equal -Wshadow -Wcast-qual -Wconversion -Winline) @@ -218,6 +227,8 @@ if (SQLITECPP_BUILD_TESTS) endif (NOT MSVC) # add the subdirectory containing the CMakeLists.txt for the gtest library + # TODO: under Linux, uses libgtest-dev if found + # TODO: move to the new googletest Github repository add_subdirectory(googletest) include_directories("${PROJECT_SOURCE_DIR}/googletest/include")