forked from solvcon/modmesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
286 lines (247 loc) · 9.16 KB
/
Makefile
File metadata and controls
286 lines (247 loc) · 9.16 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# Copyright (c) 2019, Yung-Yu Chen <yyc@solvcon.net>
# BSD-style license; see COPYING
# Build modmesh Python extension (even when the timestamp is clean):
# make
# Build verbosely:
# make VERBOSE=1
# Build with clang-tidy
# make USE_CLANG_TIDY=ON
SETUP_FILE ?= ./setup.mk
ifneq (,$(wildcard $(SETUP_FILE)))
include $(SETUP_FILE)
endif
# Optional extension appended to the auto-computed BUILD_PATH
# (e.g. BUILD_PATH_EXT=_noqt).
BUILD_PATH_EXT ?=
# To workaround macos SIP: https://github.com/solvcon/modmesh/pull/16.
# Additional configuration can be loaded from SETUP_FILE.
RUNENV += PYTHONPATH=$(MODMESH_ROOT)
SKIP_PYTHON_EXECUTABLE ?= OFF
HIDE_SYMBOL ?= ON
DEBUG_SYMBOL ?= ON
MODMESH_PROFILE ?= OFF
BUILD_METAL ?= OFF
BUILD_QT ?= ON
USE_CLANG_TIDY ?= OFF
CMAKE_BUILD_TYPE ?= Release
MAKE_PARALLEL ?= -j
MODMESH_ROOT ?= $(shell pwd)
CMAKE_INSTALL_PREFIX ?= $(MODMESH_ROOT)/build/fakeinstall
CMAKE_LIBRARY_OUTPUT_DIRECTORY ?= $(MODMESH_ROOT)/modmesh
# Use CMAKE_PREFIX_PATH to make it easier to build with Qt, e.g.,
# CMAKE_PREFIX_PATH=/path/to/qt/6.2.3/macos
CMAKE_PREFIX_PATH ?=
CMAKE_ARGS ?=
VERBOSE ?=
FORCE_CLANG_FORMAT ?=
QT3D_USE_RHI ?= OFF
# Let CMake find vcpkg-provided OpenBLAS/LAPACK headers, import libraries, and
# package metadata during configure and link on Windows.
ifeq ($(OS),Windows_NT)
VCPKG_INSTALLATION_ROOT ?= C:/vcpkg
CMAKE_TOOLCHAIN_FILE ?= $(VCPKG_INSTALLATION_ROOT)/scripts/buildsystems/vcpkg.cmake
CMAKE_ARGS += -DCMAKE_TOOLCHAIN_FILE=$(CMAKE_TOOLCHAIN_FILE)
CMAKE_ARGS += -DVCPKG_TARGET_TRIPLET=x64-windows
endif
# !!! NOTE: USING ANY VENV IS STRONGLY DISCOURAGED IN DEVELOPING MODMESH !!!
# This treatment is a "smarter" way to find python3-config executable.
# In case Python is not system Python. For example. Python virtual environment
# is used.
# However, please note a Python virtual environment is strongly discouraged in
# developing modmesh. We do not actively resolve bugs related to any virtual
# env including venv or conda.
# See https://github.com/solvcon/modmesh/pull/177 for more details.
WHICH_PYTHON := $(shell which python3)
REALPATH_PYTHON := $(realpath $(WHICH_PYTHON))
export DIRNAME_PYTHON := $(dir $(REALPATH_PYTHON))
pyextsuffix := $(shell $(DIRNAME_PYTHON)/python3-config --extension-suffix)
pyvminor := $(shell python3 -c 'import sys; print("%d%d" % sys.version_info[0:2])')
ifeq ($(CMAKE_BUILD_TYPE), Debug)
BUILD_PATH ?= build/dbg$(pyvminor)$(BUILD_PATH_EXT)
else
BUILD_PATH ?= build/rel$(pyvminor)$(BUILD_PATH_EXT)
endif
export BUILD_PATH
PYTEST ?= $(shell which py.test-3)
ifeq ($(PYTEST),)
PYTEST := $(shell which pytest)
endif
ifneq ($(VERBOSE),)
PYTEST_OPTS ?= -v -s
else
PYTEST_OPTS ?=
endif
.PHONY: default
default: buildext
.PHONY: cmake
cmake: $(BUILD_PATH)/Makefile
.PHONY: xcode
xcode: $(BUILD_PATH)_xcode/Makefile
CMAKE_CMD = cmake $(MODMESH_ROOT) \
-DCMAKE_PREFIX_PATH=$(CMAKE_PREFIX_PATH) \
-DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX) \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$(CMAKE_LIBRARY_OUTPUT_DIRECTORY) \
-DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) \
-DSKIP_PYTHON_EXECUTABLE=$(SKIP_PYTHON_EXECUTABLE) \
-DHIDE_SYMBOL=$(HIDE_SYMBOL) \
-DDEBUG_SYMBOL=$(DEBUG_SYMBOL) \
-DBUILD_METAL=$(BUILD_METAL) \
-DBUILD_QT=$(BUILD_QT) \
-DUSE_CLANG_TIDY=$(USE_CLANG_TIDY) \
-DLINT_AS_ERRORS=ON \
-DMODMESH_PROFILE=$(MODMESH_PROFILE) \
-DQT3D_USE_RHI=$(QT3D_USE_RHI) \
$(CMAKE_ARGS)
$(BUILD_PATH)/Makefile: CMakeLists.txt Makefile
mkdir -p $(BUILD_PATH) ; \
cd $(BUILD_PATH) ; \
env $(RUNENV) $(CMAKE_CMD)
$(BUILD_PATH)_xcode/Makefile: CMakeLists.txt Makefile
mkdir -p $(BUILD_PATH)_xcode ; \
cd $(BUILD_PATH)_xcode ; \
env $(RUNENV) $(CMAKE_CMD) -G Xcode
.PHONY: buildext
buildext: cmake
cmake --build $(BUILD_PATH) --target _modmesh_py VERBOSE=$(VERBOSE) $(MAKE_PARALLEL)
.PHONY: install
install: cmake
cmake --build $(BUILD_PATH) --target $@ VERBOSE=$(VERBOSE) $(MAKE_PARALLEL)
# Pass PYTEST_OPTS to forward arguments to the pytest harness. Examples:
# Example for one file:
# make pytest PYTEST_OPTS='-k test_buffer.py'
# Example for one class:
# make pytest PYTEST_OPTS='-v -k SimpleArrayBasicTC'
.PHONY: pytest
pytest: buildext
env $(RUNENV) \
$(PYTEST) $(PYTEST_OPTS) tests/
PROFFILES = $(shell find profiling -type f -name 'profile_*.py' | sort)
PROFRESDIR = profiling/results
.PHONY: pyprof
pyprof: buildext $(PROFFILES)
@mkdir -p profiling/results
@mkdir -p profiling/results/png
@for fn in $(PROFFILES); \
do \
outfn=$${fn%%.py}; \
outfn=profiling/results/$${outfn##profiling/}.output; \
echo "$(WHICH_PYTHON) $${fn} > $${outfn}"; \
env $(RUNENV) \
$(WHICH_PYTHON) $${fn} > $${outfn} || exit 1; \
done
.PHONY: pilot
pilot: cmake
cmake --build $(BUILD_PATH) --target $@ VERBOSE=$(VERBOSE) $(MAKE_PARALLEL)
.PHONY: gtest
gtest: cmake
cmake --build $(BUILD_PATH) --target run_gtest VERBOSE=$(VERBOSE) $(MAKE_PARALLEL)
# Pass PYTEST_OPTS to forward arguments to the pytest harness running
# inside the pilot binary.
# Example for one file:
# make run_pilot_pytest PYTEST_OPTS='-k test_buffer.py'
# Example for one class:
# make run_pilot_pytest PYTEST_OPTS='-v -k SimpleArrayBasicTC'
.PHONY: run_pilot_pytest
run_pilot_pytest: pilot
env $(RUNENV) PYTEST_OPTS="$(PYTEST_OPTS)" \
cmake --build $(BUILD_PATH) --target $@ VERBOSE=$(VERBOSE)
.PHONY: standalone_buffer_setup
standalone_buffer_setup:
$(MAKE) -C contrib/standalone_buffer copy
.PHONY: standalone_buffer
standalone_buffer:
$(MAKE) -C contrib/standalone_buffer build
$(MAKE) -C contrib/standalone_buffer run
CLANG_FORMAT ?= clang-format
FLAKE8 ?= flake8
AUTOPEP8 ?= autopep8
# Pinned to the clang-format major version used by CI; see
# .github/workflows/lint.yml. A different major version may produce a different
# formatting output and cause CI disagreement with local runs.
CLANG_FORMAT_CI_VERSION ?= 20
# Keep autopep8 a no-op against the current code base: only fix codes that
# flake8 also reports here, leave the rest alone. Specifically ignore:
# E121,E123,E126 continuation indent variants (flake8 default-ignored)
# E201,E202,E203,E241 whitespace inside brackets / around commas; preserve
# deliberate `# noqa` numeric alignment such as in
# `tests/test_mesh.py`
# E226 whitespace around arithmetic operator
# (flake8 default-ignored)
# E301,E303 blank-line rules that pycodestyle does not flag in
# their current uses (docstring-followed methods and
# nested defs inside `if HAS_SPHINX:`); autopep8 would
# add or remove blank lines that flake8 never reports
# E501 line too long; autopep8's wraps are often ugly, so
# leave long-line decisions to humans
# W503,W504 line-break style around binary operators
# (flake8 default-ignored)
AUTOPEP8_OPTS ?= --recursive --max-line-length=79 \
--ignore=E121,E123,E126,E201,E202,E203,E226,E241,E301,E303,E501,W503,W504 \
--exclude=thirdparty,tmp,_deps
CFFILES = $(shell find cpp gtests -type f -name '*.[ch]pp' | sort)
ifeq ($(FORCE_CLANG_FORMAT),inplace)
CFCMD ?= $(CLANG_FORMAT) -i
else
CFCMD ?= $(CLANG_FORMAT) --dry-run -Werror
endif
.PHONY: cformat
cformat: $(CFFILES)
@command -v $(CLANG_FORMAT) >/dev/null 2>&1 || { \
echo "Error: '$(CLANG_FORMAT)' not found in PATH."; \
echo " Install: pip install 'clang-format==$(CLANG_FORMAT_CI_VERSION).*'"; \
echo " (CI pins clang-format $(CLANG_FORMAT_CI_VERSION))"; \
exit 1; \
}
@ver=$$($(CLANG_FORMAT) --version 2>/dev/null | sed -nE 's/.*version ([0-9]+).*/\1/p' | head -n1); \
if [ -n "$$ver" ] && [ "$$ver" != "$(CLANG_FORMAT_CI_VERSION)" ]; then \
echo "Warning: $(CLANG_FORMAT) major version $$ver differs from CI ($(CLANG_FORMAT_CI_VERSION)); formatting output may differ."; \
fi
@for fn in $(CFFILES) ; \
do \
echo "$(CFCMD) $${fn}:"; \
$(CFCMD) $${fn} ; ret=$$? ; \
if [ $${ret} -ne 0 ] ; then exit $${ret} ; fi ; \
done
.PHONY: cinclude
cinclude: $(CFFILES)
@if grep -rnE '^[[:space:]]*#[[:space:]]*include[[:space:]]*"' cpp/ gtests/ 2>/dev/null; then \
echo "Error: use angle brackets for #include, not quotes (see lines above)."; \
exit 1; \
fi
.PHONY: flake8
flake8:
@command -v $(FLAKE8) >/dev/null 2>&1 || { \
echo "Error: '$(FLAKE8)' not found in PATH."; \
echo " Install: pip install flake8"; \
exit 1; \
}
$(FLAKE8) . --exclude thirdparty,tmp,_deps
.PHONY: checkascii
checkascii:
$(WHICH_PYTHON) contrib/lint/check_ascii.py
.PHONY: checktws
checktws:
$(WHICH_PYTHON) contrib/lint/check_ascii.py --check-tws
.PHONY: lint
lint: cformat cinclude flake8 checkascii checktws
.PHONY: pyformat
pyformat:
@command -v $(AUTOPEP8) >/dev/null 2>&1 || { \
echo "Error: '$(AUTOPEP8)' not found in PATH."; \
echo " Install: pip install autopep8"; \
exit 1; \
}
$(AUTOPEP8) $(AUTOPEP8_OPTS) --in-place .
.PHONY: format
format: pyformat
@$(MAKE) FORCE_CLANG_FORMAT=inplace cformat
.PHONY: clean
clean:
rm -f $(MODMESH_ROOT)/modmesh/_modmesh$(pyextsuffix)
rm -f $(MODMESH_ROOT)/_modmesh$(pyextsuffix)
make -C $(BUILD_PATH) clean
.PHONY: cmakeclean
cmakeclean:
rm -f $(MODMESH_ROOT)/modmesh/_modmesh$(pyextsuffix)
rm -f $(MODMESH_ROOT)/_modmesh$(pyextsuffix)
rm -rf $(BUILD_PATH)