-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
174 lines (145 loc) · 5.34 KB
/
Makefile
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# This Makefile allows easy execution of the several unittest steps within eclipse.
# "build" / "exec" also allows parsing of the compiler output into the "Problems" view.
#
# Targets
# -------
# create-makefiles-clang create the Ninja makefiles for clang
# create-makefiles-gcc create the Ninja makefiles for gcc
# clean clean $(BUILD_DIR)
# build build the tests specified by $(TARGET) or all
# exec (build and) execute the tests specified by $(TARGET) or all
# coverage-clang collect coverage information for clang objects
# coverage-gcc-gcovr collect coverage information for gcc objects
#
# Parameters
# ----------
# cmake_opt options for cmake execution
# ctest_opt options for ctest execution
# target name of the executable to build / execute
#
# Cygwin / MSYS / Linux
# ---------------------
# The above "UNAME" and "MSYS_ROOT" handling is a little bit tricky. It works at least on "rg"s
# machine which has a primary Cygwin installation and uses the BlueCOnnect_Tools make for building.
# Also the paths in e.g. "RM" avoids some mysterious effects. So leave this part alone unless
# there are urgent reasons.
#
.ONESHELL:
ifeq '$(findstring ;,$(PATH))' ';'
UNAME := Windows
else
UNAME := $(shell uname 2>/dev/null || echo Unknown)
UNAME := $(patsubst CYGWIN%,Cygwin,$(UNAME))
UNAME := $(patsubst MSYS%,MSYS,$(UNAME))
UNAME := $(patsubst MINGW%,MSYS,$(UNAME))
endif
ifeq ($(UNAME),Cygwin)
MSYS_ROOT ?= /cygdrive/c/msys64
else
MSYS_ROOT ?= /c/msys64
endif
MSYS_ARCH_FOLDER ?= $(MSYS_ROOT)/mingw32
BUILD_DIR ?= _build
CMAKE_BUILD_TYPE ?= Debug
CMAKE_GENERATOR ?= Ninja
ifeq ($(OS),Windows_NT)
# compiler: ".exe" required for MSYS2-cmake
CLANG := clang.exe
CLANGXX := clang++.exe
GCC := gcc.exe
GCCXX := g++.exe
else
# Linux?
CLANG := clang
CLANGXX := clang++
GCC := gcc
GCCXX := g++
MSYS_ROOT :=
MSYS_ARCH_FOLDER :=
endif
CMAKE := cmake
CTEST := ctest
ECHO := echo
FIND := /usr/bin/find
GCOV := gcov
GREP := grep
LLVM_COV := llvm-cov-14
LLVM_PROFDATA := llvm-profdata-14
RM := /bin/rm
XARGS := /usr/bin/xargs
ifeq ($(UNAME),Linux)
GCOVR := python3 -m gcovr
else
GCOVR := py -3 -m gcovr
endif
PATH_EXT := $(MSYS_ARCH_FOLDER)/bin:$(MSYS_ROOT)/bin:$(MSYS_ROOT)/usr/bin
ifeq ($(UNAME),Linux)
ABS_PWD := $(shell realpath .)
else
ABS_PWD := $(shell /usr/bin/cygpath -ma .)
endif
# create compile_commands.json
CMAKE_BUILD_OPT := -DCMAKE_EXPORT_COMPILE_COMMANDS=1
#
# set the cmake / ctest options
#
CMAKE_OPT ?= $(cmake_opt)
CTEST_OPT ?= $(ctest_opt)
ifneq ($(target),)
CMAKE_OPT += --target $(target)
CTEST_OPT += -R $(target) -V
endif
# works only if there is a _build. But otherwise there is nothing to clean...
.PHONY: clean
clean:
@export PATH=$(PATH_EXT):$$PATH
echo $$PATH
$(CMAKE) --build $(BUILD_DIR) --target clean $(CMAKE_OPT) -- -v
.PHONY: clean-real
clean-real:
@export PATH=$(PATH_EXT):$$PATH
$(RM) -rfv $(BUILD_DIR)
.PHONY: build
build:
@export PATH=$(PATH_EXT):$$PATH
$(CMAKE) --build $(BUILD_DIR) $(CMAKE_OPT) -- -k 0 -v
.PHONY: exec
exec: build
@export PATH=$(PATH_EXT):$$PATH
$(CMAKE) --build $(BUILD_DIR) $(CMAKE_OPT) -- -k 0 -v && \
$(CTEST) --test-dir $(BUILD_DIR) --output-on-failure $(CTEST_OPT)
.PHONY: create-makefiles-gcc
create-makefiles-gcc:
@export PATH=$(PATH_EXT):$$PATH
export CC=$(GCC)
export CXX=$(GCCXX)
$(CMAKE) $(CMAKE_BUILD_OPT) -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) -DCMAKE_C_COMPILER=$$CC -DCMAKE_CXX_COMPILER=$$CXX -B $(BUILD_DIR) -G "$(CMAKE_GENERATOR)"
.PHONY: coverage-gcc-gcovr
coverage-gcc-gcovr: exec
@export PATH=$(PATH_EXT):$$PATH
cd $(BUILD_DIR)
$(FIND) . -iname "*.gcda" | $(XARGS) $(GCOV) --branch-counts --branch-probabilities --demangled-names --function-summaries
$(GCOVR) -g --html-details --exclude-unreachable-branches -o index.html -k --decisions -f ".*/games/.*" -f ".*/modules/.*" -f ".*/unittest/[^_].*"
echo ...
echo "open file://$(ABS_PWD)/$(BUILD_DIR)/index.html with browser to view coverage results"
.PHONY: create-makefiles-clang
create-makefiles-clang:
@export PATH=$(PATH_EXT):$$PATH
export CC=$(CLANG)
export CXX=$(CLANGXX)
$(CMAKE) $(CMAKE_BUILD_OPT) -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) -DCMAKE_C_COMPILER=$$CC -DCMAKE_CXX_COMPILER=$$CXX -B $(BUILD_DIR) -G "$(CMAKE_GENERATOR)"
.PHONY: coverage-clang
coverage-clang: exec
@export PATH=$(PATH_EXT):$$PATH
cd $(BUILD_DIR)
EXECS_O=$$($(FIND) . -type f -executable | $(GREP) -v CMakeFiles | $(XARGS) -n 1 $(ECHO) -object)
$(FIND) . -iname "*.profraw" | $(XARGS) $(LLVM_PROFDATA) merge -sparse -o coverage.profdata
$(LLVM_COV) show -format=html -output-dir=. $$EXECS_O -instr-profile=coverage.profdata -ignore-filename-regex='.*/googletest/.*'
# --show-branches=count --show-expansions
echo ...
echo "open file://$(ABS_PWD)/$(BUILD_DIR)/index.html with browser to view coverage results"
.PHONY: check-clang
check-clang:
@export PATH=$(PATH_EXT):$$PATH
cd $(BUILD_DIR)
run-clang-tidy