-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
67 lines (55 loc) · 2.69 KB
/
Makefile
File metadata and controls
67 lines (55 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#━━━━━━━━━━Make Configuration━━━━━━━━━━━━━━━━━━━━━━━
.PHONY: test clean coverage valgrind all
.DEFAULT_GOAL := test
#━━━━━━━━━━Compiler and Base Flags━━━━━━━━━━━━━━━━━━
CXX = g++
STD_FLAGS := -std=c++17 -pedantic
WARN_FLAGS := -Werror -Wextra -Wall -Weffc++ -Wconversion -Wsign-conversion -Wpadded
DEPENDENCY_FLAGS := -MMD -MP
INCLUDE_DIRS := -I./src
# DEBUG_FLAG := -g
CXXFLAGS := $(STD_FLAGS) $(WARN_FLAGS) $(DEPENDENCY_FLAGS) $(INCLUDE_DIRS) $(DEBUG_FLAG)
#━━━━━━━━━━Test and Coverage Configuration━━━━━━━━━━
TESTS_LINKER_FLAGS := -lgtest_main -lgtest -pthread
COVERAGE_FLAGS := -fprofile-arcs -ftest-coverage
GCOVR_THEME := --html-theme github.dark-green
GCOVR_CONFIG_FLAGS := --html --html-single-page=js-enabled --html-details
GCOVR_EXCLUDES := --exclude-unreachable-branches --exclude-throw-branches --exclude-noncode-lines
GCOVR_FLAGS := $(GCOVR_CONFIG_FLAGS) $(GCOVR_EXCLUDES) $(GCOVR_THEME)
VALGRIND_FLAGS := --tool=memcheck --leak-check=full --show-leak-kinds=all --show-reachable=yes --track-origins=yes --verbose
#━━━━━━━━━━Directory Structure━━━━━━━━━━━━━━━━━━━━━━
SRC_DIR := src
TESTS_SRC_DIR := tests
BUILD_DIR := build
TESTS_BUILD_DIR := $(BUILD_DIR)/tests
COVERAGE_DIR := $(BUILD_DIR)/coverage
#━━━━━━━━━━Files and Dependencies━━━━━━━━━━━━━━━━━━━
-include $(TESTS_BUILD_DIR)/*.d
TESTS_SRC_FILES := $(wildcard $(TESTS_SRC_DIR)/*.cc)
TESTS_OBJ_FILES := $(patsubst $(TESTS_SRC_DIR)/%.cc,$(TESTS_BUILD_DIR)/%.o,$(TESTS_SRC_FILES))
#━━━━━━━━━━OS-Specific Configuration━━━━━━━━━━━━━━━━
ifeq ($(shell uname),Darwin)
OPEN_COMMAND := open
else
OPEN_COMMAND := xdg-open
endif
#━━━━━━━━━━Targets━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
test: $(BUILD_DIR)/run_tests
./$(BUILD_DIR)/run_tests
all: coverage valgrind
$(BUILD_DIR)/run_tests: $(TESTS_OBJ_FILES)
$(CXX) $(CXXFLAGS) $^ $(TESTS_LINKER_FLAGS) -o $@
$(TESTS_BUILD_DIR)/%.o: tests/%.cc
@mkdir -p $(TESTS_BUILD_DIR)
$(CXX) $(CXXFLAGS) -c $< -o $@
coverage: CXXFLAGS += $(COVERAGE_FLAGS)
coverage: clean $(BUILD_DIR)/run_tests
mkdir -p $(COVERAGE_DIR)
./$(BUILD_DIR)/run_tests
@gcovr -o $(COVERAGE_DIR)/gcov_report.html $(GCOVR_FLAGS) --exclude $(TESTS_SRC_DIR)
@$(OPEN_COMMAND) $(COVERAGE_DIR)/gcov_report.html &
rm -f *.gcda *.gcno *.gcov
clean:
rm -rf $(BUILD_DIR)
valgrind: $(BUILD_DIR)/run_tests
valgrind $(VALGRIND_FLAGS) ./$(BUILD_DIR)/run_tests