From 90c9ae390eed4321d5bdf982bb13dd7925f496ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Fri, 31 May 2024 10:12:48 -0400
Subject: [PATCH] cmake: add coverage option

This allow to get coverage reports from ctest.
e.g.
    $ ctest -R typers -T test -T coverage

Change-Id: Ic7d1bf5d7d641f1e581e4855bbc923ee5d8994b5
---
 CMakeLists.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3c11de2515..1dd183360d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,6 +21,8 @@ option(JAMI_VIDEO_ACCEL "Build video hardware acceleration support" ON)
 option(BUILD_CONTRIB "Build contrib to CONTRIB_PATH" ON)
 option(BUILD_EXTRA_TOOLS "Build extra tools" OFF)
 option(ENABLE_ASAN "Enable address sanitization" OFF)
+option(ENABLE_COVERAGE "Enable coverage (for tests)" OFF)
+
 if(ENABLE_ASAN AND NOT MSVC)
   message(STATUS "Address sanitization enabled for daemon")
   # Add AddressSanitizer flags for both compiler and linker
@@ -28,6 +30,10 @@ if(ENABLE_ASAN AND NOT MSVC)
   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
 endif()
 
+if(ENABLE_COVERAGE)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
+endif()
+
 include(CTest)
 
 if(NOT MSVC)
-- 
GitLab