-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
180 lines (140 loc) · 3.46 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
INC:=include
SRC:=src
BLD:=build
OUT:=out
# general includes
INCLUDES= \
-I $(INC) \
-isystem third_party/argparse/include \
-isystem third_party/range-v3/include \
-isystem third_party/gttl/include \
# includes for tests only
INCLUDES_TEST = \
# GCC
CPP=g++
CPP_FLAGS= \
-Wall \
-Wextra \
-pedantic \
-Wnon-virtual-dtor \
-Wold-style-cast \
-Wunused \
-Woverloaded-virtual \
-Wimplicit-fallthrough \
-std=c++20 \
-g \
-fopenmp \
$(INCLUDES)\
CPP_PROFILE_FLAGS=$(CPP_FLAGS) -pg
# CLANG
# CPP=clang++
# CPP_FLAGS= \
# -Wall \
# -Wextra \
# -pedantic \
# -Wnon-virtual-dtor \
# -Wold-style-cast \
# -Wunused \
# -Woverloaded-virtual \
# -Wimplicit-fallthrough \
# -Wdocumentation \
# -std=c++20 \
# -g \
# -fopenmp=libomp \
# $(INCLUDES)\
# includes for tests only
CPP_FLAGS_TEST = \
$(CPP_FLAGS) \
$(INCLUDES_TEST) \
DEBUG ?= 0
ifeq ($(DEBUG), 1)
CPP_FLAGS += -O0 -DDEBUG
BLD:=$(BLD)/debug
else
CPP_FLAGS += -O3 -march=native
endif
### DEFAULT ###
.PHONY: default
.DEFAULT_GOAL=default
default: test run_examples
### ALL ###
.PHONY: all
all: test doc run_examples
### VALIDATE ###
.PHONY: validate
validate: test examples doc run_examples check_tidy
### CLEAN ##
.PHONY:clean
clean:
rm -rf build/*
rm -rf doc/*
.PHONY: delete_dependency_files
delete_dependency_files:
find $(BLD) -name '*.d' -delete
### DOCUMENTATION ###
.PHONY: doc
doc:
@mkdir -p doc
doxygen Doxyfile.in
### TESTS ###
TEST_SOURCES = $(shell find $(SRC)/test -name '*.cpp')
TEST_DEPENDS = $(TEST_SOURCES:$(SRC)/%.cpp=$(BLD)/%.d)
TEST_BINARIES = $(TEST_SOURCES:$(SRC)/%.cpp=$(BLD)/%)
TESTS = $(filter $(BLD)/test/%, $(TEST_BINARIES))
.PHONY: test
test: $(TESTS);
@# loop is exited after first failure
@set -e; for T in $(TESTS); do echo "test: $$T"; $$T -l warning; done
$(TEST_DEPENDS): $(BLD)/%.d: $(SRC)/%.cpp
@mkdir -p $(@D) # provide parent directory of target
$(CPP) $(CPP_FLAGS_TEST) -MM -MQ $@ -o $@ $<
$(TESTS): $(BLD)/%: $(SRC)/%.cpp $(BLD)/%.d
@mkdir -p $(@D) # provide parent directory of target
$(CPP) $(CPP_FLAGS_TEST) -o $@ $<
# import dependencies for all target binaries (if possible)
-include $(TEST_DEPENDS)
### EXAMPLES ###
EXAMPLE_SOURCES = $(shell find $(SRC)/examples -name '*.cpp')
EXAMPLE_DEPENDS = $(EXAMPLE_SOURCES:$(SRC)/%.cpp=$(BLD)/%.d)
EXAMPLE_BINARIES = $(EXAMPLE_SOURCES:$(SRC)/%.cpp=$(BLD)/%)
EXAMPLES = $(filter $(BLD)/examples/%, $(EXAMPLE_BINARIES))
$(EXAMPLE_DEPENDS): $(BLD)/%.d: $(SRC)/%.cpp
@mkdir -p $(@D) # provide parent directory of target
$(CPP) $(CPP_FLAGS) -MM -MQ $@ -o $@ $<
$(EXAMPLES): $(BLD)/%: $(SRC)/%.cpp $(BLD)/%.d
@mkdir -p $(@D) # provide parent directory of target
$(CPP) $(CPP_FLAGS) -o $@ $<
# import dependencies for all example binaries (if possible)
-include $(EXAMPLE_DEPENDS)
.PHONY: examples
examples: $(EXAMPLES);
.PHONY: run_examples
run_examples: $(EXAMPLES);
@mkdir -p $(OUT)
@for E in $(EXAMPLES); \
do \
echo "rendering preview for $$E"; \
$$E \
--out $(OUT)/example_$${E##*/}.preview \
#--verbose \
done
ALL_INCLUDE_FILES = $(shell find $(INC) -iname *.hpp -o -iname *.cpp)
ALL_SOURCE_FILES = $(shell find $(SRC) -iname *.hpp -o -iname *.cpp)
### CLANG-TIDY ###
CLANG_TIDY_ARGS=\
--warnings-as-errors="*" \
CLANG_TIDY_COMPILER_ARGS=\
-std=c++20 \
$(INCLUDES) \
.PHONY: run_clang_tidy
run_clang_tidy:
clang-tidy \
$(CLANG_TIDY_ARGS) \
$(ALL_INCLUDE_FILES) \
-- \
$(CLANG_TIDY_COMPILER_ARGS) \
clang-tidy \
$(CLANG_TIDY_ARGS) \
$(ALL_SOURCE_FILES) \
-- \
$(CLANG_TIDY_COMPILER_ARGS) \