-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
57 lines (43 loc) · 1.67 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
gtest_dir = deps/gtest-1.7.0
cppflags = -isystem $(gtest_dir)/include
cxxflags = -O3 -pthread -Wall -Wextra -std=c++11
gtest_headers = $(gtest_dir)/include/gtest/*.h \
$(gtest_dir)/include/gtest/internal/*.h
build_dir=build
bin_dir=bin
src_dir=src
test_dir=test
tests_src := $(notdir $(shell find $(test_dir) -type f -name *_test.cc))
tests_objects := $(patsubst %.cc,$(build_dir)/%.o,$(tests_src))
tests := $(bin_dir)/test
sources := $(notdir $(shell find $(src_dir) -type f -name "*.h"))
objects := $(patsubst %.h,$(build_dir)/%.o,$(sources))
all : $(bin_dir)/run $(tests)
$(bin_dir)/run : main.cc $(objects)
$(CXX) $(cppflags) $(cxxflags) -lpthread $^ -o $@
test : $(tests)
./$(tests) #--gtest_output=xml:detail_test.xml
clean :
rm -f $(build_dir)/*
rm -f $(bin_dir)/*
$(build_dir)/%.o : $(src_dir)/%.cc $(src_dir)/%.h
$(CXX) $(cppflags) $(cxxflags) -c $< -o $@
## Tests ##
## Tests files ##
$(bin_dir)/test : $(tests_objects) $(objects) $(build_dir)/gtest_main.a
mkdir -p bin
$(CXX) $(cppflags) $(cxxflags) -lpthread $^ -o $@
## GTest tasks ##
gtest_srcs_ = $(gtest_dir)/src/*.cc $(gtest_dir)/src/*.h $(gtest_headers)
$(build_dir)/gtest-all.o : $(gtest_srcs_)
$(CXX) $(cppflags) -I$(gtest_dir) $(cxxflags) -c \
$(gtest_dir)/src/gtest-all.cc -o $@
$(build_dir)/gtest_main.o : $(gtest_srcs_)
$(CXX) $(cppflags) -I$(gtest_dir) $(cxxflags) -c \
$(gtest_dir)/src/gtest_main.cc -o $@
$(build_dir)/gtest.a : $(build_dir)/gtest-all.o
$(AR) $(ARFLAGS) $@ $^
$(build_dir)/gtest_main.a : $(build_dir)/gtest-all.o $(build_dir)/gtest_main.o
$(AR) $(ARFLAGS) $@ $^
$(build_dir)/%_test.o : $(test_dir)/%_test.cc $(objects) $(gtest_headers)
$(CXX) $(cppflags) $(cxxflags) -c $< -o $@