Skip to content

Commit

Permalink
Merged Pull Request '#45 feature/gcov->main : feat: introduce code co…
Browse files Browse the repository at this point in the history
…verage generation'

feat: introduce code coverage generation
  • Loading branch information
Automation51D authored Jul 25, 2024
2 parents 0b36f29 + 8be49e1 commit 13c89aa
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ if(NOT CMAKE_BUILD_TYPE AND NOT MSVC)
set(CMAKE_BUILD_TYPE "Release")
endif()

string(TOLOWER ${CMAKE_BUILD_TYPE} lower_CMAKE_BUILD_TYPE)

if (NOT MSVC)
string(TOLOWER ${CMAKE_BUILD_TYPE} lower_CMAKE_BUILD_TYPE)
if (lower_CMAKE_BUILD_TYPE MATCHES "^debug")
set(COMPILE_OPTION_DEBUG -D_DEBUG)
endif()
Expand Down Expand Up @@ -121,6 +122,18 @@ if (MSVC)
else ()
target_compile_options(fiftyone-common-c PRIVATE ${COMPILE_OPTION_DEBUG} "-Werror" "-Wno-atomic-alignment")
target_compile_options(fiftyone-common-cxx PRIVATE ${COMPILE_OPTION_DEBUG} "-Werror")
if (lower_CMAKE_BUILD_TYPE STREQUAL "debug")
message("-- fiftyone-common-c(xx)-cov adding targets with code coverage")
add_library(fiftyone-common-c-cov ${COMC_SRC} ${COMC_H})
target_link_libraries(fiftyone-common-c-cov ${CMAKE_THREAD_LIBS_INIT} ${GCCLIBATOMIC_LIBRARY})
add_library(fiftyone-common-cxx-cov ${COMCPP_SRC} ${COMCPP_H})
target_link_libraries(fiftyone-common-cxx-cov fiftyone-common-c-cov)
target_compile_options(fiftyone-common-c-cov PRIVATE "--coverage")
target_compile_options(fiftyone-common-cxx-cov PRIVATE "--coverage")
set_target_properties(fiftyone-common-c-cov fiftyone-common-cxx-cov PROPERTIES FOLDER "Common")
target_compile_options(fiftyone-common-c-cov PRIVATE ${COMPILE_OPTION_DEBUG} "-Werror" "-Wno-atomic-alignment")
target_compile_options(fiftyone-common-cxx-cov PRIVATE ${COMPILE_OPTION_DEBUG} "-Werror")
endif()
endif()

# Examples
Expand Down Expand Up @@ -181,9 +194,19 @@ if(BUILD_TESTING)
target_link_options(CommonTests PRIVATE "/WX")
else ()
target_compile_options(CommonTests PRIVATE ${COMPILE_OPTION_DEBUG})
if (lower_CMAKE_BUILD_TYPE STREQUAL "debug")
message("-- CommonTests Linker options for code coverage")
target_link_options(CommonTests PRIVATE "-fprofile-arcs" "-ftest-coverage")
endif()
endif()

if (MSVC OR NOT lower_CMAKE_BUILD_TYPE STREQUAL "debug")
target_link_libraries(CommonTests fiftyone-common-cxx gtest_main)
else()
message("-- CommonTests linking fiftyone-common-cxx-cov lib with coverage")
target_link_libraries(CommonTests fiftyone-common-cxx-cov gtest_main)
endif()

target_link_libraries(CommonTests fiftyone-common-cxx gtest_main)
gtest_discover_tests(CommonTests PROPERTIES TEST_DISCOVERY_TIMEOUT 600)
set_target_properties(CommonTests PROPERTIES FOLDER "Tests")

Expand Down

0 comments on commit 13c89aa

Please sign in to comment.