-
Notifications
You must be signed in to change notification settings - Fork 120
/
Makefile
217 lines (163 loc) · 6.75 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# ====================
# LIBRARY DEFINITIONS
# ====================
TARGET= vis
TEST_TARGET= run_tests
PERF_TEST_TARGET= run_perf_tests
###############################################################################
## SETTINGS ##
###############################################################################
CLANG := $(shell which clang)
CCACHE := $(shell which ccache)
OS= $(shell uname)
#prefer clang over g++
ifdef VIS_COMPILER
CXX=$(VIS_COMPILER)
endif
ifndef PREFIX
PREFIX=/usr/local/bin/
endif
DIR=$(shell pwd)
BUILD_DIR = $(DIR)/build
BUILD_TEST_DIR = $(DIR)/build_tests
BUILD_PERF_TEST_DIR = $(DIR)/build_perf_tests
# Override optimizations via: make OPT_LEVEL=n
OPT_LEVEL = 3
# Make-local Compiler Flags
CXX_FLAGS = -std=c++14
CXX_FLAGS += -O$(OPT_LEVEL)
CXX_FLAGS += -march=native
CXX_FLAGS += -ffast-math
CXX_FLAGS += -fno-omit-frame-pointer
CXX_FLAGS += -D__extern_always_inline=inline
TEST_CCACHE_CLANG=ccache clang++
TEST_CLANG=clang++
ALL_WARNINGS=-Werror -Weverything -Wno-variadic-macros -Wno-format-nonliteral -Wno-global-constructors -Wno-exit-time-destructors -Wno-padded -Wno-reserved-id-macro -Wno-gnu-zero-variadic-macro-arguments -Wno-c++98-compat
# Only turn on extra warnings for clang since g++ does not support -Weverything
ifeq ($(CXX),$(TEST_CLANG))
CXX_FLAGS += $(ALL_WARNINGS)
else
ifeq ($(CXX),$(TEST_CCACHE_CLANG))
CXX_FLAGS += $(ALL_WARNINGS)
endif
endif
#perf tests should not have many warnings or error out on warning
PERF_TEST_CXX_FLAGS = -std=c++14
PERF_TEST_CXX_FLAGS += -O$(OPT_LEVEL)
PERF_TEST_CXX_FLAGS += -march=native
PERF_TEST_CXX_FLAGS += -ffast-math
PERF_TEST_CXX_FLAGS += -fno-omit-frame-pointer
PERF_TEST_CXX_FLAGS += -ggdb -g2
ifeq ($(OS),Darwin)
CXX_FLAGS += -dynamic -D_OS_OSX -D_XOPEN_SOURCE_EXTENDED
else
CXX_FLAGS += -D_LINUX
endif
# Linker flags
LD_FLAGS = $(LDFLAGS) -fno-omit-frame-pointer
PERF_TEST_LD_FLAGS = -fno-omit-frame-pointer
ifeq ($(OS),Darwin)
LD_FLAGS += -D_XOPEN_SOURCE_EXTENDED
endif
# DEBUG Settings
ifdef DEBUG
OPT_LEVEL=0
CXX_FLAGS += -ggdb -g2 -DVIS_LOG_DEBUG
LD_FLAGS += -DVIS_LOG_DEBUG
endif
# Clang sanitize options
ifdef SANITIZE
#to get symbols from clang sanitize, run "export ASAN_SYMBOLIZER_PATH=<path_to_llvm_symbolizer>" on Arch Linux symbolizer is usually at"/usr/bin/llvm-symbolizer"
CXX_FLAGS += -fsanitize=$(SANITIZE)
LD_FLAGS += -fsanitize=$(SANITIZE)
endif
# Include Paths
INCLUDE_PATH = -I/usr/local/include -I$(DIR)/include -I$(DIR)/src
TEST_INCLUDE_PATH = -I/usr/include
PERF_TEST_INCLUDE_PATH = -I/usr/include
# Lib Paths
LIB_PATH = -L/usr/local/lib
# Libs
LIBS = -lfftw3 -lm -lstdc++
TEST_LIBS = -lgtest -lpthread
PERF_TEST_LIBS = -lbenchmark -lpthread
#if this box has an older version of ncurses
ifneq ("$(wildcard /usr/include/ncursesw/ncurses.h)","")
LIBS += -lncursesw
CXX_FLAGS += -DNCURSESW
LD_FLAGS += -DNCURSESW
else
LIBS += -lncurses
endif
#use jemalloc if available
ifneq ("$(wildcard /usr/lib/libjemalloc.so)","")
LIBS += -ljemalloc
endif
#clang tidy checks
CLANG_TIDY_CHECKS=clang-analyzer-*,modernize-*,readability-*,misc-*,cppcoreguidelines-*,google-*,-google-readability-namespace-comments
###############################################################################
## OBJECTS ##
###############################################################################
SOURCES= $(wildcard src/*.cpp) $(wildcard src/*/*.cpp) $(wildcard src/*/*/*.cpp)
HEADERS= $(wildcard include/*.h) $(wildcard include/*/*.h) $(wildcard src/*.h) $(wildcard src/*/*.h) $(wildcard src/*/*/*.h)
OBJECTS= $(addprefix $(BUILD_DIR)/,$(notdir $(SOURCES:.cpp=.o)))
TEST_SOURCES= $(wildcard tests/*.cpp) $(wildcard tests/*/*.cpp) $(wildcard tests/*/*/*.cpp)
TEST_OBJECTS= $(addprefix $(BUILD_TEST_DIR)/,$(notdir $(TEST_SOURCES:.cpp=.o))) $(filter-out $(BUILD_DIR)/$(TARGET).o,$(OBJECTS))
PERF_TEST_SOURCES= $(wildcard perf_tests/*.cpp) $(wildcard perf_tests/*/*.cpp) $(wildcard perf_tests/*/*/*.cpp)
PERF_TEST_OBJECTS= $(addprefix $(BUILD_PERF_TEST_DIR)/,$(notdir $(PERF_TEST_SOURCES:.cpp=.o))) $(filter-out $(BUILD_DIR)/$(TARGET).o,$(OBJECTS))
VPATH= $(dir $(wildcard src/*/ src/*/*/)) $(dir $(wildcard tests/*/ tests/*/*/)) $(dir $(wildcard perf_tests/*/ perf_tests/*/*/))
###############################################################################
## MAIN TARGETS ##
###############################################################################
all: prepare build
test: tests
tests: prepare_tests build_tests
perf_tests: prepare_perf_tests build_perf_tests
.PHONY: prepare
prepare:
mkdir -p $(BUILD_DIR)
rm -f $(BUILD_DIR)/$(TARGET)
.PHONY: prepare_tests
prepare_tests:
mkdir -p $(BUILD_TEST_DIR)
rm -f $(BUILD_TEST_DIR)/$(TEST_TARGET)
.PHONY: prepare_perf_tests
prepare_perf_tests:
mkdir -p $(BUILD_PERF_TEST_DIR)
rm -f $(BUILD_PERF_TEST_DIR)/$(PERF_TEST_TARGET)
.PHONY: build
build: $(OBJECTS) $(TARGET)
.PHONY: build build_tests run_tests
build_tests: $(TEST_OBJECTS) $(TEST_TARGET)
.PHONY: build build_perf_tests run_perf_tests
build_perf_tests: $(PERF_TEST_OBJECTS) $(PERF_TEST_TARGET)
.PHONY:clean
clean:
@rm -rf $(BUILD_DIR)
@rm -rf $(BUILD_TEST_DIR)
@rm -rf $(BUILD_PERF_TEST_DIR)
uninstall:
@rm -f $(BUILD_DIR)/$(TARGET)
install:
cp $(BUILD_DIR)/$(TARGET) $(PREFIX)
###############################################################################
## BUILD TARGETS ##
###############################################################################
$(BUILD_DIR)/%.o: %.cpp
$(CXX) $(CXX_FLAGS) $(LD_FLAGS) $(INCLUDE_PATH) -c $< -o $@
$(TARGET): $(OBJECTS)
$(CXX) $(CXX_FLAGS) $(LDFLAGS) $(INCLUDE_PATH) $(LIB_PATH) -o $(BUILD_DIR)/$(TARGET) $(OBJECTS) $(LIBS)
$(BUILD_TEST_DIR)/%.o: %.cpp
$(CXX) $(CXX_FLAGS) $(LD_FLAGS) $(INCLUDE_PATH) $(TEST_INCLUDE_PATH) -c $< -o $@
$(TEST_TARGET): $(OBJECTS) $(TEST_OBJECTS)
$(CXX) $(CXX_FLAGS) $(LDFLAGS) $(INCLUDE_PATH) $(TEST_INCLUDE_PATH) $(LIB_PATH) -o $(BUILD_TEST_DIR)/$(TEST_TARGET) $(TEST_OBJECTS) $(LIBS) $(TEST_LIBS)
$(BUILD_TEST_DIR)/$(TEST_TARGET)
$(BUILD_PERF_TEST_DIR)/%.o: %.cpp
$(CXX) $(PERF_TEST_CXX_FLAGS) $(PERF_TEST_LD_FLAGS) $(INCLUDE_PATH) $(PERF_TEST_INCLUDE_PATH) -c $< -o $@
$(PERF_TEST_TARGET): $(OBJECTS) $(PERF_TEST_OBJECTS)
$(CXX) $(PERF_TEST_CXX_FLAGS) $(PERF_TEST_LD_FLAGS) $(INCLUDE_PATH) $(PERF_TEST_INCLUDE_PATH) $(LIB_PATH) -o $(BUILD_PERF_TEST_DIR)/$(PERF_TEST_TARGET) $(PERF_TEST_OBJECTS) $(LIBS) $(PERF_TEST_LIBS)
$(BUILD_PERF_TEST_DIR)/$(PERF_TEST_TARGET)
clang_tidy: $(HEADERS) $(SOURCES) $(TEST_SOURCES) $(PERF_TEST_SOURCES)
clang-tidy -checks=${CLANG_TIDY_CHECKS} $? -- -x c++ -std=c++14 -I$(INCLUDE_PATH)
clang_format: $(HEADERS) $(SOURCES) $(TEST_SOURCES) $(PERF_TEST_SOURCES)
clang-format -i $?