coverage: move coverage flags within its own cmake

Signed-off-by: Ramon Roche <mrpollo@gmail.com>
This commit is contained in:
Ramon Roche
2025-07-02 17:20:42 +00:00
committed by Beat Küng
parent 5faa46fa0a
commit a54bbe0b24
2 changed files with 14 additions and 14 deletions

View File

@@ -240,20 +240,6 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${PX4_BUILD_TYPE} CACHE STRING "Build type" FORCE) set(CMAKE_BUILD_TYPE ${PX4_BUILD_TYPE} CACHE STRING "Build type" FORCE)
endif() endif()
if (CMAKE_BUILD_TYPE STREQUAL Coverage)
# Coverage instrumentation plus atomic updates
set(COVERAGE_FLAGS
--coverage
-fprofile-update=atomic
)
# Apply to every compile and link invocation
add_compile_options(${COVERAGE_FLAGS})
add_link_options(${COVERAGE_FLAGS})
message(STATUS "Coverage instrumentation enabled with flags: ${COVERAGE_FLAGS}")
endif()
if((CMAKE_BUILD_TYPE STREQUAL "Debug") OR (CMAKE_BUILD_TYPE STREQUAL "Coverage")) if((CMAKE_BUILD_TYPE STREQUAL "Debug") OR (CMAKE_BUILD_TYPE STREQUAL "Coverage"))
set(MAX_CUSTOM_OPT_LEVEL -O0) set(MAX_CUSTOM_OPT_LEVEL -O0)
elseif(CMAKE_BUILD_TYPE MATCHES "Sanitizer") elseif(CMAKE_BUILD_TYPE MATCHES "Sanitizer")

View File

@@ -36,6 +36,20 @@ find_program(GENHTML_PATH genhtml)
message(STATUS "Building for code coverage") message(STATUS "Building for code coverage")
if (CMAKE_BUILD_TYPE STREQUAL Coverage)
# Coverage instrumentation plus atomic updates
set(COVERAGE_FLAGS
--coverage
-fprofile-update=atomic
)
# Apply to every compile and link invocation
add_compile_options(${COVERAGE_FLAGS})
add_link_options(${COVERAGE_FLAGS})
message(STATUS "Coverage instrumentation enabled with flags: ${COVERAGE_FLAGS}")
endif()
# add code coverage build type # add code coverage build type
if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "AppleClang")) if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "AppleClang"))
set(CMAKE_C_FLAGS_COVERAGE "--coverage -ftest-coverage -fdiagnostics-absolute-paths -O0 -fprofile-arcs -fno-inline-functions" set(CMAKE_C_FLAGS_COVERAGE "--coverage -ftest-coverage -fdiagnostics-absolute-paths -O0 -fprofile-arcs -fno-inline-functions"