forked from mattjr/structured
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
87 lines (64 loc) · 1.73 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
#
# The Makefile calls cmake and make to perform an out-of-source build in the
# directory specified by the BUILD_DIR variable. If the directory does not
# exist it is created.
#
BUILD_DIR = /tmp/$(shell whoami)/$(shell pwd)
SOURCE_DIR = $(shell pwd)
ifndef OSTYPE
OSTYPE = $(shell uname)
endif
# Get the number of processors
ifeq ("$(OSTYPE)","Darwin")
CPU_COUNT=2
else
CPU_COUNT := $(shell cat /proc/cpuinfo | grep -P "processor\t" | wc -l)
ifeq ($(CPU_COUNT),0)
CPU_COUNT=1
endif
endif
# Set the number of build threads to the number of processors
ARGS=-j ${CPU_COUNT}
# Normal build
all: setup
@make ${ARGS} -C $(BUILD_DIR) all
# Other targets. This works for 'make clean' and 'make install'
%: setup
@make ${ARGS} -C $(BUILD_DIR) $@
debug: setup
@cd $(BUILD_DIR); \
cmake $(SOURCE_DIR) -DCMAKE_BUILD_TYPE=Debug
make ${ARGS}
release: setup
@cd $(BUILD_DIR); \
cmake $(SOURCE_DIR) -DCMAKE_BUILD_TYPE=Release
make ${ARGS}
relwithdebinfo: setup
@cd $(BUILD_DIR); \
cmake $(SOURCE_DIR) -DCMAKE_BUILD_TYPE=RelWithDebInfo
make ${ARGS}
minsizerel: setup
@cd $(BUILD_DIR); \
cmake $(SOURCE_DIR) -DCMAKE_BUILD_TYPE=MinSizeRel
make ${ARGS}
test: setup
@cd $(BUILD_DIR); \
ctest .
doc: setup
doxygen doc/doxygen.cfg
setup:
# Clean up if someone has run cmake . for an in-source build
rm -f CMakeCache.txt
# Make sure the directory for an out-of source build exists
# If the build dir exists but the makefile doesn't, rerun cmake
@if test -d $(BUILD_DIR) ; \
then \
if ! test -f $(BUILD_DIR)/Makefile ; then \
cd $(BUILD_DIR); \
cmake $(SOURCE_DIR); \
fi \
else \
mkdir -p $(BUILD_DIR); \
cd $(BUILD_DIR); \
cmake $(SOURCE_DIR); \
fi