Skip to content

Commit 002f3ed

Browse files
refs #203
- moved configuration files from cpp-pthread into cpp-logger
1 parent b11858f commit 002f3ed

File tree

7 files changed

+99
-10
lines changed

7 files changed

+99
-10
lines changed

cmake/CMakeLists.txt.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ project(googletest-download VERSION 1.8.1)
88
include(ExternalProject)
99
ExternalProject_Add(googletest
1010
GIT_REPOSITORY https://github.com/google/googletest.git
11-
GIT_TAG release-1.8.1
11+
GIT_TAG v1.10.x
1212
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
1313
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
1414
CONFIGURE_COMMAND ""

cmake/CoverageConfig.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
option(COVERAGE "Activate coverage")
2+
3+
if (COVERAGE)
4+
5+
# Handle coverage with GNU compilers
6+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
7+
message(STATUS "Detecting LCOV")
8+
find_program(LCOV lcov)
9+
if ( LCOV )
10+
11+
message(STATUS "Detecting LCOV [${LCOV}] - done")
12+
add_custom_target( coverage
13+
COMMAND ${CMAKE_CURRENT_LIST_DIR}/LCOV
14+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
15+
COMMENT "Coverage report (${CMAKE_CURRENT_LIST_DIR}/LCOV)"
16+
VERBATIM
17+
)
18+
message(STATUS "Added custom build target [coverage]...")
19+
20+
endif()
21+
22+
message(STATUS "Setting GCOV --coverage compiler option")
23+
add_compile_options(--coverage)
24+
if (CMAKE_VERSION VERSION_GREATER "3.13.5")
25+
message(STATUS "Setting GCOV --coverage linker option")
26+
add_link_options(--coverage)
27+
else ()
28+
message(STATUS "Setting GCOV --coverage option in linker related variables CMAKE_EXE_LINKER_FLAGS and CMAKE_SHARED_LINKER_FLAGS")
29+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
30+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
31+
endif ()
32+
endif ()
33+
endif ()

cmake/FGCOV

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env sh
2+
3+
# author: herbert koelman
4+
#
5+
# This shell script makes sure to handle only files that have produced coverage data. It comes with the
6+
# SonarConfig.cmake module
7+
#
8+
9+
for source_gcda_file in $(find ./ -type f -name "*.gcda")
10+
do
11+
source_file=`basename $source_gcda_file .gcda`
12+
source_dir=`dirname $source_gcda_file`
13+
source_gcno_file=$source_dir/$source_file.gcno
14+
15+
echo "Handling file [$source_gcno_file]------------------------"
16+
[ -f $source_gcno_file ] && gcov -m $source_gcno_file
17+
echo "Done -----------------------------------------------------"
18+
echo
19+
done

cmake/GTestExtConfig.cmake

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@ if (BUILD_TESTS)
2828
# Add googletest directly to our build. This adds
2929
# the following targets: gtest, gtest_main, gmock
3030
# and gmock_main
31-
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src"
32-
"${CMAKE_BINARY_DIR}/googletest-build")
31+
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src" "${CMAKE_BINARY_DIR}/googletest-build")
3332

3433
# The gtest/gmock targets carry header search path
3534
# dependencies automatically when using CMake 2.8.11 or
3635
# later. Otherwise we have to add them here ourselves.
3736
if(CMAKE_VERSION VERSION_LESS 2.8.11)
38-
message(STATUS "GoogleTest include directory ${gtest_SOURCE_DIR}/include ${gmock_SOURCE_DIR}/include)")
39-
include_directories("${gtest_SOURCE_DIR}/include"
40-
"${gmock_SOURCE_DIR}/include")
37+
message(STATUS "GoogleTest include directory ${gtest_SOURCE_DIR}/include ${gmock_SOURCE_DIR}/include)")
38+
include_directories("${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include")
4139
endif()
4240

