-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
62 lines (48 loc) · 1.51 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
# Compiler and flags
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
CXX = clang++
else
CXX = g++
endif
CXXFLAGS = -std=c++17 -Wall -Wextra -Iinclude `pkg-config --cflags opencv4` -I/opt/homebrew/include
LDFLAGS = `pkg-config --libs opencv4` -L/opt/homebrew/lib -lavcodec -lavformat -lavutil -lswscale
# Directories
SRC_DIR = imgutil
TEST_DIR = tests
BUILD_DIR = build
BIN_DIR = bin
# Executable target
EXECUTABLE = $(BIN_DIR)/app
# Find all source and test files
SRC_FILES = $(shell find $(SRC_DIR) -name '*.cpp')
TEST_FILES = $(shell find $(TEST_DIR) -name '*.cpp')
# Object files
OBJ_FILES = $(patsubst $(SRC_DIR)/%.cpp, $(BUILD_DIR)/%.o, $(SRC_FILES))
TEST_OBJ_FILES = $(patsubst $(TEST_DIR)/%.cpp, $(BUILD_DIR)/%.o, $(TEST_FILES))
# Default target
all: $(EXECUTABLE)
# Build the main executable
$(EXECUTABLE): $(OBJ_FILES)
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
# Build object files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -c -o $@ $<
# Compile test files into object files (if needed for a test executable)
$(BUILD_DIR)/%.o: $(TEST_DIR)/%.cpp
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -c $< -o $@
# Clean build artifacts
clean:
rm -rf $(BUILD_DIR) $(BIN_DIR)
# Run tests (example placeholder, assuming test framework like Catch2 or Google Test)
test: $(TEST_OBJ_FILES) $(OBJ_FILES)
@mkdir -p $(BIN_DIR)
$(CXX) $(CXXFLAGS) $^ -o $(BIN_DIR)/tests $(LDFLAGS)
$(BIN_DIR)/tests
# Run the application
run: $(EXECUTABLE)
./$(EXECUTABLE)
.PHONY: all clean test