-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile.in
240 lines (175 loc) · 6.74 KB
/
Makefile.in
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# This is a template for project build automation with make.
# The actual build system in use if CMake.
# This file is not meant to be used directly. Please generate a working Makefile for your system via configure script:
# ./configure [configuration options]
# Project directory layout
BUILD_DIR = build
ANALYZE_DIR = build-analyze
INCLUDE_DIR = include
SRC_DIR = src
TEST_DIR = test
MODULE_HEADERS = ${INCLUDE_DIR}/*
MODULE_SRC = ${SRC_DIR}/*
MODULE_TESTS = ${TEST_DIR}/*
DEP_INSTALL = $(BUILD_DIR)/conan.lock
GENERATED_MAKE = $(BUILD_DIR)/CMakeFiles
LIBNAME = lib$(PROJECT).a
LIB_TAGRET = $(BUILD_DIR)/lib/$(LIBNAME)
TESTNAME = test_$(PROJECT)
TEST_TAGRET = $(BUILD_DIR)/bin/$(TESTNAME)
DOC_DIR = docs
DOC_TARGET_HTML = $(DOC_DIR)/html
COVERAGE_REPORT = coverage.info
CPPCHECK_VERSION = '2.3'
ifdef sanitize
SANITIZE = ON
else
SANITIZE = OFF
endif
ifdef dbg
BUILD_TYPE = Debug
else
BUILD_TYPE = Release
endif
ifdef coverage
COVERAGE = ON
else
COVERAGE = OFF
endif
ifdef profile
ENABLE_PROFILE = ON
else
ENABLE_PROFILE = OFF
endif
ifdef pkgconfig
PKG_CONFIG = ON
else
PKG_CONFIG = OFF
endif
ifdef CONAN_PROFILE
CONAN_INSTALL_PROFILE = --profile ${CONAN_PROFILE}
endif
# First tagret that starts not with '.'' - is a default target to run
all: lib
#-------------------------------------------------------------------------------
# CMake wrapper
#-------------------------------------------------------------------------------
$(DEP_INSTALL):
mkdir -p $(BUILD_DIR)
conan install -if $(BUILD_DIR) -s build_type=${BUILD_TYPE} . ${CONAN_INSTALL_PROFILE} --build missing
$(GENERATED_MAKE): $(DEP_INSTALL)
cd $(BUILD_DIR) && cmake -G ${GENERATOR} -DPROFILE=${ENABLE_PROFILE} -DCOVERAGE=${COVERAGE} -DSANITIZE=${SANITIZE} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DPKG_CONFIG=${PKG_CONFIG} ..
#-------------------------------------------------------------------------------
# Build the project
#-------------------------------------------------------------------------------
.PHONY: $(LIB_TAGRET)
$(LIB_TAGRET): $(GENERATED_MAKE) $(MODULE_SRC)
cd $(BUILD_DIR) && cmake --build . -j --target $(PROJECT)
lib: $(LIB_TAGRET)
#-------------------------------------------------------------------------------
# Build unit tests
#-------------------------------------------------------------------------------
.PHONY: $(TEST_TAGRET)
$(TEST_TAGRET): $(GENERATED_MAKE) $(MODULE_TESTS)
cd $(BUILD_DIR) && cmake --build . -j --target $(TESTNAME)
tests: $(LIB_TAGRET) $(TEST_TAGRET)
.PHONY: test
test: tests
./$(TEST_TAGRET)
#-------------------------------------------------------------------------------
# Build examples
#-------------------------------------------------------------------------------
.PHONY: examples
examples: $(LIB_TAGRET)
cd $(BUILD_DIR) && cmake --build . -j --target examples
#-------------------------------------------------------------------------------
# Build docxygen documentation
#-------------------------------------------------------------------------------
$(DOC_TARGET_HTML):
doxygen $(DOC_DIR)/Doxyfile
# Build project doxygen docs doxyfile.inc
doc: $(MODULE_HEADERS) $(MODULE_SRC) $(DOC_TARGET_HTML)
#-------------------------------------------------------------------------------
# Code Quality Assurance
#-------------------------------------------------------------------------------
ANALYZE_MAKE: $(ANALYZE_DIR)
mkdir -p $(ANALYZE_DIR)
cd $(ANALYZE_DIR) && cmake -DCMAKE_C_COMPILER=$(shell which scan-build) ..
tools/cppcheck:
# Getting latest cppcheck
# Fix cppcheck version to as master may be is borked sometimes
git clone -b ${CPPCHECK_VERSION} --single-branch --depth 1 https://github.com/danmar/cppcheck.git tools/cppcheck
tools/cppcheck/cppcheck: tools/cppcheck
$(MAKE) -j2 -C tools/cppcheck cppcheck
# TODO: Extra cppcheck options to consider: --enable=style,unusedFunction --inconclusive
# note: don't use --enable=all, 'cause `style` is too verbose
.PHONY: cppcheck
cppcheck: $(MODULE_HEADERS) $(MODULE_SRC) tools/cppcheck/cppcheck
tools/cppcheck/cppcheck --std=c++20 -D __linux__ -D __x86_64__ --inline-suppr -q --error-exitcode=2 \
--enable=warning,performance,portability,information,missingInclude \
--report-progress \
-I include -i test/ci ${SRC_DIR} ${TEST_DIR} examples
.PHONY: cpplint
cpplint: $(MODULE_HEADERS) $(MODULE_SRC)
cpplint --recursive --exclude=${TEST_DIR}/ci/* ${INCLUDE_DIR} ${SRC_DIR} ${TEST_DIR}
scan-build: ANALYZE_MAKE
cd $(ANALYZE_DIR) && scan-build $(MAKE)
tidy:
clang-tidy -checks=llvm-*,modernize-*,clang-analyzer-*,-modernize-pass-by-value -header-filter=.* \
${SRC_DIR}/*.cpp -- -I${INCLUDE_DIR} -std=c++17
.PHONY: codecheck
codecheck: cpplint cppcheck #scan-build
#-------------------------------------------------------------------------------
# Runtime Quality Control
#-------------------------------------------------------------------------------
valgrind-memcheck: $(TEST_TAGRET)
valgrind --tool=memcheck --trace-children=yes --track-fds=yes --redzone-size=128 --error-exitcode=3 \
--leak-check=full --track-origins=yes --show-reachable=yes --show-leak-kinds=all --errors-for-leak-kinds=all --partial-loads-ok=no \
$(TEST_TAGRET)
# Plugin more valgrind checks when they are available
.PHONY: verify
verify: valgrind-memcheck
$(COVERAGE_REPORT): $(TEST_TAGRET)
ifeq ($(COVERAGE), OFF)
$(error Coverage info generation is not configured. Run ./configure --enable-coverage to enable)
else
./$(TEST_TAGRET)
# capture coverage info
lcov --directory . --capture --output-file $@
# filter out system and test code
lcov --remove coverage.info 'test/*' '/usr/*' 'external/*' --output-file $@
endif
coverage: $(COVERAGE_REPORT)
coverage_report: $(COVERAGE_REPORT)
lcov --list $(COVERAGE_REPORT)
#-------------------------------------------------------------------------------
# Install
#-------------------------------------------------------------------------------
.PHONY: install
install: $(LIB_TAGRET)
cd $(BUILD_DIR) && cmake \
-DCMAKE_INSTALL_PREFIX=$(PREFIX) \
-DSANITIZE=${SANITIZE} \
..
#cd $(BUILD_DIR) && cmake --build . --target install --config ${BUILD_TYPE}
$(MAKE) -C $(BUILD_DIR) install DESTDIR=$(DESTDIR)
.PHONY: uninstall
uninstall:
$(RM) -f $(DESTDIR)$(PREFIX)/lib/$(LIBNAME)
$(RM) -rf $(DESTDIR)$(PREFIX)/include/$(PROJECT)
#-------------------------------------------------------------------------------
# Packaging
#-------------------------------------------------------------------------------
.PHONY: debian
debian:
dpkg-buildpackage -d
.PHONY: debian-clean
debian-clean:
dpkg-buildpackage -d -T clean
#-------------------------------------------------------------------------------
# Cleanup
#-------------------------------------------------------------------------------
.PHONY: clean
clean:
$(RM) -rf $(DOC_TARGET_HTML) $(BUILD_DIR) $(COVERAGE_REPORT)
$(RM) tools/cppcheck/cppcheck