-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
40 lines (28 loc) · 824 Bytes
/
Makefile
File metadata and controls
40 lines (28 loc) · 824 Bytes
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
# Compiler and flags
CXX := g++
CXXFLAGS := -std=c++20 -Ofast -march=native -Wall -Wextra -I./src -I./tests
# Google Test flags (assuming installed globally)
GTEST_LIBS := -lgtest -lgtest_main -pthread
# Directories
SRC_DIR := src
TEST_DIR := tests
BUILD_DIR := build
# Files
SRC_FILES := $(wildcard $(SRC_DIR)/*.cpp)
SRC_NO_MAIN := $(filter-out $(SRC_DIR)/main.cpp, $(SRC_FILES))
TEST_FILES := $(wildcard $(TEST_DIR)/*.cpp)
# Output binaries
MAIN_BIN := $(BUILD_DIR)/main
TEST_BIN := $(BUILD_DIR)/test
.PHONY: all main test clean
all: main
main: $(MAIN_BIN)
$(MAIN_BIN): $(SRC_FILES) | $(BUILD_DIR)
$(CXX) $(CXXFLAGS) -o $@ $^
test: $(TEST_BIN)
$(TEST_BIN): $(SRC_NO_MAIN) $(TEST_FILES) | $(BUILD_DIR)
$(CXX) $(CXXFLAGS) -o $@ $^ $(GTEST_LIBS)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
clean:
rm -rf $(BUILD_DIR)