From 48deb72574416f431da3e805c52dbc76101e327e Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 7 Jul 2023 21:04:08 +0200 Subject: support code coverage report generation --- Makefile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 8a4c755..7b5a8b9 100644 --- a/Makefile +++ b/Makefile @@ -4,18 +4,21 @@ src_dir := $(abspath .) build_dir := $(src_dir)/build cmake_dir := $(build_dir)/cmake install_dir := $(build_dir)/install +coverage_dir := $(build_dir)/coverage COMPILER ?= clang CONFIGURATION ?= Debug DEFAULT_HOST ?= 127.0.0.1 DEFAULT_PORT ?= 5556 INSTALL_PREFIX ?= $(install_dir) +COVERAGE ?= $(eval $(call noexpand,COMPILER)) $(eval $(call noexpand,CONFIGURATION)) $(eval $(call noexpand,DEFAULT_HOST)) $(eval $(call noexpand,DEFAULT_PORT)) $(eval $(call noexpand,INSTALL_PREFIX)) +$(eval $(call noexpand,COVERAGE)) .PHONY: all all: build @@ -37,6 +40,7 @@ build: -D 'CMAKE_INSTALL_PREFIX=$(call escape,$(INSTALL_PREFIX))' \ -D 'DEFAULT_HOST=$(call escape,$(DEFAULT_HOST))' \ -D 'DEFAULT_PORT=$(call escape,$(DEFAULT_PORT))' \ + -D 'COVERAGE=$(call escape,$(COVERAGE))' \ -S '$(call escape,$(src_dir))' \ -B '$(call escape,$(cmake_dir))' cmake --build '$(call escape,$(cmake_dir))' -- -j @@ -45,6 +49,20 @@ build: release: CONFIGURATION := Release release: build +.PHONY: coverage +coverage: COMPILER := gcc +coverage: CONFIGURATION := Debug +coverage: COVERAGE := 1 +coverage: clean build test + @echo ----------------------------------------------------------------- + @echo Generating code coverage report + @echo ----------------------------------------------------------------- + @mkdir -p -- '$(call escape,$(coverage_dir))' + gcovr --html-details '$(call escape,$(coverage_dir))/index.html' --print-summary +ifndef CI + xdg-open '$(call escape,$(coverage_dir))/index.html' &> /dev/null +endif + .PHONY: install install: build cmake --install '$(call escape,$(cmake_dir))' -- cgit v1.2.3