4341
add_library(GTest::GTest ALIAS gtest)
@@ -53,4 +51,4 @@ if (BUILD_TESTS)
5351
endif()
5452
else()
5553
message(STATUS "Disabled unit testing (BUILD_TESTS is ${BUILD_TESTS})")
56-
endif()
54+
endif()

cmake/LCOV

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#8/usr/bin/env bash
2+
3+
initialize_coverage_file=""
4+
5+
for directory in $(find ./ -type f -name "*.gcda" -exec dirname {} \; | sort -u)
6+
do
7+
echo "Handling directory [$directory]"
8+
9+
if [ "${initialize_coverage_file}" == "" ]
10+
then
11+
echo "Initializing [coverage.info] file"
12+
lcov --quiet --directory $directory --capture --output-file coverage.info
13+
initialize_coverage_file="`date`"
14+
else
15+
coverage_info=$(mktemp --suffix=.coverage)
16+
lcov --quiet --directory $directory --capture --output-file $coverage_info
17+
echo "Adding tracefile [$coverage_info] to [coverage.info]"
18+
lcov --quiet --add-tracefile $coverage_info --add-tracefile coverage.info --output-file coverage.info
19+
fi
20+
done
21+
lcov --quiet --remove coverage.info '/usr/*' --output-file coverage.info
22+
lcov --quiet --remove coverage.info '*/googletest/*' --output-file coverage.info
23+
lcov --list coverage.info

cmake/SonarCloudConfig.cmake

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,30 @@ if ( SONAR )
3535
find_program(SONAR_BUILD_WRAPPER build-wrapper-linux-x86-64)
3636
if ( SONAR_BUILD_WRAPPER )
3737
add_custom_target( build-wrapper
38-
COMMAND ${SONAR_BUILD_WRAPPER} --out-dir ${SONAR_WRAPPER_OUTPUT_DIR} make clean all
38+
COMMAND ${SONAR_BUILD_WRAPPER} --out-dir ${SONAR_WRAPPER_OUTPUT_DIR} make clean all test
3939
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
4040
COMMENT "run SONAR's ${SONAR_BUILD_WRAPPER}"
4141
)
4242
message(STATUS "Added custom target [build-wrapper]...")
43-
add_dependencies(code-quality build-wrapper)
4443
endif()
4544

45+
find_program(SONAR_GCOV gcov)
46+
if(SONAR_GCOV)
47+
add_custom_target( sonar-gcov-report
48+
# COMMAND find ./CMakeFiles/ -type f -name "*.gcno" -exec ${SONAR_GCOV} {} -m \; > /dev/null 2>&1
49+
COMMAND ${CMAKE_CURRENT_LIST_DIR}/FGCOV
50+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
51+
# COMMENT "Built sonar GCOV report (${SONAR_GCOV})"
52+
COMMENT "Built sonar GCOV report (${CMAKE_CURRENT_LIST_DIR}/FGCOV)"
53+
VERBATIM
54+
)
55+
message(STATUS "Added custom target [sonar-gcov-report]...")
56+
57+
add_dependencies(sonar-gcov-report build-wrapper )
58+
add_dependencies(code-quality sonar-gcov-report)
59+
else()
60+
add_dependencies(code-quality build-wrapper)
61+
endif()
4662

4763
else()
4864
message(SEND_ERROR "Failed to find the program [sonar_scanner], make sure sonar tools are installed.")

sonar-project.properties.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sonar.cfamily.build-wrapper-output=@CMAKE_CURRENT_BINARY_DIR@/bw-output
3131

3232
# Name of the project that will be displayed on the web interface.
3333
sonar.projectName=@PROJECT_NAME@
34-
sonar.projectVersion=@PROJECT_VERSION@
34+
sonar.projectVersion=@CPP_LOGGER_VERSION@
3535
sonar.links.homepage==https://github.com/HerbertKoelman/cpp-logger
3636

3737
# Base directory

0 commit comments

Comments
 (0)