-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
60 lines (48 loc) · 1.5 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
.PHONY = build clean
# Make all recipes begin with the > character rather than a tab.
.RECIPEPREFIX := >
TARGET_EXEC := BGP_simulation
BUILD_DIR := cmake-release
DEBUG_DIR := cmake-debug
# You can set these variables from the command line, and also from the environment.
DEBUG ?= # Put 1 to enable
IWYU ?= # Put 1 to enable
# Use Clang
export CC := clang
export CXX := clang++
export CMAKE_C_COMPILER := clang
export CMAKE_CXX_COMPILER := clang++
# Generate the build files
$(BUILD_DIR)/Makefile: CMakeLists.txt
> @echo;
> @echo "[.] Generating build files...";
> cmake -DTARGET_EXEC:STRING=$(TARGET_EXEC) -S . -B $(BUILD_DIR)
$(DEBUG_DIR)/Makefile: CMakeLists.txt
> @echo;
> @echo "[.] Generating debug build files...";
> cmake -DTARGET_EXEC:STRING=$(TARGET_EXEC) -S . -B $(DEBUG_DIR)
# Compile
ifeq ($(DEBUG), 1)
CHOOSEN_DIR := $(DEBUG_DIR)
else
CHOOSEN_DIR := $(BUILD_DIR)
endif
build: $(CHOOSEN_DIR)/Makefile
> @echo;
> @echo "[.] Building program";
ifeq ($(IWYU), 1)
> @echo "[.] Using Include What You Use (IWYU)...";
> @cmake -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="iwyu;-Xiwyu;--no_fwd_decls" $(CHOOSEN_DIR)
endif
ifeq ($(DEBUG), 1)
> @echo "[.] Enabling DEBUG mode...";
> @cmake -DUSE_DEBUG=ON $(CHOOSEN_DIR)
> @cmake -DCMAKE_BUILD_TYPE=Debug $(CHOOSEN_DIR)
endif
> @cmake --build $(CHOOSEN_DIR)
# Cleanup
clean:
> @echo
> @echo "[.] Cleaning up...";
> rm -rf $(BUILD_DIR);
> rm -rf $(DEBUG_DIR);