diff options
author | Joakim Söderberg <joakim.soderberg@gmail.com> | 2014-12-10 22:30:33 +0100 |
---|---|---|
committer | Joakim Söderberg <joakim.soderberg@gmail.com> | 2014-12-12 23:57:01 +0100 |
commit | 19f33c0e71a950c673db39ed3e8c00eee928aad3 (patch) | |
tree | e04121039d8000167d57f36a8a9fdd5d10662afb /CMakeLists.txt | |
parent | 1c38ab17f5ab7e5f555b134fbb48eec049f383f1 (diff) | |
download | jansson-19f33c0e71a950c673db39ed3e8c00eee928aad3.zip jansson-19f33c0e71a950c673db39ed3e8c00eee928aad3.tar.gz jansson-19f33c0e71a950c673db39ed3e8c00eee928aad3.tar.bz2 |
Add support for coverage/coveralls.io in cmake project.
This adds support for http://coveralls.io/ to the cmake project. This can then be run via a new Travis job, which uploads json containing the coverage data to the website.
To use this, please login usin github at http://coveralls.io/ and enable the Jansson project. You can then get a nice percentage badge for code coverage after each Travis buid. Coveralls will also comment on pull request with coverage info.
To test and run it locally do:
```bash
$ mkdir build && cd build
$ cmake -DJANSSON_COVERALLS=ON -DCMAKE_BUILD_TYPE=Debug ..
$ cmake --build . # $ make
$ cmake --build . --target coveralls # $ make coveralls
```
There is also another script that generates a local HTML page using lcov CodeCoverage.cmake which can be run using
```bash
$ make coverage
```
The required depdencies to run this are:
gcov
curl
lcov (is needed for the normal CodeCoverage script)
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index fdc6b36..ea55e28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,12 @@ if (MSVC) option(JANSSON_STATIC_CRT "Link the static CRT libraries" OFF ) endif () +if (UNIX) + option(JANSSON_COVERAGE "(GCC Only! Requires gcov/lcov to be installed). Include target for doing coverage analysis for the test suite. Note that -DCMAKE_BUILD_TYPE=Debug must be set" OFF) + option(JANSSON_COVERALLS "Generate coverage info for Coveralls" OFF) + option(JANSSON_COVERALLS_UPLOAD "Upload coverage info to Coveralls (Only works via Travis)" ON) +endif () + # Set some nicer output dirs. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) @@ -108,6 +114,21 @@ if (NOT WIN32 AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)) add_definitions("-fPIC") endif() +message("C compiler: ${CMAKE_C_COMPILER_ID}") + +# Coverage only works with GCC for a debug build. +if (JANSSON_COVERALLS) + set(JANSSON_COVERAGE ON) +endif() + +if (JANSSON_COVERAGE) + include(CodeCoverage) + include(Coveralls) + + # This adds coverage arguments to gcc/clang. + coveralls_turn_on_coverage() +endif() + check_include_files (endian.h HAVE_ENDIAN_H) check_include_files (fcntl.h HAVE_FCNTL_H) check_include_files (sched.h HAVE_SCHED_H) @@ -520,6 +541,7 @@ if (NOT JANSSON_WITHOUT_TESTS) # Test harness for the suites tests. build_testprog(json_process ${PROJECT_SOURCE_DIR}/test/bin) + set(SUITE_TEST_CMD ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/json_process) set(SUITES encoding-flags valid invalid invalid-unicode) foreach (SUITE ${SUITES}) file(GLOB TESTDIRS ${jansson_SOURCE_DIR}/test/suites/${SUITE}/*) @@ -528,8 +550,6 @@ if (NOT JANSSON_WITHOUT_TESTS) if (IS_DIRECTORY ${TESTDIR}) get_filename_component(TNAME ${TESTDIR} NAME) - set(SUITE_TEST_CMD ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/json_process) - if (JANSSON_TEST_WITH_VALGRIND) add_test(memcheck__${SUITE}__${TNAME} ${MEMCHECK_COMMAND} ${SUITE_TEST_CMD} ${TESTDIR}) @@ -551,6 +571,21 @@ if (NOT JANSSON_WITHOUT_TESTS) endforeach () endforeach () + if (JANSSON_COVERAGE) + setup_target_for_coverage( + coverage # Coverage make target "make coverage". + coverage # Name of output directory. + make # Name of test runner executable. + test) # Arguments to the test runner above (make test). + + if (JANSSON_COVERALLS) + set(COVERAGE_SRCS ${JANSSON_SRC}) + coveralls_setup("${COVERAGE_SRCS}" ${JANSSON_COVERALLS_UPLOAD}) + endif () + endif () + + # Enable using "make check" just like the autotools project. + # By default cmake creates a target "make test" add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS json_process ${api_tests}) endif () |