This commit is contained in:
Viktor Szakats 2025-09-03 14:32:29 +02:00
parent 5ef4451f7b
commit d1b81352e8
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
4 changed files with 17 additions and 1 deletions

View file

@ -311,6 +311,19 @@ if(CURL_CLANG_TIDY)
endif()
endif()
option(CURL_CODE_COVERAGE "Enable code coverage build options" OFF)
if(CURL_CODE_COVERAGE)
set(CURL_CFLAGS_COVERAGE "")
set(CURL_LIBS_COVERAGE "")
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
string(APPEND CURL_CFLAGS_COVERAGE " -DNDEBUG -O0 -g -fprofile-arcs -ftest-coverage")
list(APPEND CURL_LIBS_COVERAGE "gcov")
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
string(APPEND CURL_CFLAGS_COVERAGE " -DNDEBUG -O0 -g -fprofile-arcs -ftest-coverage")
list(APPEND CURL_LIBS_COVERAGE "llvm-gcov")
endif()
endif()
# For debug libs and exes, add "-d" postfix
if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "-d")
@ -1983,7 +1996,7 @@ if(WIN32)
endif()
endif()
list(APPEND CURL_LIBS ${CURL_NETWORK_AND_TIME_LIBS})
list(APPEND CURL_LIBS ${CURL_NETWORK_AND_TIME_LIBS} ${CURL_LIBS_COVERAGE})
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") # MSVC but exclude clang-cl
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-MP") # Parallel compilation

View file

@ -229,6 +229,7 @@ target_link_libraries(my_target PRIVATE CURL::libcurl)
- `BUILD_TESTING`: Build tests. Default: `ON`
- `CURL_CLANG_TIDY`: Run the build through `clang-tidy`. Default: `OFF`
- `CURL_CLANG_TIDYFLAGS`: Custom options to pass to `clang-tidy`. Default: (empty)
- `CURL_CODE_COVERAGE`: Enable code coverage build options. Default: `OFF`
- `CURL_COMPLETION_FISH`: Install fish completions. Default: `OFF`
- `CURL_COMPLETION_FISH_DIR`: Custom fish completion install directory.
- `CURL_COMPLETION_ZSH`: Install zsh completions. Default: `OFF`

View file

@ -25,6 +25,7 @@
set(LIBCURL_OUTPUT_NAME "${LIB_NAME}" CACHE STRING "Basename of the curl library")
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS ${CURL_DEBUG_MACROS} "BUILDING_LIBCURL")
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS ${CURL_CFLAGS_COVERAGE})
configure_file("curl_config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/curl_config.h")

View file

@ -23,6 +23,7 @@
###########################################################################
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "${CURL_DEBUG_MACROS}")
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS ${CURL_CFLAGS_COVERAGE})
set(_curl_cfiles_gen "")
set(_curl_hfiles_gen "")