Skip to content

Commit

Permalink
Improve handling of the coverage reports.
Browse files Browse the repository at this point in the history
- Enable building the documentation (optional)
- Applying the coverage flags for *all* binaries and not only
for unit test application.
  • Loading branch information
vahancho committed Nov 28, 2022
1 parent f7a2412 commit c116157
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 19 deletions.
1 change: 0 additions & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,3 @@ jobs:
with:
verbose: true
gcov: true
gcov_include: ${{github.workspace}}/src/textable.*
56 changes: 54 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ project(textable VERSION 1.1.0
include(GNUInstallDirs)

# General options
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
option(ENABLE_TESTING "Enable unit test build" OFF)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
option(ENABLE_TESTING "Enable unit test build" OFF)
option(BUILD_DOCUMENTATION "Build documentation" ON)

# By default, Visual Studio detects a byte-order mark to determine if the source
# file is in an encoded Unicode format, for example, UTF-16 or UTF-8. If no
Expand Down Expand Up @@ -93,6 +94,57 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

###############################################################################
# Generate documentation if needed
#

# Check if Doxygen is installed
find_package(Doxygen)

if (DOXYGEN_FOUND AND BUILD_DOCUMENTATION)
set(DOXYGEN_GENERATE_LATEX NO)
set(DOXYGEN_CREATE_SUBDIRS YES)
set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/docs/html)
set(DOXYGEN_PROJECT_NAME ${PROJECT_DESCRIPTION})
set(DOXYGEN_EXTRACT_STATIC YES)
set(DOXYGEN_EXTRACT_ALL YES)
set(DOXYGEN_EXTRACT_LOCAL_METHODS YES)
set(DOXYGEN_WARN_NO_PARAMDOC YES)
set(DOXYGEN_RECURSIVE YES)
set(DOXYGEN_EXCLUDE ${PROJECT_SOURCE_DIR}/tes)
set(DOXYGEN_HTML_OUTPUT .)
set(DOXYGEN_GENERATE_TREEVIEW YES)
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE README.md)

# Add the documentation target. This target doesn't build by default if doxygen is found.
# To build it explicitly, use '--target documentation' or 'make documentation' option.
doxygen_add_docs(documentation
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Building the project documentation")
else()
message("Failed to generate documentation: Doxygen is not found")
endif()

###############################################################################
# Testing
#
if (ENABLE_TESTING)
# Coverage support.
option(CODE_COVERAGE "Enable coverage reporting" ON)
if (CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Add required flags (GCC & LLVM/Clang)
add_compile_options(-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags
)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
add_link_options(--coverage)
else()
link_libraries(--coverage)
endif()
endif()
endif()

add_subdirectory(src)

if (ENABLE_TESTING)
Expand Down
18 changes: 2 additions & 16 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# SOFTWARE. *
#*********************************************************************************/

set(TARGET textable_test)
set(TARGET unittest)

find_package(GTest CONFIG REQUIRED)

Expand All @@ -40,18 +40,4 @@ add_custom_command(
$<TARGET_FILE_DIR:${TARGET}>
)

# Coverage support.
option(CODE_COVERAGE "Enable coverage reporting" ON)
if (CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Add required flags (GCC & LLVM/Clang)
target_compile_options(${TARGET} PUBLIC
-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags
)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
target_link_options(${TARGET} PUBLIC --coverage)
else()
target_link_libraries(${TARGET} PUBLIC --coverage)
endif()
endif()
add_test(NAME unittests COMMAND unittest)

0 comments on commit c116157

Please sign in to comment.