forked from eclipse/cloe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.package
322 lines (287 loc) · 11 KB
/
Makefile.package
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# vim: set ft=make noet:
#
# Usage:
#
# PROJECT_ROOT := ...
# include ${PROJECT_ROOT}/Makefile.package
#
# This Makefile is used for every Conan package in this project.
# It expects a conanfile.py to reside in the directory and reads
# package information from this.
#
# You may also use it for your own Cloe plugins or other Conan packages.
# In this case though, you should remove variables that make explicit
# reference to files found in the Cloe repository, such as PROJECT_VERSION.
# You should also adjust the PACKAGE_CHANNEL variable.
#
PROJECT_ROOT := $(dir $(abspath $(lastword ${MAKEFILE_LIST})))
PROJECT_VERSION := $(shell [ -r ${PROJECT_ROOT}/VERSION ] && cat ${PROJECT_ROOT}/VERSION || echo unknown)
DATE := $(shell date +"%Y%m%d")
TIMESTAMP := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
HAS_GIT := $(shell [ -d ${PROJECT_ROOT}/.git ] && echo "true")
ifeq (${PROJECT_VERSION},unknown)
ifeq (${HAS_GIT},true)
GIT_COMMIT_HASH := $(shell git log -1 --format=%h)
GIT_COMMIT_DIRTY := $(shell git diff --quiet || echo "-dirty")
GIT_DESCRIBE := $(shell git describe --dirty="-dirty" | sed -r "s/^v(.*)/\1/")
else
GIT_DESCRIBE := "unknown"
endif
PROJECT_VERSION := ${GIT_DESCRIBE}
endif
SOURCE_DIR := .
SOURCE_CONANFILE := conanfile.py
SOURCE_CMAKELISTS:= ${SOURCE_DIR}/CMakeLists.txt
CLEAN_SOURCE_DIR := false
BUILD_DIR := build
BUILD_CONANINFO := ${BUILD_DIR}/conanbuildinfo.cmake
BUILD_CMAKECACHE := ${BUILD_DIR}/CMakeCache.txt
BUILD_LAYOUT := ${PROJECT_ROOT}/.conan-layout.ini
BUILD_POLICY := missing
# Normally, you should set this in your profile, but if you just want to build
# the package in debug mode once, you can do it this way, although it will
# only apply to local builds.
#
# This can be one of: None, Debug, Release, RelWithDebInfo, MinSizeRel
BUILD_TYPE := RelWithDebInfo
PACKAGE_NAME := $(shell sed -rn 's/.*name\s*=\s*"([^"]+)"$$/\1/p' ${SOURCE_CONANFILE})
PACKAGE_VERSION := $(or \
$(shell sed -rn 's/\s+version\s*=\s*"([^"]+)"$$/\1/p' ${SOURCE_CONANFILE}), \
${PROJECT_VERSION}, \
unknown \
)
PACKAGE_CHANNEL := cloe/develop
PACKAGE_FQN := ${PACKAGE_NAME}/${PACKAGE_VERSION}@${PACKAGE_CHANNEL}
# Determining the PACKAGE_DIR takes a long time because we have to call Conan,
# so only do it for the targets that actually make use of it.
ifneq "$(filter help list status,${MAKECMDGOALS})" ""
PACKAGE_INFO := $(shell conan info ${PACKAGE_FQN} --package-filter ${PACKAGE_FQN} --paths 2>/dev/null | sed -r 's/$$/\\n/')
PACKAGE_ID := $(shell echo "${PACKAGE_INFO}" | sed -rn "s/^ *ID: *(.*)$$/\1/p")
PACKAGE_DIR := $(shell echo "${PACKAGE_INFO}" | sed -rn "s/^ *package_folder: *(.*)$$/\1/p")
PACKAGE_DATE := $(shell echo "${PACKAGE_INFO}" | sed -rn "s/^ *Creation date: *(.*)$$/\1/p")
endif
# These options can be set to influence package and configure.
CONAN_OPTIONS :=
.DEFAULT: help
.SILENT: help status info-name info-version info-channel info-fqn
.PHONY: help status info-name info-version info-channel info-fqn
help::
echo "Usage: make <target>"
echo
echo "The following targets define common operations with this package in"
echo "editable (local in-source) and uneditable (in the Conan cache) modes."
echo
echo "Available targets:"
echo " help to show this help"
echo " status to show status of package"
echo
echo " export to export recipe and sources [conan-cache]"
echo " download to download or create package [conan-cache]"
echo " package to create package with build policy [conan-cache]"
echo " package-all to create package and dependencies [conan-cache]"
echo " package-outdated to create package if outdated [conan-cache]"
echo " list to list installed package files [conan-cache]"
echo " purge to remove package from cache [conan-cache]"
echo
echo " editable to instruct Conan to use in-source build"
echo " uneditable to instruct Conan to use local cache"
echo
echo " all to build the package [in-source]"
echo " conan to configure Conan and install dependencies [in-source]"
echo " configure to configure CMake package [in-source]"
echo " test to run CMake tests if they are available [in-source]"
echo " export-pkg to export build artifacts to Conan cache [in-source]"
echo " clean to remove build directory [in-source]"
echo
echo "Configuration:"
echo " SOURCE_DIR: ${SOURCE_DIR}"
echo " BUILD_DIR: ${BUILD_DIR}"
echo " BUILD_POLICY: ${BUILD_POLICY}"
echo " BUILD_TYPE: ${BUILD_TYPE}"
echo " CONAN_OPTIONS: ${CONAN_OPTIONS}"
echo
echo "Package information:"
echo " PACKAGE_NAME: ${PACKAGE_NAME}"
echo " PACKAGE_VERSION: ${PACKAGE_VERSION}"
echo " PACKAGE_CHANNEL: ${PACKAGE_CHANNEL}"
echo " PACKAGE_FQN: ${PACKAGE_FQN}"
echo " PACKAGE_ID: ${PACKAGE_ID}"
echo " PACKAGE_DIR: ${PACKAGE_DIR}"
echo " PACKAGE_DATE: ${PACKAGE_DATE}"
echo " GIT_COMMIT_HASH: ${GIT_COMMIT_HASH}"
echo
status:
# Show the *approximate* status of each package in the cloe workspace.
#
# This lets you know whether a package is in editable mode or not,
# and will also let you know if any of the files in the package
# directory has been modified more recently than the package in the
# Conan cache.
#
_editable=$$(conan editable list | grep "${PACKAGE_FQN}"); \
if [ -z "$${_editable}" ]; then \
if [ -n "${PACKAGE_DATE}" ] && [ -z "$$(find -type f -newermt "${PACKAGE_DATE}")" ]; then \
echo "ok : ${PACKAGE_FQN}"; \
else \
echo "outdated : ${PACKAGE_FQN}"; \
fi \
else \
echo "editable : ${PACKAGE_FQN}"; \
fi
info-name:
echo ${PACKAGE_NAME}
info-version:
echo ${PACKAGE_VERSION}
info-channel:
echo ${PACKAGE_CHANNEL}
info-fqn:
echo ${PACKAGE_FQN}
# CONFIGURATION TARGETS -------------------------------------------------------
.PHONY: editable uneditable
editable:
# Conan will now resolve references to the in-source build.
#
# In editable mode, Conan will use the in-source build for all references
# to this package. You should use [in-source] targets while the package is
# editable. It is not possible to create a Conan package while the package
# is in editable mode.
#
# Run `make uneditable` to leave this mode.
#
conan editable add . --layout "${BUILD_LAYOUT}" ${PACKAGE_FQN}
uneditable:
# Conan will now resolve references to the package in the cache.
#
# In uneditable mode, Conan will use the package within the Conan cache
# (normally located in ~/.conan/data). This is the default behavior.
#
conan editable remove ${PACKAGE_FQN}
# CONAN TARGETS ---------------------------------------------------------------
.PHONY: export package package-all package-missing package-outdated purge list
export:
# Export sources to Conan cache.
#
# This does not build this package but provides the sources and the
# build recipe to Conan for on-demand building.
#
conan export . ${PACKAGE_FQN}
download:
# Try to download the package to Conan cache.
#
# Only if the package is not available in the remote, will the package be built:
# The first command tries to create the package without building anything; if
# there is an error, then we build the package using the default build policy.
# Thus, errors arising from the first command can be safely ignored.
# Note that this cannot be called if the package is currently in editable mode.
#
# See: https://docs.conan.io/en/latest/mastering/policies.html
#
conan create . ${PACKAGE_FQN} \
--build=never \
${CONAN_OPTIONS} || \
conan create . ${PACKAGE_FQN} \
--build=${BUILD_POLICY} --build=${PACKAGE_NAME} \
${CONAN_OPTIONS}
package:
# Build the package in Conan cache unconditionally.
#
# Conan will retrieve and build all dependencies based on the build policy.
# Note that this cannot be called if the package is currently in editable mode.
#
# See: https://docs.conan.io/en/latest/mastering/policies.html
#
conan create . ${PACKAGE_FQN} \
--build=${BUILD_POLICY} --build=${PACKAGE_NAME} \
${CONAN_OPTIONS}
package-all:
# Build the package in Conan cache unconditionally.
#
# Conan will retrieve and build all dependencies unconditionally.
# Note that this cannot be called if the package is currently in editable mode.
#
conan create . ${PACKAGE_FQN} \
--build \
${CONAN_OPTIONS}
package-outdated:
# Build the package in Conan cache if it is outdated.
#
# Note that this does not take dependencies of ${PACKAGE_NAME} into account.
# Rebuilds will occur if package info has changed or a hash of the source
# code changes. Timestamps are not taken into account.
#
conan create . ${PACKAGE_FQN} \
--build=outdated \
${CONAN_OPTIONS}
purge:
# Remove all instances of this package in the Conan cache.
#
# Normally, building a package only replaces the instance in the Cache that
# has the same ID. Purging all instances is useful for forcing a rebuild
# of all instances of this package henceforth.
#
-conan remove -f ${PACKAGE_FQN}
list:
# List all files in the Conan cache package directory.
#
@tree ${PACKAGE_DIR}
# IN-SOURCE TARGETS -----------------------------------------------------------
.PHONY: all clean conan configure test export-pkg
all: ${SOURCE_DIR} ${BUILD_CONANINFO}
# Build the package in-source.
#
mkdir -p ${BUILD_DIR}
conan build . --source-folder=${SOURCE_DIR} --build-folder=${BUILD_DIR}
clean:
# Clean the build directory and Python cache files.
#
rm -rf ${BUILD_DIR}
rm -rf __pycache__
if ${CLEAN_SOURCE_DIR}; then \
rm -rf ${SOURCE_DIR}; \
fi
conan: ${BUILD_CONANINFO}
configure: ${BUILD_CMAKECACHE}
test:
# Run tests available to CMake ctest.
#
# If no tests are available, this will simply return true.
#
@if [ -f ${BUILD_DIR}/CTestTestfile.cmake ]; then \
cd ${BUILD_DIR} && ctest; \
else \
true; \
fi
export-pkg:
# Export in-source build artifacts to Conan cache.
#
# This requires the in-source build to be complete and uses the package
# recipe in the conanfile. This is useful when you want to make the
# binaries available to Conan but not the source.
#
# Note that this does not require the package to be editable.
conan export-pkg . ${PACKAGE_FQN} \
--build-folder=${BUILD_DIR}
${SOURCE_DIR}:
# Copy source to an external source directory.
#
# This usually isn't necessary, and should not be called when
# SOURCE_DIR is identical to the current directory.
#
[ "$(shell readlink -f "${SOURCE_DIR}")" != "$(shell readlink -f .)" ]
conan source . --source-folder=${SOURCE_DIR}
${SOURCE_CMAKELISTS}: ${SOURCE_DIR}
${BUILD_CONANINFO}: ${SOURCE_CONANFILE}
# Install package dependencies and prepare in-source build.
#
mkdir -p ${BUILD_DIR}
conan install . ${PACKAGE_FQN} \
--install-folder=${BUILD_DIR} \
-s ${PACKAGE_NAME}:build_type=${BUILD_TYPE} \
--build=${BUILD_POLICY} \
${CONAN_OPTIONS}
touch ${BUILD_CONANINFO}
${BUILD_CMAKECACHE}: ${BUILD_CONANINFO} ${SOURCE_CMAKELISTS}
# Configure in-source build with CMake.
#
mkdir -p ${BUILD_DIR}
conan build --configure . --source-folder=${SOURCE_DIR} --build-folder=${BUILD_DIR}