Skip to content

Commit

Permalink
refs #203
Browse files Browse the repository at this point in the history
- moved configuration files from cpp-pthread into cpp-logger
  • Loading branch information
HerbertKoelman committed Oct 27, 2019
1 parent b11858f commit 002f3ed
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmake/CMakeLists.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project(googletest-download VERSION 1.8.1)
include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.1
GIT_TAG v1.10.x
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
Expand Down
33 changes: 33 additions & 0 deletions cmake/CoverageConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
option(COVERAGE "Activate coverage")

if (COVERAGE)

# Handle coverage with GNU compilers
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message(STATUS "Detecting LCOV")
find_program(LCOV lcov)
if ( LCOV )

message(STATUS "Detecting LCOV [${LCOV}] - done")
add_custom_target( coverage
COMMAND ${CMAKE_CURRENT_LIST_DIR}/LCOV
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Coverage report (${CMAKE_CURRENT_LIST_DIR}/LCOV)"
VERBATIM
)
message(STATUS "Added custom build target [coverage]...")

endif()

message(STATUS "Setting GCOV --coverage compiler option")
add_compile_options(--coverage)
if (CMAKE_VERSION VERSION_GREATER "3.13.5")
message(STATUS "Setting GCOV --coverage linker option")
add_link_options(--coverage)
else ()
message(STATUS "Setting GCOV --coverage option in linker related variables CMAKE_EXE_LINKER_FLAGS and CMAKE_SHARED_LINKER_FLAGS")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
endif ()
endif ()
endif ()
19 changes: 19 additions & 0 deletions cmake/FGCOV
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env sh

# author: herbert koelman
#
# This shell script makes sure to handle only files that have produced coverage data. It comes with the
# SonarConfig.cmake module
#

for source_gcda_file in $(find ./ -type f -name "*.gcda")
do
source_file=`basename $source_gcda_file .gcda`
source_dir=`dirname $source_gcda_file`
source_gcno_file=$source_dir/$source_file.gcno

echo "Handling file [$source_gcno_file]------------------------"
[ -f $source_gcno_file ] && gcov -m $source_gcno_file
echo "Done -----------------------------------------------------"
echo
done
10 changes: 4 additions & 6 deletions cmake/GTestExtConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ if (BUILD_TESTS)
# Add googletest directly to our build. This adds
# the following targets: gtest, gtest_main, gmock
# and gmock_main
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src"
"${CMAKE_BINARY_DIR}/googletest-build")
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src" "${CMAKE_BINARY_DIR}/googletest-build")

# The gtest/gmock targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if(CMAKE_VERSION VERSION_LESS 2.8.11)
message(STATUS "GoogleTest include directory ${gtest_SOURCE_DIR}/include ${gmock_SOURCE_DIR}/include)")
include_directories("${gtest_SOURCE_DIR}/include"
"${gmock_SOURCE_DIR}/include")
message(STATUS "GoogleTest include directory ${gtest_SOURCE_DIR}/include ${gmock_SOURCE_DIR}/include)")
include_directories("${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include")
endif()

add_library(GTest::GTest ALIAS gtest)
Expand All @@ -53,4 +51,4 @@ if (BUILD_TESTS)
endif()
else()
message(STATUS "Disabled unit testing (BUILD_TESTS is ${BUILD_TESTS})")
endif()
endif()
23 changes: 23 additions & 0 deletions cmake/LCOV
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#8/usr/bin/env bash

initialize_coverage_file=""

for directory in $(find ./ -type f -name "*.gcda" -exec dirname {} \; | sort -u)
do
echo "Handling directory [$directory]"

if [ "${initialize_coverage_file}" == "" ]
then
echo "Initializing [coverage.info] file"
lcov --quiet --directory $directory --capture --output-file coverage.info
initialize_coverage_file="`date`"
else
coverage_info=$(mktemp --suffix=.coverage)
lcov --quiet --directory $directory --capture --output-file $coverage_info
echo "Adding tracefile [$coverage_info] to [coverage.info]"
lcov --quiet --add-tracefile $coverage_info --add-tracefile coverage.info --output-file coverage.info
fi
done
lcov --quiet --remove coverage.info '/usr/*' --output-file coverage.info
lcov --quiet --remove coverage.info '*/googletest/*' --output-file coverage.info
lcov --list coverage.info
20 changes: 18 additions & 2 deletions cmake/SonarCloudConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,30 @@ if ( SONAR )
find_program(SONAR_BUILD_WRAPPER build-wrapper-linux-x86-64)
if ( SONAR_BUILD_WRAPPER )
add_custom_target( build-wrapper
COMMAND ${SONAR_BUILD_WRAPPER} --out-dir ${SONAR_WRAPPER_OUTPUT_DIR} make clean all
COMMAND ${SONAR_BUILD_WRAPPER} --out-dir ${SONAR_WRAPPER_OUTPUT_DIR} make clean all test
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "run SONAR's ${SONAR_BUILD_WRAPPER}"
)
message(STATUS "Added custom target [build-wrapper]...")
add_dependencies(code-quality build-wrapper)
endif()

find_program(SONAR_GCOV gcov)
if(SONAR_GCOV)
add_custom_target( sonar-gcov-report
# COMMAND find ./CMakeFiles/ -type f -name "*.gcno" -exec ${SONAR_GCOV} {} -m \; > /dev/null 2>&1
COMMAND ${CMAKE_CURRENT_LIST_DIR}/FGCOV
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
# COMMENT "Built sonar GCOV report (${SONAR_GCOV})"
COMMENT "Built sonar GCOV report (${CMAKE_CURRENT_LIST_DIR}/FGCOV)"
VERBATIM
)
message(STATUS "Added custom target [sonar-gcov-report]...")

add_dependencies(sonar-gcov-report build-wrapper )
add_dependencies(code-quality sonar-gcov-report)
else()
add_dependencies(code-quality build-wrapper)
endif()

else()
message(SEND_ERROR "Failed to find the program [sonar_scanner], make sure sonar tools are installed.")
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sonar.cfamily.build-wrapper-output=@CMAKE_CURRENT_BINARY_DIR@/bw-output

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

# Base directory
Expand Down

0 comments on commit 002f3ed

Please sign in to comment.