4
4
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5
5
# cmake-format: on
6
6
7
- INSTALL_PREFIX? =.install/
7
+ # This Makefile is a thin wrapper around CMake. It is intended to be used.
8
+
9
+ # Default target.
8
10
PROJECT? =$(shell basename $(CURDIR ) )
11
+
12
+ # Default install prefix.
13
+ INSTALL_PREFIX? =.install/
14
+ # Default build directory.
9
15
BUILD_DIR? =.build
16
+ # Default destination directory.
10
17
DEST? =$(INSTALL_PREFIX )
18
+ # Default toolchain: missing => c++ sytem tool.
19
+ TOOLCHAIN? =
20
+ # Default configuration: missing => Asan.
21
+ BUILD_CONFIG? =Asan
22
+ # Default CMake flags.
11
23
CMAKE_FLAGS? =
12
24
25
+ # Default targets.
13
26
TARGETS := test clean all ctest
14
27
15
28
export
@@ -20,36 +33,40 @@ export
20
33
21
34
.gitmodules : .update-submodules
22
35
23
- CONFIG? =Asan
24
36
25
37
export
26
38
27
39
ifeq ($(strip $(TOOLCHAIN ) ) ,)
28
- _build_name?=build-system/
29
- _build_dir?=.build/
40
+ # Default build configuration.
41
+ _build_name?=toolchain/c++-system
42
+ _build_dir?=$(BUILD_DIR)
30
43
_configuration_types?="RelWithDebInfo;Debug;Tsan;Asan"
31
44
_cmake_args=-DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/etc/toolchain.cmake
32
45
else
33
- _build_name?=build-$(TOOLCHAIN)
34
- _build_dir?=.build/
46
+ # Custom toolchain.
47
+ _build_name?=toolchain/$(TOOLCHAIN)
48
+ _build_dir?=$(BUILD_DIR)
35
49
_configuration_types?="RelWithDebInfo;Debug;Tsan;Asan"
36
50
_cmake_args=-DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/etc/$(TOOLCHAIN)-toolchain.cmake
37
51
endif
38
52
39
-
53
+ # Build path.
40
54
_build_path? =$(_build_dir ) /$(_build_name )
41
55
56
+ # CMake command wrapper.
42
57
define run_cmake =
43
58
cmake \
44
59
-G "Ninja Multi-Config" \
45
60
-DCMAKE_CONFIGURATION_TYPES=$(_configuration_types ) \
46
61
-DCMAKE_INSTALL_PREFIX=$(abspath $(INSTALL_PREFIX ) ) \
47
62
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
48
63
$(_cmake_args ) \
64
+ $(CMAKE_FLAGS ) \
49
65
$(CURDIR )
50
66
endef
51
67
52
- default : test
68
+ # Default target.
69
+ default : build test
53
70
54
71
$(_build_path ) :
55
72
mkdir -p $(_build_path )
@@ -59,34 +76,34 @@ $(_build_path)/CMakeCache.txt: | $(_build_path) .gitmodules
59
76
-rm compile_commands.json
60
77
ln -s $(_build_path ) /compile_commands.json
61
78
62
- compile : $(_build_path ) /CMakeCache.txt # # Compile the project
63
- cmake $(CMAKE_FLAGS ) -DCMAKE_TOOLCHAIN_FILE=etc/$(TOOLCHAIN ) -toolchain.cmake -B $(_build_path ) -S .
64
- cmake --build $(_build_path ) --config $(CONFIG ) --target all -- -k 0
79
+ build : $(_build_path ) /CMakeCache.txt # # Compile the project.
80
+ cmake $(CMAKE_FLAGS ) -DCMAKE_TOOLCHAIN_FILE=etc/$(TOOLCHAIN ) -toolchain.cmake -B $(_build_path ) -S .
81
+ cmake --build $(_build_path ) --config $(BUILD_CONFIG ) --target all -- -k 0
65
82
66
- install : $(_build_path ) /CMakeCache.txt # # Install the project
83
+ install : $(_build_path ) /CMakeCache.txt # # Install the project.
67
84
DESTDIR=$(abspath $(DEST ) ) ninja -C $(_build_path ) -k 0 install
68
85
69
- ctest : $(_build_path ) /CMakeCache.txt # # Run CTest on current build
70
- ctest --build-config $(CONFIG ) --output-on-failure --test-dir $(_build_path )
86
+ ctest : $(_build_path ) /CMakeCache.txt # # Run CTest on current build.
87
+ ctest --build-config $(BUILD_CONFIG ) --output-on-failure --test-dir $(_build_path )
71
88
72
- ctest_ : compile
73
- ctest --build-config $(CONFIG ) --output-on-failure --test-dir $(_build_path )
89
+ ctest_ : build
90
+ ctest --build-config $(BUILD_CONFIG ) --output-on-failure --test-dir $(_build_path )
74
91
75
- test : ctest_ # # Rebuild and run tests
92
+ test : ctest_ # # Rebuild and run tests.
76
93
77
94
cmake : | $(_build_path )
78
95
cd $(_build_path ) && ${run_cmake}
79
96
80
- clean : $(_build_path ) /CMakeCache.txt # # Clean the build artifacts
81
- cmake --build $(_build_path ) --config $(CONFIG ) --target clean
97
+ clean : $(_build_path ) /CMakeCache.txt # # Clean the build artifacts, but don't delete the build directory.
98
+ cmake --build $(_build_path ) --config $(BUILD_CONFIG ) --target clean
82
99
83
- realclean : # # Delete the build directory
100
+ realclean : # # Delete the entire build directory.
84
101
rm -rf $(_build_path )
85
102
86
103
env :
87
104
$(foreach v, $(.VARIABLES ) , $(info $(v ) = $($(v ) ) ) )
88
105
89
- .PHONY : compile install ctest ctest_ test cmake clean realclean env
106
+ .PHONY : build install ctest ctest_ test cmake clean realclean env
90
107
91
108
.PHONY : papers
92
109
papers :
@@ -95,4 +112,4 @@ papers:
95
112
# Help target
96
113
.PHONY : help
97
114
help : # # Show this help.
98
- @awk ' BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST ) targets.mk | sort
115
+ @awk ' BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST ) | sort
0 commit comments