blob: 5fd6df0466a607d4905646bf53205c53b939f68c (
plain)
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
|
# Requires CVS CMake for 'function' and '-E touch' and '--build'
find_package(CVS)
find_package(Subversion)
function(get_external_project_directories base_dir_var build_dir_var downloads_dir_var install_dir_var sentinels_dir_var source_dir_var tmp_dir_var)
set(base "${CMAKE_BINARY_DIR}/CMakeExternals")
set(${base_dir_var} "${base}" PARENT_SCOPE)
set(${build_dir_var} "${base}/Build" PARENT_SCOPE)
set(${downloads_dir_var} "${base}/Downloads" PARENT_SCOPE)
set(${install_dir_var} "${base}/Install" PARENT_SCOPE)
set(${sentinels_dir_var} "${base}/Sentinels" PARENT_SCOPE)
set(${source_dir_var} "${base}/Source" PARENT_SCOPE)
set(${tmp_dir_var} "${base}/tmp" PARENT_SCOPE)
endfunction(get_external_project_directories)
function(get_configure_build_working_dir name working_dir_var)
get_external_project_directories(base_dir build_dir downloads_dir install_dir
sentinels_dir source_dir tmp_dir)
get_target_property(dir ${name} AEP_CONFIGURE_DIR)
if(dir)
if (IS_ABSOLUTE "${dir}")
set(working_dir "${dir}")
else()
set(working_dir "${source_dir}/${name}/${dir}")
endif()
else()
set(working_dir "${build_dir}/${name}")
endif()
set(${working_dir_var} "${working_dir}" PARENT_SCOPE)
endfunction(get_configure_build_working_dir)
function(get_configure_command_id name cfg_cmd_id_var)
get_target_property(cmd ${name} AEP_CONFIGURE_COMMAND)
if(cmd STREQUAL "")
# Explicit empty string means no configure step for this project
set(${cfg_cmd_id_var} "none" PARENT_SCOPE)
else()
if(NOT cmd)
# Default is "use cmake":
set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
else()
# Otherwise we have to analyze the value:
if(cmd MATCHES "/configure$")
set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
else()
if(cmd MATCHES "cmake")
set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
else()
if(cmd MATCHES "config")
set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
else()
set(${cfg_cmd_id_var} "unknown:${cmd}" PARENT_SCOPE)
endif()
endif()
endif()
endif()
endif()
endfunction(get_configure_command_id)
function(add_external_project_download_command name)
set(added 0)
get_external_project_directories(base_dir build_dir downloads_dir install_dir
sentinels_dir source_dir tmp_dir)
if(NOT added)
get_target_property(cmd ${name} AEP_DOWNLOAD_COMMAND)
if(cmd STREQUAL "")
# Explicit empty string means no download step for this project
add_custom_command(
OUTPUT ${sentinels_dir}/${name}-download
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/${name}-download
WORKING_DIRECTORY ${sentinels_dir}
COMMENT "No download step for '${name}'"
)
set(added 1)
else()
if(cmd)
set(args "")
get_target_property(download_args ${name} AEP_DOWNLOAD_ARGS)
if(download_args)
set(args "${download_args}")
separate_arguments(args)
endif()
add_custom_command(
OUTPUT ${sentinels_dir}/${name}-download
COMMAND ${cmd} ${args}
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/${name}-download
WORKING_DIRECTORY ${downloads_dir}
COMMENT "Performing download step for '${name}'"
)
set(added 1)
else()
# No explicit DOWNLOAD_COMMAND property. Look for other properties
# indicating which download method to use in the logic below...
endif()
endif()
endif()
if(NOT added)
get_target_property(cvs_repository ${name} AEP_CVS_REPOSITORY)
if(cvs_repository)
if(NOT CVS_EXECUTABLE)
message(FATAL_ERROR "error: could not find cvs for checkout of ${name}")
endif()
get_target_property(cvs_module ${name} AEP_CVS_MODULE)
if(NOT cvs_module)
message(FATAL_ERROR "error: no CVS_MODULE")
endif()
get_target_property(tag ${name} AEP_CVS_TAG)
set(cvs_tag)
if(tag)
set(cvs_tag ${tag})
endif()
set(args -d ${cvs_repository} co ${cvs_tag} -d ${name} ${cvs_module})
set(wd "${source_dir}")
set(repository ${cvs_repository})
set(module ${cvs_module})
set(tag ${cvs_tag})
configure_file(
"${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
"${sentinels_dir}/${name}-cvsinfo.txt"
@ONLY
)
add_custom_command(
OUTPUT ${sentinels_dir}/${name}-download
COMMAND ${CVS_EXECUTABLE} ${args}
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/${name}-download
WORKING_DIRECTORY ${wd}
COMMENT "Performing download step (CVS checkout) for '${name}'"
DEPENDS "${sentinels_dir}/${name}-cvsinfo.txt"
)
set(added 1)
endif()
endif(NOT added)
if(NOT added)
get_target_property(svn_repository ${name} AEP_SVN_REPOSITORY)
if(svn_repository)
if(NOT Subversion_SVN_EXECUTABLE)
message(FATAL_ERROR "error: could not find svn for checkout of ${name}")
endif()
get_target_property(tag ${name} AEP_SVN_TAG)
set(svn_tag)
if(tag)
set(svn_tag ${tag})
endif()
set(args co ${svn_repository} ${svn_tag} ${name})
set(wd "${source_dir}")
set(repository ${svn_repository})
set(module)
set(tag ${svn_tag})
configure_file(
"${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
"${sentinels_dir}/${name}-svninfo.txt"
@ONLY
)
add_custom_command(
OUTPUT ${sentinels_dir}/${name}-download
COMMAND ${Subversion_SVN_EXECUTABLE} ${args}
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/${name}-download
WORKING_DIRECTORY ${wd}
COMMENT "Performing download step (SVN checkout) for '${name}'"
DEPENDS "${sentinels_dir}/${name}-svninfo.txt"
)
set(added 1)
endif()
endif(NOT added)
if(NOT added)
get_target_property(dir ${name} AEP_DIR)
if(dir)
add_custom_command(
OUTPUT ${sentinels_dir}/${name}-download
COMMAND ${CMAKE_COMMAND} -E copy_directory ${dir} ${source_dir}/${name}
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/${name}-download
WORKING_DIRECTORY ${source_dir}
COMMENT "Performing download step (DIR copy) for '${name}'"
DEPENDS ${dir}
)
set(added 1)
endif()
endif(NOT added)
if(NOT added)
get_target_property(tar ${name} AEP_TAR)
if(tar)
add_custom_command(
OUTPUT ${sentinels_dir}/${name}-download
COMMAND ${CMAKE_COMMAND} -Dfilename=${tar} -Dtmp=${tmp_dir}/${name} -Ddirectory=${source_dir}/${name} -P ${CMAKE_ROOT}/Modules/UntarFile.cmake
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/${name}-download
WORKING_DIRECTORY ${source_dir}
COMMENT "Performing download step (TAR untar) for '${name}'"
DEPENDS ${tar}
)
set(added 1)
endif()
endif(NOT added)
if(NOT added)
get_target_property(tgz ${name} AEP_TGZ)
if(tgz)
add_custom_command(
OUTPUT ${sentinels_dir}/${name}-download
COMMAND ${CMAKE_COMMAND} -Dfilename=${tgz} -Dtmp=${tmp_dir}/${name} -Ddirectory=${source_dir}/${name} -P ${CMAKE_ROOT}/Modules/UntarFile.cmake
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/${name}-download
WORKING_DIRECTORY ${source_dir}
COMMENT "Performing download step (TGZ untar) for '${name}'"
DEPENDS ${tgz}
)
set(added 1)
endif()
endif(NOT added)
if(NOT added)
get_target_property(tgz_url ${name} AEP_TGZ_URL)
if(tgz_url)
add_custom_command(
OUTPUT ${sentinels_dir}/${name}-download
COMMAND ${CMAKE_COMMAND} -Dremote=${tgz_url} -Dlocal=${downloads_dir}/${name}.tgz -P ${CMAKE_ROOT}/Modules/DownloadFile.cmake
COMMAND ${CMAKE_COMMAND} -Dfilename=${downloads_dir}/${name} -Dtmp=${tmp_dir}/${name} -Ddirectory=${source_dir}/${name} -P ${CMAKE_ROOT}/Modules/UntarFile.cmake
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/${name}-download
WORKING_DIRECTORY ${source_dir}
COMMENT "Performing download step (TGZ_URL download and untar) for '${name}'"
DEPENDS ${downloads_dir}/${name}.tgz
)
set(added 1)
endif()
endif(NOT added)
if(NOT added)
get_target_property(tar_url ${name} AEP_TAR_URL)
if(tar_url)
add_custom_command(
OUTPUT ${sentinels_dir}/${name}-download
COMMAND ${CMAKE_COMMAND} -Dremote=${tar_url} -Dlocal=${downloads_dir}/${name}.tar -P ${CMAKE_ROOT}/Modules/DownloadFile.cmake
COMMAND ${CMAKE_COMMAND} -Dfilename=${downloads_dir}/${name} -Dtmp=${tmp_dir}/${name} -Ddirectory=${source_dir}/${name} -P ${CMAKE_ROOT}/Modules/UntarFile.cmake
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/${name}-download
WORKING_DIRECTORY ${source_dir}
COMMENT "Performing download step (TAR_URL download and untar) for '${name}'"
DEPENDS ${downloads_dir}/${name}.tar
)
set(added 1)
endif()
endif(NOT added)
if(NOT added)
message(SEND_ERROR "error: no download info for '${name}'")
endif(NOT added)
endfunction(add_external_project_download_command)
function(add_external_project_configure_command name)
get_external_project_directories(base_dir build_dir downloads_dir install_dir
sentinels_dir source_dir tmp_dir)
get_configure_build_working_dir(${name} working_dir)
# Create the working_dir for configure, build and install steps:
#
add_custom_command(
OUTPUT ${working_dir}
COMMAND ${CMAKE_COMMAND} -E make_directory ${working_dir}
DEPENDS ${sentinels_dir}/${name}-download
)
get_target_property(cmd ${name} AEP_CONFIGURE_COMMAND)
if(cmd STREQUAL "")
# Explicit empty string means no configure step for this project
add_custom_command(
OUTPUT ${sentinels_dir}/${name}-configure
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/${name}-configure
WORKING_DIRECTORY ${working_dir}
COMMENT "No configure step for '${name}'"
DEPENDS ${working_dir} ${sentinels_dir}/${name}-download
)
else()
if(NOT cmd)
set(cmd ${CMAKE_COMMAND})
endif()
set(args "")
get_target_property(configure_args ${name} AEP_CONFIGURE_ARGS)
if(configure_args)
set(args "${configure_args}")
separate_arguments(args)
endif()
add_custom_command(
OUTPUT ${sentinels_dir}/${name}-configure
COMMAND ${cmd} ${args}
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/${name}-configure
WORKING_DIRECTORY ${working_dir}
COMMENT "Performing configure step for '${name}'"
DEPENDS ${working_dir} ${sentinels_dir}/${name}-download
)
endif()
endfunction(add_external_project_configure_command)
function(add_external_project_build_command name)
get_external_project_directories(base_dir build_dir downloads_dir install_dir
sentinels_dir source_dir tmp_dir)
get_configure_build_working_dir(${name} working_dir)
get_target_property(cmd ${name} AEP_BUILD_COMMAND)
if(cmd STREQUAL "")
# Explicit empty string means no build step for this project
add_custom_command(
OUTPUT ${sentinels_dir}/${name}-build
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/${name}-build
WORKING_DIRECTORY ${working_dir}
COMMENT "No build step for '${name}'"
DEPENDS ${sentinels_dir}/${name}-configure
)
else()
get_configure_command_id(${name} cfg_cmd_id)
if(NOT cmd)
set(cmd make)
if(cfg_cmd_id STREQUAL "cmake")
set(cmd ${CMAKE_COMMAND})
endif()
endif()
get_target_property(args ${name} AEP_BUILD_ARGS)
if(NOT args)
set(args)
if(cfg_cmd_id STREQUAL "cmake")
set(args --build ${working_dir} --config ${CMAKE_CFG_INTDIR})
endif()
endif()
add_custom_command(
OUTPUT ${sentinels_dir}/${name}-build
COMMAND ${cmd} ${args}
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/${name}-build
WORKING_DIRECTORY ${working_dir}
COMMENT "Performing build step for '${name}'"
DEPENDS ${sentinels_dir}/${name}-configure
)
endif()
endfunction(add_external_project_build_command)
function(add_external_project_install_command name)
get_external_project_directories(base_dir build_dir downloads_dir install_dir
sentinels_dir source_dir tmp_dir)
get_configure_build_working_dir(${name} working_dir)
get_target_property(cmd ${name} AEP_INSTALL_COMMAND)
if(cmd STREQUAL "")
# Explicit empty string means no install step for this project
add_custom_command(
OUTPUT ${sentinels_dir}/${name}-install
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/${name}-install
WORKING_DIRECTORY ${working_dir}
COMMENT "No install step for '${name}'"
DEPENDS ${sentinels_dir}/${name}-build
)
else()
get_configure_command_id(${name} cfg_cmd_id)
if(NOT cmd)
set(cmd make)
if(cfg_cmd_id STREQUAL "cmake")
set(cmd ${CMAKE_COMMAND})
endif()
endif()
get_target_property(args ${name} AEP_INSTALL_ARGS)
if(NOT args)
set(args)
if(cfg_cmd_id STREQUAL "cmake")
set(args --build ${working_dir} --config ${CMAKE_CFG_INTDIR} --target install)
endif()
if(cfg_cmd_id STREQUAL "configure")
set(args "install")
endif()
endif()
add_custom_command(
OUTPUT ${sentinels_dir}/${name}-install
COMMAND ${cmd} ${args}
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/${name}-install
WORKING_DIRECTORY ${working_dir}
COMMENT "Performing install step for '${name}'"
DEPENDS ${sentinels_dir}/${name}-build
)
endif()
endfunction(add_external_project_install_command)
function(add_CMakeExternals_target)
if(NOT TARGET CMakeExternals)
get_external_project_directories(base_dir build_dir downloads_dir install_dir
sentinels_dir source_dir tmp_dir)
add_custom_command(
OUTPUT ${sentinels_dir}/CMakeExternals-directories
COMMAND ${CMAKE_COMMAND} -E make_directory ${build_dir}
COMMAND ${CMAKE_COMMAND} -E make_directory ${downloads_dir}
COMMAND ${CMAKE_COMMAND} -E make_directory ${install_dir}
COMMAND ${CMAKE_COMMAND} -E make_directory ${sentinels_dir}
COMMAND ${CMAKE_COMMAND} -E make_directory ${source_dir}
COMMAND ${CMAKE_COMMAND} -E make_directory ${tmp_dir}
COMMAND ${CMAKE_COMMAND} -E touch ${sentinels_dir}/CMakeExternals-directories
COMMENT "Creating CMakeExternals directories"
)
add_custom_target(CMakeExternals ALL
DEPENDS ${sentinels_dir}/CMakeExternals-directories
)
endif()
endfunction(add_CMakeExternals_target)
function(is_known_aep_property_key key result_var)
set(${result_var} 0 PARENT_SCOPE)
if(key MATCHES "^BUILD_ARGS|BUILD_COMMAND|CONFIGURE_ARGS|CONFIGURE_COMMAND|CONFIGURE_DIR|CVS_REPOSITORY|CVS_MODULE|CVS_TAG|DEPENDS|DOWNLOAD_ARGS|DOWNLOAD_COMMAND|DIR|INSTALL_ARGS|INSTALL_COMMAND|SVN_REPOSITORY|SVN_TAG|TAR|TAR_URL|TGZ|TGZ_URL$"
)
#message(STATUS "info: recognized via MATCHES - key='${key}'")
set(${result_var} 1 PARENT_SCOPE)
else()
message(STATUS "warning: is_known_aep_property_key unknown key='${key}'")
endif()
endfunction(is_known_aep_property_key)
function(add_external_project name)
get_external_project_directories(base_dir build_dir downloads_dir install_dir
sentinels_dir source_dir tmp_dir)
# Ensure root CMakeExternals target and directories are created.
# All external projects will depend on this root CMakeExternals target.
#
add_CMakeExternals_target()
# Add a custom target for the external project and make its DEPENDS
# the output of the final build step:
#
add_custom_target(${name} ALL
DEPENDS ${sentinels_dir}/${name}-install
)
set_target_properties(${name} PROPERTIES AEP_IS_EXTERNAL_PROJECT 1)
add_dependencies(${name} CMakeExternals)
# Transfer the arguments to this function into target properties for the
# new custom target we just added so that we can set up all the build steps
# correctly based on target properties.
#
# Loop over ARGN by 2's extracting key/value pairs from the non-explicit
# arguments to this function:
#
list(LENGTH ARGN n)
set(i 0)
while(i LESS n)
math(EXPR j ${i}+1)
list(GET ARGN ${i} key)
list(GET ARGN ${j} value)
is_known_aep_property_key("${key}" is_known_key)
if(is_known_key)
if(key STREQUAL "DEPENDS")
if(NOT value STREQUAL "")
add_dependencies(${name} ${value})
else()
message(STATUS "warning: empty DEPENDS value in add_external_project")
endif()
else()
set_target_properties(${name} PROPERTIES AEP_${key} "${value}")
endif()
else()
message(SEND_ERROR "error: unknown add_external_project key with name='${name}' key='${key}' value='${value}'")
endif()
math(EXPR i ${i}+2)
endwhile()
# Set up custom build steps based on the target properties.
# Each step depends on the previous one.
#
# The target depends on the output of the final step.
# (Already set up above in the DEPENDS of the add_custom_target command.)
#
add_external_project_download_command(${name})
add_external_project_configure_command(${name})
add_external_project_build_command(${name})
add_external_project_install_command(${name})
endfunction(add_external_project)
|