-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.in
132 lines (100 loc) · 4.68 KB
/
Makefile.in
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
################################################################################
# Makefile for SPH-Qt project #
# #
# Description: Finds all sources, compiles them, creates dependencies #
# files, and links everything. If a dependency has changed, or is #
# missing, the object is recompiled. It also generates MOC files #
# #
# Author: [email protected] #
# #
# Version: 2.1 #
# #
################################################################################
#Main target, name of executable
BIN := sph
#Bullets physics installation path
BT_INSTALL_PATH = @BT_INSTALL_PATH@
#Qt installation path
QT_INSTALL_PATH = @QT_INSTALL_PATH@
#QT MOC compiler
MOC_CC := $(QT_INSTALL_PATH)/bin/moc
#Root directory where to find all sources
ROOT_SRC_DIR := .
#Root directory where to put all compiled objects
ROOT_OBJ_DIR := .obj
#Root directory where to put all moc files
ROOT_MOC_DIR := .moc
#Configure include dirs
QT_INC_DIR = $(QT_INSTALL_PATH)/include
QT_MODULES = QtGui QtCore QtWidgets QtOpenGL
CL_INC_DIR = @CL_INCLUDE_PATH@
BT_INC_DIR = $(BT_INSTALL_PATH)/src/
INC_DIRS := . $(BT_INC_DIR) $(QT_INC_DIR) $(addprefix $(QT_INC_DIR)/,$(QT_MODULES)) $(CL_INC_DIR) $(ROOT_SRC_DIR)/external
#Configure where to put the build.
BUILD_DIR :=
#Default c++ compiler flags that are always used. Additional flags can be sent
#through CXXFLAGS
DEFAULT_CXXFLAGS = -Wall -fPIC -std=c++14 -g
#Define here the dynamic libraries to be linked
LIBS := Qt5OpenGL Qt5Widgets Qt5Gui Qt5Core GL pthread OpenCL clogs stdc++ m
#Define here the dynamic libraries to be linked
BT_STATIC_LIBS := $(addprefix $(BT_INSTALL_PATH)/bin/, libBulletDynamics_gmake_x64_release.a libBulletCollision_gmake_x64_release.a libLinearMath_gmake_x64_release.a)
STATIC_LIBS := $(BT_STATIC_LIBS)
###################################################################################
#Targets and needed files definition
#Find all cpp's inside source root
SRCS := $(shell find $(ROOT_SRC_DIR) -name "*.cpp")
#Exclude tests
SRCS := $(filter-out $(ROOT_SRC_DIR)/test/%,$(SRCS))
#Exclude CPU implementation for now
SRCS := $(filter-out $(ROOT_SRC_DIR)/fluid/simulation/cpu/%,$(SRCS))
#Find all h's inside source root
HDRS := $(shell find $(ROOT_SRC_DIR) -name "*.h")
#MOC files will be named with the same name as headers, but put inside obj root dir
MOCS := $(filter $(ROOT_SRC_DIR)/gui/%,$(HDRS:.h=.moc.cpp))
MOCS := $(patsubst $(ROOT_SRC_DIR)%, $(ROOT_MOC_DIR)%,$(MOCS))
#Object files will be named with the same name as sources, but put inside obj root dir
OBJS := $(patsubst $(ROOT_SRC_DIR)%, $(ROOT_OBJ_DIR)%, $(SRCS:.cpp=.o))
MOC_OBJS := $(patsubst $(ROOT_MOC_DIR)%, $(ROOT_OBJ_DIR)%, $(MOCS:.moc.cpp=.moc.o))
#Dependecies files
DEPS := $(OBJS:.o=.o.d)
#Directories (the sort is used to remove duplicates)
SRC_DIRS := $(sort $(dir $(SRCS)))
OBJ_DIRS := $(patsubst $(ROOT_SRC_DIR)%, $(ROOT_OBJ_DIR)%, $(SRC_DIRS))
MOC_DIRS := $(patsubst $(ROOT_SRC_DIR)%, $(ROOT_MOC_DIR)%, $(SRC_DIRS))
#Compiler flags: include the default flags, user flags and also the
#include dirs flags
INC_DIR_FLAGS := $(addprefix -I, $(INC_DIRS))
FULL_CXXFLAGS := $(DEFAULT_CXXFLAGS) $(CXXFLAGS) $(INC_DIR_FLAGS)
#Linker flags
LDFLAGS := -L$(QT_INSTALL_PATH)/lib -Wl,-rpath,$(QT_INSTALL_PATH) -Wl,-rpath,$(QT_INSTALL_PATH)/lib
LDLIBS := $(addprefix -l, $(LIBS))
BUILD_TARGET := $(BUILD_DIR)$(BIN)
DIRS := $(BUILD_DIR) $(OBJ_DIRS) $(MOC_DIRS)
#Now from here, the rules
.PHONY: all
all: $(BUILD_TARGET)
$(BUILD_TARGET): $(DIRS) $(OBJS) $(MOC_OBJS)
$(CC) $(OBJS) $(MOC_OBJS) $(STATIC_LIBS) $(LDFLAGS) $(LDLIBS) -o $(BUILD_TARGET)
#Include all dependencies generated by compiler
-include $(DEPS)
$(ROOT_OBJ_DIR)/%.o: $(ROOT_SRC_DIR)/%.cpp
$(CXX) $(FULL_CXXFLAGS) -c $< -o $@
@$(CXX) -MM $(FULL_CXXFLAGS) $< > [email protected]
@sed -e 's|.*:|$@:|' < [email protected] > [email protected]
@sed -e 's/.*://' -e 's/\\$$//' < [email protected] | fmt -1 | \
sed -e 's/^ *//' -e 's/$$/:/' >> [email protected]
@rm -f [email protected]
$(ROOT_OBJ_DIR)/%.moc.o: $(ROOT_MOC_DIR)/%.moc.cpp
$(CXX) $(FULL_CXXFLAGS) -c $< -o $@
$(ROOT_MOC_DIR)/%.moc.cpp: $(ROOT_SRC_DIR)/%.h
$(MOC_CC) $(INC_DIR_FLAGS) $< -o $@
$(DIRS):
@mkdir -p $@
clean:
$(RM) $(OBJS) $(DEPS)
$(RM) $(DIRS) -r
# For debug only: make print-VAR will print VAR on the console
print-%:
@echo '$*=$($*)'