diff --git a/Meta/CMake/lagom_compile_options.cmake b/Meta/CMake/lagom_compile_options.cmake index cad5e56947..e1b0fa8fc5 100644 --- a/Meta/CMake/lagom_compile_options.cmake +++ b/Meta/CMake/lagom_compile_options.cmake @@ -34,3 +34,13 @@ add_linker_flag_if_supported(LINKER:--gdb-index) if (NOT ENABLE_FUZZERS) add_linker_flag_if_supported(LINKER:-Bsymbolic-non-weak-functions) endif() + +if (ENABLE_LAGOM_COVERAGE_COLLECTION) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND NOT ENABLE_FUZZERS) + add_compile_options(-fprofile-instr-generate -fcoverage-mapping) + add_link_options(-fprofile-instr-generate) + else() + message(FATAL_ERROR + "Collecting code coverage is unsupported in this configuration.") + endif() +endif() diff --git a/Meta/CMake/lagom_options.cmake b/Meta/CMake/lagom_options.cmake index 02496f6758..8308fa9d2f 100644 --- a/Meta/CMake/lagom_options.cmake +++ b/Meta/CMake/lagom_options.cmake @@ -15,3 +15,4 @@ serenity_option(ENABLE_LAGOM_CCACHE ON CACHE BOOL "Enable ccache for Lagom build serenity_option(ENABLE_LAGOM_LIBWEB ON CACHE BOOL "Enable compiling LibWeb for Lagom builds") serenity_option(ENABLE_LAGOM_LADYBIRD OFF CACHE BOOL "Enable compiling Ladybird from Lagom") serenity_option(LAGOM_USE_LINKER "" CACHE STRING "The linker to use (e.g. lld, mold) instead of the system default") +serenity_option(ENABLE_LAGOM_COVERAGE_COLLECTION OFF CACHE STRING "Enable code coverage instrumentation for lagom binaries in clang")