-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.common
106 lines (79 loc) · 3.16 KB
/
Makefile.common
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
# This is a cross-platform Makefile.
# It is written to work exactly the same on Linux, OSX, and Windows,
# with CMake and Conan as its only requirements.
# In addition to acting as a build system,
# CMake is used as a cross-platform coreutils,
# with subcommands for, e.g., mkdir, touch, and rm.
ifeq ($(OS),Windows_NT)
SHELL := powershell.exe
.SHELLFLAGS :=
EXE := .exe
NPROC := $(shell $$env:NUMBER_OF_PROCESSORS)
generator ?= Visual Studio 16 2019
multi ?= true
else
SHELL := /bin/bash
.SHELLFLAGS := -o pipefail -c
ifeq ($(shell uname -s),Darwin)
NPROC := $(shell sysctl -n hw.logicalcpu)
else
NPROC := $(shell nproc)
endif
generator ?= Ninja
multi ?=
endif
flavor ?= Release
shared ?= OFF
options ?=
executable ?= true
source_dir := ${CURDIR}
build_dir ?= ${source_dir}/.build
install_dir ?= ${source_dir}/../.install
CMAKE ?= cmake
CTEST ?= ctest
CONAN ?= conan
.DEFAULT_GOAL := test
${build_dir} :
${CMAKE} -E make_directory $@
conanfile := $(wildcard conanfile.*)
conan_toolchain := ${build_dir}/conan_toolchain.cmake
# Windows will not tolerate line breaks in a command.
${conan_toolchain} : ${conanfile} | ${build_dir}
${CMAKE} -E chdir ${build_dir} ${CONAN} install ${source_dir} --build missing -s build_type=${flavor} --profile:build default --profile:host default --output-folder .
conan : ${conan_toolchain}
toolchain := $(if ${conanfile},${conan_toolchain},)
cache := ${build_dir}/CMakeCache.txt
${cache} : ${toolchain} Makefile | ${build_dir}
${CMAKE} -E chdir ${build_dir} ${CMAKE} -G "${generator}" -DCMAKE_TOOLCHAIN_FILE="${toolchain}" -DCMAKE_INSTALL_PREFIX="${install_dir}" -DCMAKE_PREFIX_PATH="${install_dir}" $(if ${multi},,-DCMAKE_BUILD_TYPE=${flavor}) -DBUILD_SHARED_LIBS=${shared} ${options} ${source_dir} 2>&1 | tee ${build_dir}/configure.log
${CMAKE} -E touch $@
configure : ${cache}
built_executable := ${build_dir}/output/${flavor}/bin/${executable}${EXE}
${built_executable} : ${cache} $(wildcard ${source_dir}/src/*.cpp)
${CMAKE} -E time ${CMAKE} --build ${build_dir} --verbose $(if ${multi},--config ${flavor}) --parallel ${NPROC} --target $(if ${multi},ALL_BUILD,all) 2>&1 | tee ${build_dir}/build.log
${SHELL} ${.SHELLFLAGS} "ls -l '$@'"
${SHELL} ${.SHELLFLAGS} "ls -l '$<'"
${CMAKE} -E touch $@
build : ${built_executable}
exe :
${built_executable}
force :
${CMAKE} -E touch ${cache}
${MAKE} build
test : ${cache}
${CMAKE} -E time ${CMAKE} --build ${build_dir} --verbose $(if ${multi},--config ${flavor}) --parallel ${NPROC} --target $(if ${multi},RUN_TESTS,test) 2>&1 | tee ${build_dir}/test.log
ctest : ${cache}
${CMAKE} -E chdir ${build_dir} ${CTEST} --verbose $(if ${multi},--build-config ${flavor}) --parallel ${NPROC}
installed_executable := ${install_dir}/bin/${executable}${EXE}
# The --install option was added in CMake 3.15.
${installed_executable} : ${cache}
${CMAKE} -E time ${CMAKE} --build ${build_dir} --verbose --target install $(if ${multi},--config ${flavor})
${SHELL} ${.SHELLFLAGS} "ls -l '$@'"
${SHELL} ${.SHELLFLAGS} "ls -l '$<'"
${CMAKE} -E touch $@
install : ${installed_executable}
installed :
${installed_executable}
clean :
${CMAKE} -E rm -rf ${build_dir}
uninstall :
${CMAKE} -E rm -rf ${install_dir}