-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
55 lines (41 loc) · 1.11 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
# Compiler and flags
CXX = g++
CXXFLAGS = -std=c++14 -Wall -g
TEST_FLAGS = -pthread -lOpenCL -lgtest_main -lgtest -lgmock_main -lgmock
# Directories
SRC_DIR = src/cpp/core
TEST_DIR = tests/cpp
OBJ_DIR = obj
BIN_DIR = bin
# Source and test files
SRC_FILES = $(wildcard $(SRC_DIR)/*.cpp)
TEST_FILES = $(wildcard $(TEST_DIR)/*.cpp)
# Object files
SRC_OBJ = $(SRC_FILES:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
TEST_OBJ = $(TEST_FILES:$(TEST_DIR)/%.cpp=$(OBJ_DIR)/%.o)
# Final test executable
TEST_EXEC = $(BIN_DIR)/run_tests
# Default target
all: $(TEST_EXEC)
# Create necessary directories
$(OBJ_DIR):
mkdir -p $(OBJ_DIR)
$(BIN_DIR):
mkdir -p $(BIN_DIR)
# Compile source files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -c $< -o $@
# Compile test files
$(OBJ_DIR)/%.o: $(TEST_DIR)/%.cpp | $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -I$(SRC_DIR) -c $< -o $@
# Link everything into test executable
$(TEST_EXEC): $(SRC_OBJ) $(TEST_OBJ) | $(BIN_DIR)
$(CXX) $(CXXFLAGS) $^ $(TEST_FLAGS) -o $@
# Run the tests
.PHONY: test
test: $(TEST_EXEC)
./$(TEST_EXEC)
# Clean build files
.PHONY: clean
clean:
rm -rf $(OBJ_DIR) $(BIN_DIR)