-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
203 lines (168 loc) · 6.61 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
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
# you can set this to 1 to see all commands that are being run
VERBOSE ?= 0
ifeq ($(VERBOSE),1)
export Q :=
export VERBOSE := 1
else
export Q := @
export VERBOSE := 0
endif
BUILDRESULTS ?= buildresults
CONFIGURED_BUILD_DEP = $(BUILDRESULTS)/build.ninja
# This skeleton is built for CMake's Ninja generator
export CMAKE_GENERATOR=Ninja
OPTIONS ?=
INTERNAL_OPTIONS =
CPM_CACHE?=$(HOME)/CPM_Cache
ifneq ($(CPM_CACHE),)
INTERNAL_OPTIONS += -DCPM_SOURCE_CACHE=$(CPM_CACHE)
endif
LTO ?= 0
ifeq ($(LTO),1)
INTERNAL_OPTIONS += -DENABLE_LTO=ON
endif
CROSS ?=
ifneq ($(CROSS),)
INTERNAL_OPTIONS += -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/cross/$(CROSS).cmake
endif
NATIVE ?=
ifneq ($(NATIVE),)
INTERNAL_OPTIONS += -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/native/$(NATIVE).cmake
endif
BUILD_TYPE ?=
ifneq ($(BUILD_TYPE),)
INTERNAL_OPTIONS += -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
endif
SANITIZER ?=
ifneq ($(SANITIZER),)
INTERNAL_OPTIONS += -DUSE_SANITIZER=$(SANITIZER)
endif
all: default
.PHONY: default
default: | $(CONFIGURED_BUILD_DEP)
$(Q)ninja -C $(BUILDRESULTS)
.PHONY: test
test: default
$(Q)cd $(BUILDRESULTS); ctest
.PHONY: docs
docs: | $(CONFIGURED_BUILD_DEP)
$(Q)ninja -C $(BUILDRESULTS) docs
.PHONY: package
package: default
$(Q)ninja -C $(BUILDRESULTS) package
$(Q)ninja -C $(BUILDRESULTS) package_source
.PHONY: cppcheck
cppcheck: | $(CONFIGURED_BUILD_DEP)
$(Q) ninja -C $(BUILDRESULTS) cppcheck
.PHONY: cppcheck-xml
cppcheck-xml: | $(CONFIGURED_BUILD_DEP)
$(Q) ninja -C $(BUILDRESULTS) cppcheck-xml
.PHONY: complexity
complexity: | $(CONFIGURED_BUILD_DEP)
$(Q) ninja -C $(BUILDRESULTS) complexity
.PHONY: complexity-xml
complexity-xml: | $(CONFIGURED_BUILD_DEP)
$(Q) ninja -C $(BUILDRESULTS) complexity-xml
.PHONY: complexity-full
complexity-full: | $(CONFIGURED_BUILD_DEP)
$(Q) ninja -C $(BUILDRESULTS) complexity-full
.PHONY: tidy
tidy: $(CONFIGURED_BUILD_DEP)
$(Q) ninja -C $(BUILDRESULTS) tidy
.PHONY: format
format: $(CONFIGURED_BUILD_DEP)
$(Q)ninja -C $(BUILDRESULTS) format
.PHONY : format-patch
format-patch: $(CONFIGURED_BUILD_DEP)
$(Q)ninja -C $(BUILDRESULTS) format-patch
.PHONY: scan-build
scan-build:
$(Q) scan-build cmake -B $(BUILDRESULTS)/scan-build $(OPTIONS) $(INTERNAL_OPTIONS)
$(Q) ninja -C $(BUILDRESULTS)/scan-build
.PHONY: coverage
coverage:
$(Q) cmake -B $(BUILDRESULTS)/coverage -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE_ANALYSIS=ON $(OPTIONS) $(INTERNAL_OPTIONS)
$(Q) ninja -C $(BUILDRESULTS)/coverage
$(Q) cd $(BUILDRESULTS)/coverage; ctest
$(Q) ninja -C $(BUILDRESULTS)/coverage coverage
.PHONY: sloccount
sloccount: $(CONFIGURED_BUILD_DEP)
$(Q) ninja -C $(BUILDRESULTS) sloccount
.PHONY: sloccount-full
sloccount-full: $(CONFIGURED_BUILD_DEP)
$(Q) ninja -C $(BUILDRESULTS) sloccount-full
.PHONY: sloccount-report
sloccount-report: $(CONFIGURED_BUILD_DEP)
$(Q) ninja -C $(BUILDRESULTS) sloccount-report
.PHONY: sloccount-report-full
sloccount-full-report: $(CONFIGURED_BUILD_DEP)
$(Q) ninja -C $(BUILDRESULTS) sloccount-report-full
.PHONY: vale
vale: $(CONFIGURED_BUILD_DEP)
$(Q) ninja -C $(BUILDRESULTS) vale
# Runs whenever the build has not been configured successfully
$(CONFIGURED_BUILD_DEP):
$(Q)cmake -B $(BUILDRESULTS) $(OPTIONS) $(INTERNAL_OPTIONS)
# Manually Reconfigure a target, esp. with new options
.PHONY: reconfig
reconfig:
$(Q) cmake -B $(BUILDRESULTS) $(OPTIONS) $(INTERNAL_OPTIONS)
.PHONY: clean
clean:
$(Q) if [ -d "$(BUILDRESULTS)" ]; then ninja -C $(BUILDRESULTS) clean; fi
.PHONY: distclean
distclean:
$(Q) rm -rf $(BUILDRESULTS)
.PHONY : help
help :
@echo "usage: make [OPTIONS] <target>"
@echo " Options:"
@echo " > VERBOSE Show verbose output for Make rules. Default 0. Enable with 1."
@echo " > BUILDRESULTS Directory for build results. Default buildresults."
@echo " > OPTIONS Configuration options to pass to a build. Default empty."
@echo " > LTO Enable LTO builds. Default 0. Enable with 1."
@echo " > CROSS Enable a Cross-compilation build. "
@echo " Pass the cross-compilation toolchain name without a path or extension."
@echo " Example: make CROSS=cortex-m3"
@echo " For supported toolchains, see cmake/toolchains/cross/"
@echo " > NATIVE Use an alternate toolchain on your build machine. "
@echo " Pass the toolchain name without a path or extension."
@echo " Example: make CROSS=gcc-9"
@echo " For supported toolchains, see cmake/toolchains/native/"
@echo " > CPM_CACHE Specify the path to the CPM source cache."
@echo " Set the variable to an empty value to disable the cache."
@echo " > BUILD_TYPE Specify the build type (default: RelWithDebInfo)"
@echo " Option are: Debug Release MinSizeRel RelWithDebInfo"
@echo " > SANITIZER Compile with support for a Clang/GCC Sanitizer."
@echo " Options are: none (default), address, thread, undefined, memory,"
@echo " leak, and 'address,undefined' as a combined option"
@echo "Targets:"
@echo " default: Builds all default targets ninja knows about"
@echo " test: Build and run unit test programs"
@echo " docs: Generate documentation"
@echo " package: Build the project, generates docs, and create a release package"
@echo " clean: cleans build artifacts, keeping build files in place"
@echo " distclean: removes the configured build output directory"
@echo " reconfig: Reconfigure an existing build output folder with new settings"
@echo "Static Analysis:"
@echo " cppcheck: runs cppcheck"
@echo " cppcheck-xml: runs cppcheck and generates an XML report (for build servers)"
@echo " Code Formating:"
@echo " format: runs clang-format on codebase"
@echo " format-patch: generates a patch file with formatting changes"
@echo " Static Analysis:"
@echo " cppcheck: runs cppcheck"
@echo " cppcheck-xml: runs cppcheck and generates an XML report (for build servers)"
@echo " scan-build: runs clang static analysis"
@echo " complexity: runs complexity analysis with lizard, only prints violations"
@echo " complexity-full: runs complexity analysis with lizard, prints full report"
@echo " complexity-xml: runs complexity analysis with lizard, generates XML report"
@echo " (for build servers)"
@echo " coverage: runs code coverage analysis and generates an HTML & XML reports"
@echo " tidy: runs clang-tidy linter"
@echo " sloccount: Run SLOCCount analysis on project."
@echo " sloccount: Run SLOCCount analysis on project with detailed output."
@echo " sloccount-report: Run SLOCCount analysis on project and save the results to a file."
@echo " sloccount-report-full: Run SLOCCount analysis on project with detailed output"
@echo " save the results to a file."
@echo " vale: Run vale documentation linting."