forked from afrl-rq/OpenUxAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
169 lines (138 loc) · 5.19 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
# Platform
PLATFORM:=$(shell python3 -c "import sys; print(sys.platform)")
# Path to the makefile and containing directory
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
current_dir := $(dir $(mkfile_path))
# Don't autoconfigure the build environment if this Makefile is invoked by anod
ifneq ($(SKIP_ANOD_SETUP),true)
# Anod search path
ANOD_PATH:=$(current_dir)
# Anod binary
ANOD_BIN:=$(ANOD_PATH)/anod
# Check if anod is available and export the uxas build environment if so
ifneq (,$(wildcard $(ANOD_BIN)))
ANODENV:=$(shell NO_INSTALL_VENV=1 $(ANOD_BIN) printenv uxas --build-env --inline)
else
ANODENV:=
endif
endif
# Control whether full command line should be displayed during compilation
DEBUG_BUILD=false
# Root directory in which the object and the final executable will be created
OBJECT_DIR=obj/cpp
# Root directory under which the source files live
SOURCE_DIR=src/cpp
# Source directories for the uxas project
SOURCE_DIRS:=$(SOURCE_DIR)/Communications \
$(SOURCE_DIR)/Communications/ZeroMq/Proxy \
$(SOURCE_DIR)/Communications/ZeroMq/Receivers \
$(SOURCE_DIR)/Communications/ZeroMq/Senders \
$(SOURCE_DIR)/Communications/ZeroMq/Sockets \
$(SOURCE_DIR)/Communications/ZeroMq \
$(SOURCE_DIR)/Includes \
$(SOURCE_DIR)/Services \
$(SOURCE_DIR)/Tasks \
$(SOURCE_DIR)/DPSS \
$(SOURCE_DIR)/Plans \
$(SOURCE_DIR)/Utilities \
$(SOURCE_DIR)/VisilibityLib \
resources/AutomationDiagramDataService
# Compiler to be used - note the prefixed anod env here
CXX=$(ANODENV)g++
# Default C++ compilation flags
CXX_FLAGS:=-fPIC -std=c++11
# Note: we suppress boost deprecation warnings because they are triggering only
# on boost-internal headers.
CXX_FLAGS+=-DBOOST_ALLOW_DEPRECATED_HEADERS
# Note: also suppress the warning about geometry needing C++14. This means we
# need to change language versions if we update boost or we don't update
# boost
CXX_FLAGS+=-DBOOST_GEOMETRY_DISABLE_DEPRECATED_03_WARNING
# Enable all warnings
ifeq ($(ENABLE_WARNINGS),true)
CXX_FLAGS+=-Wall
endif
# Enable coverage with gcov
ifeq ($(ENABLE_COVERAGE),true)
CXX_FLAGS+=-fprofile-arcs -ftest-coverage -DGCOV_MODE=1
endif
# Linker flags
ifeq ($(PLATFORM),linux)
LINKER_FLAGS:=-std=c++11 -llmcp -lzyre -lpugixml -lboost_filesystem \
-lboost_regex -lboost_date_time -lboost_system -lSQLiteCpp -lsqlite3 \
-lczmq -luuid -lserial -lzmq -ldl -lpthread -static-libstdc++ -static-libgcc
else
LINKER_FLAGS:=-std=c++11 -llmcp -lzyre -lpugixml -lboost_filesystem \
-lboost_regex -lboost_date_time -lboost_system -lSQLiteCpp -lsqlite3 \
-lczmq -lserial -lzmq -ldl -lpthread
endif
# Include flags
INCLUDES=$(foreach source_dir, $(SOURCE_DIRS), -I$(source_dir))
# The list of sources
SOURCES:=$(foreach source_dir, $(SOURCE_DIRS), $(wildcard $(source_dir)/*.cpp))
# The list of non relocated object files
OBJECTS_BASE:=$(patsubst %.cpp,%.o,$(SOURCES))
# The final location of all objects
OBJECTS:=$(foreach object, $(OBJECTS_BASE),$(OBJECT_DIR)/$(object))
# The list of Makefile fragments containing the dependencies
DEPS:=$(patsubst %.o,%.o.d,$(OBJECTS))
# COMPILE_CXX(object_file, source_file)
#
# Compile a C++ source and generate Makefile dependencies
#
define COMPILE_CXX
@mkdir -p `dirname $1`
@echo "[Compiling $2]"
@if test "$(DEBUG_BUILD)" = "true"; then \
echo "$(CXX) $(CXX_FLAGS) $(INCLUDES) -MM -MT $1 $2 -MF $1.d"; \
fi
@$(CXX) $(CXX_FLAGS) $(INCLUDES) -MM -MT $1 $2 -MF $1.d
@if test "$(DEBUG_BUILD)" = "true"; then \
echo "$(CXX) -c $2 $(INCLUDES) $(CXX_FLAGS) -o $1"; \
fi
@$(CXX) -c $2 $(INCLUDES) $(CXX_FLAGS) -o $1
endef
# GENERATE_COMPILER_RULE(object_file, source_file)
#
# Generate a makefile rule to compile a C++ source
#
define GENERATE_COMPILE_RULE
$(OBJECT_DIR)/$1: $2
$$(call COMPILE_CXX,$$@,$$<)
endef
# Toplevel targets
help:
@echo "This makefile compiles the uxas main executable"
@echo
@echo "It assumes that thirdparties libraries and their respective include files"
@echo "are available in the environment (either in the system paths or using"
@echo "environment variables)"
@echo
@echo "Available targets:"
@echo " all: Compile the project"
@echo " clean: Clean all build artefacts"
@echo " help: This target"
@echo
@echo "User variables:"
@echo " DEBUG_BUILD: if 'true' then display full compilation command line"
@echo " OBJECT_DIR: root directory containing objects and executable (default: 'obj')"
@echo " ENABLE_WARNINGS: if 'true' enable all C++ warnings"
@echo " ENABLE_COVERAGE: if 'true' compile uxas with gcov enabled"
clean:
@echo "[Remove objects]"
rm -f $(OBJECTS)
rm -rf $(OBJECT_DIR)/uxas
@echo "[Remove makefile fragments (dependencies)]"
rm -f $(DEPS)
all: $(OBJECT_DIR)/uxas
@echo "[Project compiled]"
# Main compilation and link
$(OBJECT_DIR)/uxas.o: $(SOURCE_DIR)/UxAS_Main.cpp
$(call COMPILE_CXX,$@,$<)
$(OBJECT_DIR)/uxas: $(OBJECT_DIR)/uxas.o $(OBJECTS)
@echo "[Link uxas main]"
@$(CXX) -o $@ $^ $(LINKER_FLAGS) $(CXX_FLAGS)
# Create a compilation rule for each source found
$(foreach object, $(OBJECTS_BASE), $(eval $(call GENERATE_COMPILE_RULE,$(object),$(patsubst %.o,%.cpp, $(object)))))
# Include the Makefile fragments containing the dependencies
-include $(DEPS)