@@ -36,20 +36,16 @@ endif
36
36
SOURCE_DIR := .
37
37
SOURCE_CONANFILE := conanfile.py
38
38
SOURCE_CMAKELISTS: = ${SOURCE_DIR}/CMakeLists.txt
39
+ LOCKFILE_SOURCE :=
40
+ LOCKFILE_OPTION :=
39
41
CLEAN_SOURCE_DIR := false
40
42
BUILD_DIR := build
41
43
BUILD_CONANINFO := ${BUILD_DIR}/conanbuildinfo.cmake
42
44
BUILD_CMAKECACHE := ${BUILD_DIR}/CMakeCache.txt
45
+ BUILD_LOCKFILE := ${BUILD_DIR}/conan.lock
43
46
BUILD_LAYOUT := ${PROJECT_ROOT}/.conan-layout.ini
44
47
BUILD_POLICY := missing
45
48
46
- # Normally, you should set this in your profile, but if you just want to build
47
- # the package in debug mode once, you can do it this way, although it will
48
- # only apply to local builds.
49
- #
50
- # This can be one of: None, Debug, Release, RelWithDebInfo, MinSizeRel
51
- BUILD_TYPE := RelWithDebInfo
52
-
53
49
PACKAGE_NAME := $(shell sed -rn 's/.* name\s* =\s* "([^"]+) "$$/\1/p' ${SOURCE_CONANFILE})
54
50
PACKAGE_VERSION := $(or \
55
51
$(shell sed -rn 's/\s+version\s* =\s* "([^"]+) "$$/\1/p' ${SOURCE_CONANFILE}) , \
@@ -59,22 +55,42 @@ PACKAGE_VERSION := $(or \
59
55
PACKAGE_CHANNEL := cloe/develop
60
56
PACKAGE_FQN := ${PACKAGE_NAME}/${PACKAGE_VERSION}@${PACKAGE_CHANNEL}
61
57
62
- # Determining the PACKAGE_DIR takes a long time because we have to call Conan,
63
- # so only do it for the targets that actually make use of it.
64
- ifneq "$(filter help list status,${MAKECMDGOALS}) " ""
65
- PACKAGE_INFO := $(shell conan info ${PACKAGE_FQN} --package-filter ${PACKAGE_FQN} --paths 2>/dev/null | sed -r 's/$$/\\n/')
66
- PACKAGE_ID := $(shell echo "${PACKAGE_INFO}" | sed -rn "s/^ * ID: * (.* ) $$/\1/p")
67
- PACKAGE_DIR := $(shell echo "${PACKAGE_INFO}" | sed -rn "s/^ * package_folder: * (.* ) $$/\1/p")
68
- PACKAGE_DATE := $(shell echo "${PACKAGE_INFO}" | sed -rn "s/^ * Creation date: * (.* ) $$/\1/p")
69
- endif
58
+ # Normally, you should set this in your profile, but if you just want to build
59
+ # the package in debug mode once, you can do it this way, although it will
60
+ # only apply to local builds.
61
+ #
62
+ # This can be one of: None, Debug, Release, RelWithDebInfo, MinSizeRel
63
+ BUILD_TYPE := RelWithDebInfo
64
+ BUILD_TYPE_OPTION := -s ${PACKAGE_NAME}:build_type=${BUILD_TYPE}
70
65
71
66
# These options can be set to influence package and configure.
72
67
CONAN_OPTIONS :=
73
68
69
+ .PHONY : ${BUILD_LOCKFILE}
70
+ ifneq "${LOCKFILE_SOURCE}" ""
71
+ ifeq "$(realpath ${LOCKFILE_SOURCE}) " "$(realpath ${SOURCE_CONANFILE}) "
72
+ $(error "LOCKFILE_SOURCE must contain superset of SOURCE_CONANFILE package and dependencies")
73
+ endif
74
+ LOCKFILE_OPTION := --lockfile="${BUILD_LOCKFILE}"
75
+ ${BUILD_LOCKFILE} : ${LOCKFILE_SOURCE} | ${BUILD_DIR} export
76
+ # Create lockfile from LOCKFILE_SOURCE.
77
+ #
78
+ conan lock create --lockfile-out " ${BUILD_LOCKFILE} " ${BUILD_TYPE_OPTION} ${CONAN_OPTIONS} --build -- " ${LOCKFILE_SOURCE} " > /dev/null
79
+ endif
80
+
81
+ # When using a --lockfile option, we cannot use profile, settings, options, env
82
+ # or conf 'host' Conan options.
83
+ ifneq "${LOCKFILE_OPTION}" ""
84
+ ALL_OPTIONS := ${LOCKFILE_OPTION} ${CONAN_OPTIONS}
85
+ else
86
+ ALL_OPTIONS := ${BUILD_TYPE_OPTION} ${CONAN_OPTIONS}
87
+ endif
88
+
89
+ # INFORMATIONAL TARGETS -------------------------------------------------------
74
90
.DEFAULT : help
75
- .SILENT : help status info-name info-version info-channel info-fqn
76
- .PHONY : help status info-name info-version info-channel info-fqn
77
- help ::
91
+ .SILENT : help status parse- info info -name info-version info-channel info-fqn info
92
+ .PHONY : help status parse- info info -name info-version info-channel info-fqn info
93
+ help :: parse-info
78
94
echo " Usage: make <target>"
79
95
echo
80
96
echo " The following targets define common operations with this package in"
83
99
echo " Available targets:"
84
100
echo " help to show this help"
85
101
echo " status to show status of package"
102
+ echo " info to show detailed package info"
86
103
echo
87
104
echo " export to export recipe and sources [conan-cache]"
88
105
echo " download to download or create package [conan-cache]"
@@ -103,6 +120,7 @@ help::
103
120
echo " clean to remove build directory [in-source]"
104
121
echo
105
122
echo " Configuration:"
123
+ echo " LOCKFILE_SOURCE: ${LOCKFILE_SOURCE} "
106
124
echo " SOURCE_DIR: ${SOURCE_DIR} "
107
125
echo " BUILD_DIR: ${BUILD_DIR} "
108
126
echo " BUILD_POLICY: ${BUILD_POLICY} "
@@ -120,7 +138,19 @@ help::
120
138
echo " GIT_COMMIT_HASH: ${GIT_COMMIT_HASH} "
121
139
echo
122
140
123
- status :
141
+ parse-info : ${BUILD_LOCKFILE}
142
+ # Fetch package information from Conan.
143
+ #
144
+ # This command takes long, so we won't run it by default. Instead, if any
145
+ # target needs one of these variables, they should depend on this target
146
+ # to ensure that these variables are set.
147
+ #
148
+ $(eval PACKAGE_INFO := $(shell conan info ${ALL_OPTIONS} "${PACKAGE_FQN}" --package-filter "${PACKAGE_FQN}" --paths | sed -r 's/$$/\\n/') )
149
+ $(eval PACKAGE_ID := $(shell echo -e "${PACKAGE_INFO}" | sed -rn 's/^ * ID: * (.* ) $$/\1/p') )
150
+ $(eval PACKAGE_DIR := $(shell echo -e "${PACKAGE_INFO}" | sed -rn 's/^ * package_folder: * (.* ) $$/\1/p') )
151
+ $(eval PACKAGE_DATE := $(shell echo -e "${PACKAGE_INFO}" | sed -rn 's/^ * Creation date: * (.* ) $$/\1/p') )
152
+
153
+ status : parse-info
124
154
# Show the *approximate* status of each package in the cloe workspace.
125
155
#
126
156
# This lets you know whether a package is in editable mode or not,
@@ -151,6 +181,13 @@ info-channel:
151
181
info-fqn :
152
182
echo ${PACKAGE_FQN}
153
183
184
+ info : parse-info
185
+ if [ -z " ${PACKAGE_INFO} " ]; then \
186
+ echo " Errors occurred, no output available." ; \
187
+ else \
188
+ echo ${PACKAGE_INFO} ; \
189
+ fi
190
+
154
191
# CONFIGURATION TARGETS -------------------------------------------------------
155
192
.PHONY : editable uneditable
156
193
@@ -196,14 +233,10 @@ download:
196
233
#
197
234
# See: https://docs.conan.io/en/latest/mastering/policies.html
198
235
#
199
- conan create . ${PACKAGE_FQN} \
200
- --build=never \
201
- ${CONAN_OPTIONS} || \
202
- conan create . ${PACKAGE_FQN} \
203
- --build=${BUILD_POLICY} --build=${PACKAGE_NAME} \
204
- ${CONAN_OPTIONS}
236
+ conan create . ${PACKAGE_FQN} --build=never ${ALL_OPTIONS} || \
237
+ conan create . ${PACKAGE_FQN} --build=${BUILD_POLICY} --build=${PACKAGE_NAME} ${ALL_OPTIONS}
205
238
206
- package :
239
+ package : ${BUILD_LOCKFILE}
207
240
# Build the package in Conan cache unconditionally.
208
241
#
209
242
# Conan will retrieve and build all dependencies based on the build policy.
@@ -212,29 +245,24 @@ package:
212
245
# See: https://docs.conan.io/en/latest/mastering/policies.html
213
246
#
214
247
conan create . ${PACKAGE_FQN} \
215
- --build=${BUILD_POLICY} --build=${PACKAGE_NAME} \
216
- ${CONAN_OPTIONS}
248
+ --build=${BUILD_POLICY} --build=${PACKAGE_NAME} ${ALL_OPTIONS}
217
249
218
- package-all :
250
+ package-all : ${BUILD_LOCKFILE}
219
251
# Build the package in Conan cache unconditionally.
220
252
#
221
253
# Conan will retrieve and build all dependencies unconditionally.
222
254
# Note that this cannot be called if the package is currently in editable mode.
223
255
#
224
- conan create . ${PACKAGE_FQN} \
225
- --build \
226
- ${CONAN_OPTIONS}
256
+ conan create . ${PACKAGE_FQN} --build ${ALL_OPTIONS}
227
257
228
- package-outdated :
258
+ package-outdated : ${BUILD_LOCKFILE}
229
259
# Build the package in Conan cache if it is outdated.
230
260
#
231
261
# Note that this does not take dependencies of ${PACKAGE_NAME} into account.
232
262
# Rebuilds will occur if package info has changed or a hash of the source
233
263
# code changes. Timestamps are not taken into account.
234
264
#
235
- conan create . ${PACKAGE_FQN} \
236
- --build=outdated \
237
- ${CONAN_OPTIONS}
265
+ conan create . ${PACKAGE_FQN} --build=outdated ${ALL_OPTIONS}
238
266
239
267
purge :
240
268
# Remove all instances of this package in the Conan cache.
@@ -245,7 +273,7 @@ purge:
245
273
#
246
274
-conan remove -f ${PACKAGE_FQN}
247
275
248
- list :
276
+ list : parse-info
249
277
# List all files in the Conan cache package directory.
250
278
#
251
279
@tree ${PACKAGE_DIR}
@@ -255,13 +283,12 @@ list:
255
283
all : ${SOURCE_DIR} ${BUILD_CONANINFO}
256
284
# Build the package in-source.
257
285
#
258
- mkdir -p ${BUILD_DIR}
259
- conan build . --source-folder=${SOURCE_DIR} --build-folder=${BUILD_DIR}
286
+ conan build . --source-folder=" ${SOURCE_DIR} " --build-folder=" ${BUILD_DIR} "
260
287
261
288
clean :
262
289
# Clean the build directory and Python cache files.
263
290
#
264
- rm -rf ${BUILD_DIR}
291
+ rm -rf " ${BUILD_DIR} "
265
292
rm -rf __pycache__
266
293
if ${CLEAN_SOURCE_DIR} ; then \
267
294
rm -rf ${SOURCE_DIR} ; \
@@ -276,8 +303,8 @@ test:
276
303
#
277
304
# If no tests are available, this will simply return true.
278
305
#
279
- @if [ -f ${BUILD_DIR} /CTestTestfile.cmake ]; then \
280
- cd ${BUILD_DIR} && ctest; \
306
+ @if [ -f " ${BUILD_DIR} " /CTestTestfile.cmake ]; then \
307
+ cd " ${BUILD_DIR} " && ctest; \
281
308
else \
282
309
true ; \
283
310
fi
@@ -290,8 +317,8 @@ export-pkg:
290
317
# binaries available to Conan but not the source.
291
318
#
292
319
# Note that this does not require the package to be editable.
293
- conan export-pkg . ${PACKAGE_FQN} \
294
- -- build-folder=${BUILD_DIR}
320
+ #
321
+ conan export-pkg . ${PACKAGE_FQN} -- build-folder=" ${BUILD_DIR} "
295
322
296
323
${SOURCE_DIR} :
297
324
# Copy source to an external source directory.
@@ -300,23 +327,20 @@ ${SOURCE_DIR}:
300
327
# SOURCE_DIR is identical to the current directory.
301
328
#
302
329
[ " $( shell readlink -f " ${SOURCE_DIR} " ) " != " $( shell readlink -f .) " ]
303
- conan source . --source-folder=${SOURCE_DIR}
330
+ conan source . --source-folder=" ${SOURCE_DIR} "
331
+
332
+ ${BUILD_DIR} :
333
+ mkdir -p " ${BUILD_DIR} "
304
334
305
335
${SOURCE_CMAKELISTS} : ${SOURCE_DIR}
306
336
307
- ${BUILD_CONANINFO} : ${SOURCE_CONANFILE}
337
+ ${BUILD_CONANINFO} : ${SOURCE_CONANFILE} ${BUILD_DIR} ${BUILD_LOCKFILE}
308
338
# Install package dependencies and prepare in-source build.
309
339
#
310
- mkdir -p ${BUILD_DIR}
311
- conan install . ${PACKAGE_FQN} \
312
- --install-folder=${BUILD_DIR} \
313
- -s ${PACKAGE_NAME} :build_type=${BUILD_TYPE} \
314
- --build=${BUILD_POLICY} \
315
- ${CONAN_OPTIONS}
340
+ conan install . ${PACKAGE_FQN} --install-folder=" ${BUILD_DIR} " --build=${BUILD_POLICY} ${ALL_OPTIONS}
316
341
touch ${BUILD_CONANINFO}
317
342
318
- ${BUILD_CMAKECACHE} : ${BUILD_CONANINFO } ${SOURCE_CMAKELISTS }
343
+ ${BUILD_CMAKECACHE} : ${SOURCE_CMAKELISTS } ${BUILD_CONANINFO }
319
344
# Configure in-source build with CMake.
320
345
#
321
- mkdir -p ${BUILD_DIR}
322
- conan build --configure . --source-folder=${SOURCE_DIR} --build-folder=${BUILD_DIR}
346
+ conan build --configure . --source-folder=" ${SOURCE_DIR} " --build-folder=" ${BUILD_DIR} "
0 commit comments