-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
80 lines (66 loc) · 2.26 KB
/
Makefile
File metadata and controls
80 lines (66 loc) · 2.26 KB
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
SHELL := /bin/bash
BUILD_DIR := build
CMAKE := cmake
CTEST := ctest
SRC_DIRS := src
# Find source files for linting
LINT_LOCS_CPP ?= $(shell git ls-files '*.cpp')
LINT_LOCS_H ?= $(shell git ls-files '*.h')
.PHONY: config
config:
$(CMAKE) -E make_directory $(BUILD_DIR)
$(CMAKE) \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-B $(BUILD_DIR)
.PHONY: debug
debug: config
$(CMAKE) --build $(BUILD_DIR) --config Debug
.PHONY: release
release:
$(CMAKE) -E make_directory $(BUILD_DIR)
$(CMAKE) -S . -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=Release
$(CMAKE) --build $(BUILD_DIR) --config Release
.PHONY: clean
clean:
$(CMAKE) -E remove_directory $(BUILD_DIR)
.PHONY: test
test: release
$(CMAKE) --build $(BUILD_DIR) --target test_nutra --config Release
cd $(BUILD_DIR) && $(CTEST) --output-on-failure -C Release
.PHONY: run
run: debug
./$(BUILD_DIR)/nutra
.PHONY: format
format:
-prettier --write .github/
clang-format -i $(LINT_LOCS_CPP) $(LINT_LOCS_H)
.PHONY: lint
lint: config
@echo "Linting..."
@# Build test target first to generate MOC files for tests
@$(CMAKE) --build $(BUILD_DIR) --target test_nutra --config Debug 2>/dev/null || true
@echo "Running cppcheck..."
cppcheck --enable=warning,performance,portability \
--language=c++ --std=c++17 \
--suppress=missingIncludeSystem \
-Dslots= -Dsignals= -Demit= \
--quiet --error-exitcode=1 \
$(SRC_DIRS) include tests
@if [ ! -f $(BUILD_DIR)/compile_commands.json ]; then \
echo "Error: compile_commands.json not found in $(BUILD_DIR). Run 'make config' first."; \
exit 1; \
fi
@# Create a temp clean compile_commands.json to avoid modifying the original
@mkdir -p $(BUILD_DIR)/lint_tmp
@sed 's/-mno-direct-extern-access//g' $(BUILD_DIR)/compile_commands.json > $(BUILD_DIR)/lint_tmp/compile_commands.json
@echo "Running clang-tidy in parallel..."
@echo $(LINT_LOCS_CPP) $(LINT_LOCS_H) | xargs -n 1 -P $(shell nproc 2>/dev/null || sysctl -n hw.logicalcpu 2>/dev/null || echo 1) clang-tidy --quiet -p $(BUILD_DIR)/lint_tmp -extra-arg=-Wno-unknown-argument
@rm -rf $(BUILD_DIR)/lint_tmp
.PHONY: install
install: release
@echo "Installing..."
@$(MAKE) -C $(BUILD_DIR) install || ( \
$(CMAKE) -DCMAKE_INSTALL_PREFIX=$(HOME)/.local -B $(BUILD_DIR) && \
$(MAKE) -C $(BUILD_DIR) install \
)