Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ set(QL_INSTALL_CMAKEDIR "lib/cmake/${PACKAGE_NAME}" CACHE STRING
option(QL_BUILD_EXAMPLES "Build examples" ON)
option(QL_BUILD_TEST_SUITE "Build test suite" ON)
option(QL_BUILD_FUZZ_TEST_SUITE "Build fuzz test suite" OFF)
option(QL_ENABLE_COVERAGE "Enable code coverage reporting (gcov/lcov)" OFF)
option(QL_ENABLE_OPENMP "Detect and use OpenMP" OFF)
option(QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER "Enable the parallel unit test runner" OFF)
option(QL_ENABLE_SESSIONS "Singletons return different instances for different sessions" OFF)
Expand Down Expand Up @@ -84,6 +85,42 @@ if (NOT DEFINED CMAKE_CXX_EXTENSIONS)
set(CMAKE_CXX_EXTENSIONS FALSE)
endif()

# Code coverage flags
if (QL_ENABLE_COVERAGE)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-fprofile-arcs -ftest-coverage)
add_link_options(-fprofile-arcs -ftest-coverage)
else()
message(FATAL_ERROR "Code coverage is only supported with GCC or Clang")
endif()

find_program(LCOV_PATH lcov REQUIRED)
find_program(GENHTML_PATH genhtml REQUIRED)

add_custom_target(coverage
COMMENT "Running test suite and generating coverage report..."
# Reset counters
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters
# Run the test suite
COMMAND ${CMAKE_CTEST_COMMAND} --test-dir ${CMAKE_BINARY_DIR} --output-on-failure
# Capture coverage data
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --capture
--output-file ${CMAKE_BINARY_DIR}/coverage.info
# Filter to only ql/ source files
COMMAND ${LCOV_PATH}
--extract ${CMAKE_BINARY_DIR}/coverage.info
"${CMAKE_SOURCE_DIR}/ql/*"
--output-file ${CMAKE_BINARY_DIR}/coverage_filtered.info
# Generate HTML report
COMMAND ${GENHTML_PATH} ${CMAKE_BINARY_DIR}/coverage_filtered.info
--output-directory ${CMAKE_BINARY_DIR}/coverage_report
--title "QuantLib Coverage Report"
--legend --show-details
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
message(STATUS "Coverage enabled: build, then run 'make coverage' to generate report")
endif()

# Convenience option to activate all STD options
if (QL_USE_STD_CLASSES)
set(QL_USE_STD_ANY ON)
Expand Down
4 changes: 4 additions & 0 deletions test-suite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(QL_TEST_SOURCES
blackformula.cpp
blackvolsurfacedelta.cpp
bondforward.cpp
bondfunctions.cpp
bonds.cpp
brownianbridge.cpp
businessdayconventions.cpp
Expand All @@ -27,6 +28,7 @@ set(QL_TEST_SOURCES
capfloor.cpp
capflooredcoupon.cpp
cashflows.cpp
cashflowsmore.cpp
catbonds.cpp
cdo.cpp
cdsoption.cpp
Expand Down Expand Up @@ -82,6 +84,7 @@ set(QL_TEST_SOURCES
gjrgarchmodel.cpp
gsr.cpp
hestonmodel.cpp
hestonprocess.cpp
hestonslvmodel.cpp
himalayaoption.cpp
hybridhestonhullwhiteprocess.cpp
Expand Down Expand Up @@ -134,6 +137,7 @@ set(QL_TEST_SOURCES
pagodaoption.cpp
partialtimebarrieroption.cpp
pathgenerator.cpp
payoffs.cpp
period.cpp
perpetualfutures.cpp
piecewiseblackvariancesurface.cpp
Expand Down
Loading