-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFetchDependency.cmake
More file actions
519 lines (443 loc) · 22 KB
/
FetchDependency.cmake
File metadata and controls
519 lines (443 loc) · 22 KB
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
# Minimum CMake version required. Currently driven by the use of GET_MESSAGE_LOG_LEVEL:
# https://cmake.org/cmake/help/latest/command/cmake_language.html#get-message-log-level
set(MinimumCMakeVersion "3.25")
if(${CMAKE_VERSION} VERSION_LESS ${MinimumCMakeVersion})
message(FATAL_ERROR "FetchDependency requires CMake ${MinimumCMakeVersion} (currently using ${CMAKE_VERSION})")
endif()
# The storage version reflects how we handle the build, package and state directories and store derived dependency data
# in them. When it changes, those directories are refreshed.
set(StorageVersion "1")
function(_fd_run)
cmake_parse_arguments(FDR "" "WORKING_DIRECTORY;ERROR_CONTEXT;OUT_STDOUT;OUT_STDERR" "COMMAND" ${ARGN})
if(NOT FDR_WORKING_DIRECTORY)
set(FDR_WORKING_DIRECTORY "")
endif()
cmake_language(GET_MESSAGE_LOG_LEVEL Level)
if((${Level} STREQUAL "VERBOSE") OR (${Level} STREQUAL "DEBUG") OR (${Level} STREQUAL "TRACE"))
set(EchoOutput "ECHO_OUTPUT_VARIABLE")
set(EchoError "ECHO_ERROR_VARIABLE")
endif()
string(REPLACE ";" " " Command "${FDR_COMMAND}")
message(VERBOSE ">> ${Command}")
execute_process(
COMMAND ${FDR_COMMAND}
OUTPUT_VARIABLE Output
ERROR_VARIABLE Error
RESULT_VARIABLE Result
WORKING_DIRECTORY "${FDR_WORKING_DIRECTORY}"
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
${EchoOutput}
${EchoError}
)
if(Result)
if(FDR_OUT_STDERR)
set(${FDR_OUT_STDERR} ${Error} PARENT_SCOPE)
else()
message(FATAL_ERROR "${FDR_ERROR_CONTEXT} (${Result})\n${Output}\n${Error}")
endif()
endif()
if(FDR_OUT_STDOUT)
set(${FDR_OUT_STDOUT} ${Output} PARENT_SCOPE)
endif()
endfunction()
# This function computes the hash of the given script and compares it to the previous hash stored in the hash file.
# It returns whether or not the step should run in the variable specified by FDCS_RESULT. The current hash is returned
# in the variable specified by FDCS_RESULT_HASH.
function(_fd_check_step FDCS_SCRIPT_FILE FDCS_HASH_FILE FDCS_RESULT FDCS_RESULT_HASH)
file(MD5 "${FDCS_SCRIPT_FILE}" CurrentHash)
set(PreviousHash "")
if(EXISTS "${FDCS_HASH_FILE}")
file(READ "${FDCS_HASH_FILE}" PreviousHash)
endif()
set(${FDCS_RESULT_HASH} "${CurrentHash}" PARENT_SCOPE)
if("${CurrentHash}" STREQUAL "${PreviousHash}")
set(${FDCS_RESULT} FALSE PARENT_SCOPE)
else()
set(${FDCS_RESULT} TRUE PARENT_SCOPE)
endif()
endfunction()
function(_fd_find FDF_NAME)
cmake_parse_arguments(FDF "" "ROOT" "PATHS" ${ARGN})
set(SavedPrefixPath ${CMAKE_PREFIX_PATH})
set(CMAKE_PREFIX_PATH "${FDF_PATHS}")
find_package(${FDF_NAME} QUIET PATHS ${FDF_ROOT})
if(NOT ${FDF_NAME}_FOUND)
# Try using PkgConfig to locate the dependency.
find_package(PkgConfig QUIET)
if(NOT PkgConfig_FOUND)
message(FATAL_ERROR "Dependency '${FDF_NAME}' does not export targets for use with find_package().")
endif()
pkg_search_module(${FDF_NAME} QUIET NO_CMAKE_ENVIRONMENT_PATH IMPORTED_TARGET ${FDF_NAME})
if(NOT ${FDF_NAME}_FOUND)
message(FATAL_ERROR "Dependency '${FDF_NAME}' does not export targets for use with find_package() or PkgConfig.")
endif()
endif()
set(CMAKE_PREFIX_PATH ${SavedPrefixPath})
endfunction()
function(declare_dependency DD_NAME)
cmake_parse_arguments(DD
""
"CONFIGURATION;OUT_BINARY_DIR"
"CONFIGURE_OPTIONS;BUILD_OPTIONS"
${ARGN}
)
if(NOT DD_CONFIGURATION)
message(FATAL_ERROR "CONFIGURATION must be provided")
endif()
message(VERBOSE "-- Configuring dependency ${DD_NAME} (${DD_CONFIGURATION})")
set(_fd_${DD_NAME}_${DD_CONFIGURATION}_ConfigureOptions ${DD_CONFIGURE_OPTIONS} PARENT_SCOPE)
set(_fd_${DD_NAME}_${DD_CONFIGURATION}_BuildOptions ${DD_BUILD_OPTIONS} PARENT_SCOPE)
list(APPEND _fd_${DD_NAME}_Configurations ${DD_CONFIGURATION})
set(_fd_${DD_NAME}_Configurations ${_fd_${DD_NAME}_Configurations} PARENT_SCOPE)
if(DD_OUT_BINARY_DIR)
set(_fd_${DD_NAME}_${DD_CONFIGURATION}_BinaryDirectoryVariable "${DD_OUT_BINARY_DIR}" PARENT_SCOPE)
endif()
endfunction()
function(fetch_dependency FD_NAME)
cmake_parse_arguments(FD
"GIT_DISABLE_SUBMODULES;GIT_DISABLE_SUBMODULE_RECURSION;NO_RESOLVE;NO_BUILD"
"SOURCE_ROOT;BINARY_ROOT;GIT_SOURCE;LOCAL_SOURCE;VERSION;PACKAGE_NAME;GENERATOR;CONFIGURATION;CMAKELIST_SUBDIRECTORY;LIST_SEPARATOR;OUT_SOURCE_DIR"
"GIT_SUBMODULES;CONFIGURE_OPTIONS;BUILD_OPTIONS"
${ARGN}
)
get_property(Role GLOBAL PROPERTY CMAKE_ROLE)
set(IsScriptMode FALSE)
if("${Role}" STREQUAL "SCRIPT")
set(IsScriptMode TRUE)
# find_package() won't work in script mode (the scripts it finds will almost always call add_library() to create the
# neccessary imported targets).
set(FD_NO_RESOLVE TRUE)
endif()
set(FastMode OFF)
set(FastModeNotice "")
if($ENV{FETCH_DEPENDENCY_FAST})
set(FastMode ON)
set(FastModeNotice " (fast)")
endif()
message(STATUS "Checking dependency ${FD_NAME}${FastModeNotice}")
if(NOT FD_GENERATOR)
if(IsScriptMode)
# In script mode, CMake will not have a generator defined.
message(FATAL_ERROR "GENERATOR must be provided when running in script mode.")
endif()
set(FD_GENERATOR "${CMAKE_GENERATOR}")
endif()
message(VERBOSE "-- Using generator: ${FD_GENERATOR}")
# Process the source arguments.
set(SourceMode "")
if(FD_LOCAL_SOURCE)
if(FD_GIT_SOURCE)
message(AUTHOR_WARNING "LOCAL_SOURCE and GIT_SOURCE are mutually exclusive, LOCAL_SOURCE will be used")
endif()
if(FD_VERSION)
message(AUTHOR_WARNING "VERSION is ignored when LOCAL_SOURCE is provided")
endif()
set(SourceMode "local")
elseif(FD_GIT_SOURCE)
if(NOT FD_VERSION)
message(FATAL_ERROR "VERSION must be provided")
endif()
set(SourceMode "git")
else()
message(FATAL_ERROR "LOCAL_SOURCE or GIT_SOURCE must be provided")
endif()
if(FD_GIT_DISABLE_SUBMODULES)
set(IsSubmoduleUpdateEnabled FALSE)
else()
set(IsSubmoduleUpdateEnabled TRUE)
endif()
if(FD_GIT_DISABLE_SUBMODULE_RECURSION)
set(SubmoduleRecursiveFlag "")
else()
set(SubmoduleRecursiveFlag "--recursive")
endif()
if(NOT FD_PACKAGE_NAME)
set(FD_PACKAGE_NAME "${FD_NAME}")
endif()
if(NOT FD_SOURCE_ROOT)
if(FETCH_DEPENDENCY_DEFAULT_SOURCE_ROOT)
set(FD_SOURCE_ROOT "${FETCH_DEPENDENCY_DEFAULT_SOURCE_ROOT}")
else()
set(FD_SOURCE_ROOT "External")
endif()
endif()
if(NOT FD_BINARY_ROOT)
if(FETCH_DEPENDENCY_DEFAULT_BINARY_ROOT)
set(FD_BINARY_ROOT "${FETCH_DEPENDENCY_DEFAULT_BINARY_ROOT}")
else()
set(FD_BINARY_ROOT "External")
endif()
endif()
# If the roots are relative, they are interpreted as being relative to the current binary directory.
cmake_path(IS_RELATIVE FD_SOURCE_ROOT IsSourceRootRelative)
if(IsSourceRootRelative)
cmake_path(APPEND CMAKE_BINARY_DIR ${FD_SOURCE_ROOT} OUTPUT_VARIABLE FD_SOURCE_ROOT)
endif()
cmake_path(IS_RELATIVE FD_BINARY_ROOT IsBinaryRootRelative)
if(IsBinaryRootRelative)
cmake_path(APPEND CMAKE_BINARY_DIR ${FD_BINARY_ROOT} OUTPUT_VARIABLE FD_BINARY_ROOT)
endif()
cmake_path(SET FD_SOURCE_ROOT NORMALIZE "${FD_SOURCE_ROOT}")
cmake_path(SET FD_BINARY_ROOT NORMALIZE "${FD_BINARY_ROOT}")
set(ProjectDirectory "${FD_BINARY_ROOT}/${FD_NAME}")
set(BuildDirectory "${ProjectDirectory}/Build")
set(PackageDirectory "${ProjectDirectory}/Package")
set(StateDirectory "${ProjectDirectory}/State")
# The source file tracks the source mode and value when the dependency was last processed.
set(SourceFilePath "${StateDirectory}/source.txt")
# The version file tracks the version of FetchDependency that last processed the dependency.
set(VersionFilePath "${StateDirectory}/version.txt")
# The manifest file contains the package directories of every dependency fetched for the calling project so far.
set(ManifestFile "FetchedDependencies.txt")
set(ManifestFilePath "${CMAKE_BINARY_DIR}/${ManifestFile}")
if("${SourceMode}" STREQUAL "local")
set(SourceDirectory "${FD_LOCAL_SOURCE}")
else()
# If the source and binary roots are the same, the source is nested. This preserves the older behavior, prior to
# splitting the two roots. It also prevents the binary subdirectories from modifying the source working tree.
if("${FD_SOURCE_ROOT}" STREQUAL "${FD_BINARY_ROOT}")
set(SourceDirectory "${FD_SOURCE_ROOT}/Source/${FD_NAME}")
else()
set(SourceDirectory "${FD_SOURCE_ROOT}/${FD_NAME}")
endif()
endif()
if(UNIX)
set(ScriptHeader "#!/bin/sh")
set(ScriptSet "export")
set(ScriptExtension "sh")
else()
set(ScriptHeader "@echo off")
set(ScriptSet "set")
set(ScriptExtension "bat")
endif()
set(ConfigureScriptTemplateFilePath "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Steps/configure.in")
set(BuildScriptTemplateFilePath "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Steps/build.in")
list(APPEND FETCH_DEPENDENCY_PACKAGE_PATHS "${PackageDirectory}")
if(FD_OUT_SOURCE_DIR)
set(${FD_OUT_SOURCE_DIR} "${SourceDirectory}" PARENT_SCOPE)
endif()
get_property(IsMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
set(BuildNeededMessage "")
# Check the source stamp. If it changed, the whole dependency needs to be refreshed.
set(RequiredSourceStamp "${SourceMode}: ${SourceDirectory}")
set(PreviousSourceStamp "")
if(EXISTS "${SourceFilePath}")
file(READ "${SourceFilePath}" PreviousSourceStamp)
if(NOT "${RequiredSourceStamp}" STREQUAL "${PreviousSourceStamp}")
message(STATUS "Updating (source changed)")
file(REMOVE_RECURSE "${ProjectDirectory}")
endif()
else()
message(STATUS "Downloading (source missing)")
file(REMOVE_RECURSE "${ProjectDirectory}")
endif()
# Check the version stamp. If it changed, the build, package and state directories need to be refreshed.
if(EXISTS ${VersionFilePath})
file(READ ${VersionFilePath} PreviousVersion)
if(NOT "${StorageVersion}" STREQUAL "${PreviousVersion}")
message(STATUS "Updating (storage format changed)")
file(REMOVE_RECURSE "${BuildDirectory}")
file(REMOVE_RECURSE "${PackageDirectory}")
file(REMOVE_RECURSE "${StateDirectory}")
endif()
endif()
if("${SourceMode}" STREQUAL "git")
# Ensure the source directory exists and is up to date.
set(IsFetchRequired FALSE)
if(NOT IS_DIRECTORY "${SourceDirectory}")
_fd_run(COMMAND git clone ${FD_GIT_SOURCE} "${SourceDirectory}")
if(IsSubmoduleUpdateEnabled)
_fd_run(COMMAND git submodule update --init ${SubmoduleRecursiveFlag} ${FD_GIT_SUBMODULES} WORKING_DIRECTORY "${SourceDirectory}")
endif()
elseif(NOT FastMode)
# If the directory exists, before doing anything else, make sure the it is in a clean state. Any local changes are
# assumed to be intentional and prevent attempts to update.
_fd_run(COMMAND git status --porcelain WORKING_DIRECTORY "${SourceDirectory}" OUT_STDOUT GitStatus)
if(NOT "${GitStatus}" STREQUAL "")
message(AUTHOR_WARNING "Source has local changes, update suppressed (${SourceDirectory})")
else()
# Determine what the required version refers to in order to decide if we need to fetch from the remote or not.
_fd_run(COMMAND git show-ref ${FD_VERSION} WORKING_DIRECTORY "${SourceDirectory}" OUT_STDOUT ShowRefOutput OUT_STDERR DiscardedError)
if(${ShowRefOutput} MATCHES "^[a-z0-9]+[ \\t]+refs/(remotes|tags)/")
# The version is a branch name (with remote) or a tag. The underlying commit can move, so a fetch is required.
set(IsFetchRequired TRUE)
elseif(${ShowRefOutput} MATCHES "^[a-z0-9]+[ \\t]+refs/heads/")
# The version is a branch name without a remote. We don't allow this; the remote name must be specified.
message(FATAL_ERROR "VERSION must include a remote when referring to branch (e.g., 'origin/branch' instead of 'branch')")
else()
# The version is a commit hash. This is the ideal case, because if the current and required commits match we can
# skip the fetch entirely.
_fd_run(COMMAND git rev-parse HEAD^0 WORKING_DIRECTORY "${SourceDirectory}" OUT_STDOUT ExistingCommit)
_fd_run(COMMAND git rev-parse ${FD_VERSION}^0 WORKING_DIRECTORY "${SourceDirectory}" OUT_STDOUT RequiredCommit OUT_STDERR RevParseError)
if(NOT "${ExistingCommit}" STREQUAL "${RequiredCommit}")
# They don't match, so we have to fetch.
set(IsFetchRequired TRUE)
endif()
endif()
if(IsFetchRequired)
_fd_run(COMMAND git fetch --tags WORKING_DIRECTORY "${SourceDirectory}")
if(IsSubmoduleUpdateEnabled)
_fd_run(COMMAND git submodule update --init ${SubmoduleRecursiveFlag} ${FD_GIT_SUBMODULES} WORKING_DIRECTORY "${SourceDirectory}")
endif()
endif()
endif()
endif()
_fd_run(COMMAND git rev-parse HEAD^0 WORKING_DIRECTORY "${SourceDirectory}" OUT_STDOUT ExistingCommit)
_fd_run(COMMAND git rev-parse ${FD_VERSION}^0 WORKING_DIRECTORY "${SourceDirectory}" OUT_STDOUT RequiredCommit)
if(NOT "${ExistingCommit}" STREQUAL "${RequiredCommit}")
_fd_run(COMMAND git -c advice.detachedHead=false checkout ${FD_VERSION} WORKING_DIRECTORY "${SourceDirectory}")
if(IsSubmoduleUpdateEnabled)
_fd_run(COMMAND git submodule update --init ${SubmoduleRecursiveFlag} ${FD_GIT_SUBMODULES} WORKING_DIRECTORY "${SourceDirectory}")
endif()
set(BuildNeededMessage "new version")
endif()
elseif("${SourceMode}" STREQUAL "local")
set(BuildNeededMessage "local source")
endif()
file(WRITE "${SourceFilePath}" "${RequiredSourceStamp}")
if(NOT FD_NO_BUILD)
if(NOT FastMode)
# If CONFIGURATION is provided, allow explicitly-specified configure or build options to override those provided
# by declare_dependency().
if(FD_CONFIGURATION)
list(FIND _fd_${FD_NAME}_Configurations ${FD_CONFIGURATION} ThisConfigurationIndex)
if(${ThisConfigurationIndex} LESS 0)
# declare_dependency() was never called, so do so now.
declare_dependency(${FD_NAME} CONFIGURATION ${FD_CONFIGURATION} CONFIGURE_OPTIONS ${FD_CONFIGURE_OPTIONS} BUILD_OPTIONS ${FD_BUILD_OPTIONS})
else()
# Replace the options previously given to declare_dependency().
if(FD_CONFIGURE_OPTIONS)
set(${_fd_${FD_NAME}_${ConfigurationName}_ConfigureOptions} ${FD_CONFIGURE_OPTIONS})
endif()
if(FD_BUILD_OPTIONS)
set(${_fd_${FD_NAME}_${ConfigurationName}_BuildOptions} ${FD_BUILD_OPTIONS})
endif()
endif()
else()
# If CONFIGURATION isn't specified, there must have been at least one prior call to declare_dependency().
list(LENGTH _fd_${FD_NAME}_Configurations ConfigurationCount)
if(${ConfigurationCount} LESS_EQUAL 0)
message(FATAL_ERROR "CONFIGURATION must be provided if declare_dependency() has not been called")
endif()
# Additionally, if CONFIGURATION isn't specified, it doesn't make sense for options to be provided.
if(FD_CONFIGURE_OPTIONS)
message(FATAL_ERROR "CONFIGURE_OPTIONS must not be provided if no CONFIGURATION is provided")
endif()
if(FD_BUILD_OPTIONS)
message(FATAL_ERROR "BUILD_OPTIONS must not be provided if no CONFIGURATION is provided")
endif()
endif()
# This list holds the dependencies of the current dependency that need to be propagated. Each configuration likely
# has the same dependencies, but it's not guaranteed. Every dependency referenced is collected in this list, which
# is then de-duplicated before resolution.
set(PropagatedPackages "")
foreach(ConfigurationName ${_fd_${FD_NAME}_Configurations})
message(STATUS "Preparing configuration ${ConfigurationName}")
if(_fd_${FD_NAME}_${ConfigurationName}_BinaryDirectoryVariable)
set(${_fd_${FD_NAME}_${ConfigurationName}_BinaryDirectoryVariable} "${BuildDirectory}/${ConfigurationName}" PARENT_SCOPE)
endif()
set(ConfigureScriptFilePath "${StateDirectory}/${ConfigurationName}/configure.${ScriptExtension}")
set(ConfigureScriptHashFilePath "${StateDirectory}/${ConfigurationName}/last-configure.txt")
set(BuildScriptFilePath "${StateDirectory}/${ConfigurationName}/build.${ScriptExtension}")
set(BuildScriptHashFilePath "${StateDirectory}/${ConfigurationName}/last-build.txt")
list(APPEND ConfigureArguments "-DCMAKE_INSTALL_PREFIX=${PackageDirectory}")
list(APPEND ConfigureArguments ${_fd_${FD_NAME}_${ConfigurationName}_ConfigureOptions})
list(APPEND BuildArguments ${_fd_${FD_NAME}_${ConfigurationName}_BuildOptions})
if(CMAKE_TOOLCHAIN_FILE)
list(APPEND ConfigureArguments " --toolchain ${CMAKE_TOOLCHAIN_FILE}")
endif()
# Configuration handling differs for single- versus multi-config generators. Note that we use a unique directory
# per configuration even when multi-configuration generators are used because this allows each configuration to
# have its own set of generated properties (stored in ConfigureArguments), preserving the same behavior as with
# single-configuration generators.
if(IsMultiConfig)
list(APPEND BuildArguments "--config ${ConfigurationName}")
else()
list(APPEND ConfigureArguments "-DCMAKE_BUILD_TYPE=${ConfigurationName}")
endif()
# When invoking CMake, the package paths are passed via the CMAKE_PREFIX_PATH environment variable. This avoids a
# warning that would otherwise be generated if the dependency never actually caused CMAKE_PREFIX_PATH to be
# referenced. Note that the platform path delimiter must be used to separate individual paths in this case.
set(Packages ${FETCH_DEPENDENCY_PACKAGE_PATHS})
if(UNIX)
string(REPLACE ";" ":" Packages "${Packages}")
endif()
string(REPLACE ";" " " ConfigureArguments "${ConfigureArguments}")
if(FD_LIST_SEPARATOR)
string(REPLACE ${FD_LIST_SEPARATOR} ";" ConfigureArguments "${ConfigureArguments}")
endif()
configure_file(
"${ConfigureScriptTemplateFilePath}"
"${ConfigureScriptFilePath}"
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ
)
_fd_check_step("${ConfigureScriptFilePath}" "${ConfigureScriptHashFilePath}" IsConfigureNeeded ConfigureScriptHash)
string(REPLACE ";" " " BuildArguments "${BuildArguments}")
if(FD_LIST_SEPARATOR)
string(REPLACE ${FD_LIST_SEPARATOR} ";" BuildArguments "${BuildArguments}")
endif()
configure_file(
"${BuildScriptTemplateFilePath}"
"${BuildScriptFilePath}"
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ
)
_fd_check_step("${BuildScriptFilePath}" "${BuildScriptHashFilePath}" IsBuildNeeded BuildScriptHash)
if(IsConfigureNeeded)
set(BuildNeededMessage "new configure options")
elseif(IsBuildNeeded)
set(BuildNeededMessage "new build options")
endif()
if(NOT "${BuildNeededMessage}" STREQUAL "")
message(STATUS "Building (${BuildNeededMessage})")
if(IsConfigureNeeded)
_fd_run(COMMAND "${ConfigureScriptFilePath}" ERROR_CONTEXT "Configure failed: ")
file(WRITE "${ConfigureScriptHashFilePath}" ${ConfigureScriptHash})
endif()
_fd_run(COMMAND "${BuildScriptFilePath}" ERROR_CONTEXT "Build failed: ")
file(WRITE "${BuildScriptHashFilePath}" ${BuildScriptHash})
endif()
# Read the dependency's package manifest and propagate its dependencies.
set(DependencyManifestFilePath "${BuildDirectory}/${ConfigurationName}/${ManifestFile}")
if(EXISTS "${DependencyManifestFilePath}")
file(STRINGS "${DependencyManifestFilePath}" DependencyPackages)
foreach(DependencyPackage ${DependencyPackages})
list(APPEND PropagatedPackages "${DependencyPackage}")
endforeach()
endif()
endforeach()
list(REMOVE_DUPLICATES PropagatedPackages)
foreach(Propagated ${PropagatedPackages})
# Ensure the package is propagated down.
list(APPEND FETCH_DEPENDENCY_PACKAGE_PATHS "${Propagated}")
string(REGEX REPLACE "/Package$" "" PackageName "${Propagated}")
cmake_path(GET PackageName FILENAME PackageName)
# Resolve the dependency in the context of the calling project. This ensures that if the dependency includes
# them in its link interface, they're loaded when CMake tries to actually link with the this dependency.
_fd_find(${PackageName} ROOT ${DependencyPackage} PATHS ${FETCH_DEPENDENCY_PACKAGE_PATHS})
endforeach()
endif()
if(NOT FD_NO_RESOLVE)
# Write the most up-to-date package manifest so that anything downstream of the calling project will know where its
# dependencies were written to.
string(REPLACE ";" "\n" ManifestContent "${FETCH_DEPENDENCY_PACKAGE_PATHS}")
file(WRITE ${ManifestFilePath} "${ManifestContent}\n")
_fd_find(${FD_PACKAGE_NAME} ROOT ${PackageDirectory} PATHS ${DependencyPackages} ${FETCH_DEPENDENCY_PACKAGE_PATHS})
endif()
# Propagate the updated package directory list.
set(FETCH_DEPENDENCY_PACKAGE_PATHS "${FETCH_DEPENDENCY_PACKAGE_PATHS}" PARENT_SCOPE)
endif()
# The dependency was fully-processed, so stamp it with the current storage version.
file(WRITE ${VersionFilePath} "${StorageVersion}")
list(APPEND FETCH_DEPENDENCY_PACKAGE_NAMES "${FD_PACKAGE_NAME}")
set(FETCH_DEPENDENCY_PACKAGE_NAMES "${FETCH_DEPENDENCY_PACKAGE_NAMES}" PARENT_SCOPE)
message(STATUS "Checking dependency ${FD_NAME} - done")
endfunction()
function(export_dependencies)
cmake_parse_arguments(ED "NO_FINDPACKAGE" "PATH" "" ${ARGN})
set(FindPackageCalls "")
foreach(Name ${FETCH_DEPENDENCY_PACKAGE_NAMES})
set(FindPackageCalls "${FindPackageCalls}\n find_package(\"${Name}\")")
endforeach()
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Steps/import.cmake.in" "${ED_PATH}")
endfunction()