Skip to content

Commit ca9a35c

Browse files
committed
Add wraper Makefile which calls CMake
1 parent d2bc7c3 commit ca9a35c

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

Makefile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#This is a simple wrapper hiding cmake from non-expert end users.
2+
#
3+
# It supports the targets:
4+
# 'make' - builds everything (all libaries/executables)
5+
# 'make clean' - removes generated build objects/libraries/executables etc.
6+
# 'make distclean' - will clean everything including the cmake generated build files
7+
#
8+
# All other targets (e.g. 'make tatum_test') are passed to the cmake generated makefile
9+
# and processed according to the CMakeLists.txt.
10+
#
11+
# To perform a debug build use:
12+
# 'make BUILD_TYPE=debug'
13+
14+
#Default build type
15+
# Possible values:
16+
# release
17+
# debug
18+
BUILD_TYPE = release
19+
20+
#Allows users to pass parameters to cmake
21+
# e.g. make CMAKE_PARAMS="-DVTR_ENABLE_SANITIZE=true"
22+
override CMAKE_PARAMS := -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -G 'Unix Makefiles' ${CMAKE_PARAMS}
23+
24+
25+
# -s : Suppresss makefile output (e.g. entering/leaving directories)
26+
# --output-sync target : For parallel compilation ensure output for each target is synchronized (make version >= 4.0)
27+
MAKEFLAGS := -s
28+
29+
BUILD_DIR=./build
30+
GENERATED_MAKEFILE := $(BUILD_DIR)/Makefile
31+
32+
#Check for the cmake exectuable
33+
CMAKE := $(shell command -v cmake 2> /dev/null)
34+
35+
#Show test log on failures with 'make test'
36+
export CTEST_OUTPUT_ON_FAILURE=TRUE
37+
38+
#All targets in this make file are always out of date.
39+
# This ensures that any make target requests are forwarded to
40+
# the generated makefile
41+
.PHONY: all distclean $(GENERATED_MAKEFILE) $(MAKECMDGOALS)
42+
43+
#Build everything
44+
all: $(GENERATED_MAKEFILE)
45+
@+$(MAKE) -C $(BUILD_DIR)
46+
47+
#Call the generated Makefile's clean, and then remove all cmake generated files
48+
distclean: $(GENERATED_MAKEFILE)
49+
@ echo "Cleaning build..."
50+
@+$(MAKE) -C $(BUILD_DIR) clean
51+
@ echo "Removing build system files.."
52+
@ rm -rf $(BUILD_DIR)
53+
@ rm -rf CMakeFiles CMakeCache.txt #In case 'cmake .' was run in the source directory
54+
55+
#Call cmake to generate the main Makefile
56+
$(GENERATED_MAKEFILE):
57+
ifeq ($(CMAKE),)
58+
$(error Required 'cmake' executable not found. On debian/ubuntu try 'sudo apt-get install cmake' to install)
59+
endif
60+
@ mkdir -p $(BUILD_DIR)
61+
echo "cd $(BUILD_DIR) && $(CMAKE) $(CMAKE_PARAMS) .. "
62+
cd $(BUILD_DIR) && $(CMAKE) $(CMAKE_PARAMS) ..
63+
64+
#Forward any targets that are not named 'distclean' to the generated Makefile
65+
ifneq ($(MAKECMDGOALS),distclean)
66+
$(MAKECMDGOALS): $(GENERATED_MAKEFILE)
67+
@+$(MAKE) -C $(BUILD_DIR) $(MAKECMDGOALS)
68+
endif

0 commit comments

Comments
 (0)