1 # Copyright (C) 2018-2019 Intel Corporation
2 # SPDX-License-Identifier: Apache-2.0
7 function (resolve_archive_dependency VAR COMPONENT ARCHIVE ARCHIVE_UNIFIED ARCHIVE_WIN ARCHIVE_LIN ARCHIVE_MAC TARGET_PATH FOLDER ENVIRONMENT)
9 if (ENVIRONMENT AND (DEFINED ENV{${ENVIRONMENT}}))
13 if (NOT DEFINED HAS_ENV)
15 #TODO: check whether this is platform specific binary with same name per or it is in common folder
16 DownloadAndExtract(${COMPONENT} ${ARCHIVE} ${TARGET_PATH} result_path ${FOLDER})
18 DownloadAndExtractPlatformSpecific(${COMPONENT} ${ARCHIVE_UNIFIED} ${ARCHIVE_WIN} ${ARCHIVE_LIN} ${ARCHIVE_MAC} ${TARGET_PATH} result_path ${FOLDER})
21 set (${VAR} ${result_path} PARENT_SCOPE)
23 set (${VAR} $ENV{${ENVIRONMENT}} PARENT_SCOPE)
26 endfunction(resolve_archive_dependency)
28 function(resolve_pull_request GITHUB_PULL_REQUEST TARGET_PATH)
29 get_filename_component(FILE_NAME ${GITHUB_PULL_REQUEST} NAME)
31 DownloadAndApply("${PATCH_URL}/${GITHUB_PULL_REQUEST}" "${IE_MAIN_SOURCE_DIR}/${TARGET_PATH}/${FILE_NAME}")
32 endfunction(resolve_pull_request)
34 function(extract_version_from_filename filename regex version)
35 string(REGEX MATCH ${regex} match ${filename})
38 set(${version} ${CMAKE_MATCH_1} PARENT_SCOPE)
40 set(${version} ${filename} PARENT_SCOPE)
42 endfunction(extract_version_from_filename)
44 function(read_version archive regex version_var)
45 extract_version_from_filename(${archive} ${regex} version)
46 set(${version_var} "${version}" CACHE INTERNAL "" FORCE)
47 debug_message(STATUS "${version_var} = " ${version})
48 endfunction(read_version)
50 function (RESOLVE_DEPENDENCY NAME_OF_CMAKE_VAR)
52 list(REMOVE_AT ARGV 0)
53 set(SUPPORTED_ARGS FOLDER ARCHIVE ARCHIVE_UNIFIED ARCHIVE_WIN ARCHIVE_LIN ARCHIVE_MAC TARGET_PATH ENVIRONMENT GITHUB_PULL_REQUEST VERSION_REGEX)
58 #message("one_arg=" ${one_arg})
59 #message("arg=" ${arg})
61 if (";${SUPPORTED_ARGS};" MATCHES ";${arg};")
66 elseif(DEFINED one_arg)
67 set(${one_arg} ${arg})
70 message(FATAL_ERROR "invalid argument passed to resolve dependency: " ${arg})
74 #if last token was bool
80 if (NOT DEFINED ARCHIVE)
84 if (NOT DEFINED ARCHIVE_UNIFIED)
85 SET(ARCHIVE_UNIFIED "OFF")
88 if (NOT DEFINED ARCHIVE_WIN)
89 SET(ARCHIVE_WIN "OFF")
92 if (NOT DEFINED ARCHIVE_LIN)
93 SET(ARCHIVE_LIN "OFF")
96 if (NOT DEFINED ARCHIVE_MAC)
97 SET(ARCHIVE_MAC "OFF")
100 if (NOT DEFINED ENVIRONMENT)
101 set (ENVIRONMENT "OFF")
104 if (NOT DEFINED FOLDER)
110 #for each dependency type have to do separate things
111 if (ARCHIVE_WIN OR ARCHIVE_LIN OR ARCHIVE_MAC OR ARCHIVE OR ARCHIVE_UNIFIED)
112 if (NOT DEFINED TARGET_PATH)
113 message(FATAL_ERROR "TARGET_PATH should be defined for every dependency")
116 resolve_archive_dependency(RESULT ${NAME_OF_CMAKE_VAR} ${ARCHIVE} ${ARCHIVE_UNIFIED} ${ARCHIVE_WIN} ${ARCHIVE_LIN} ${ARCHIVE_MAC} ${TARGET_PATH} ${FOLDER} ${ENVIRONMENT})
117 set(${NAME_OF_CMAKE_VAR} ${RESULT} PARENT_SCOPE)
119 GetNameAndUrlToDownload(archive RELATIVE_URL ${ARCHIVE_UNIFIED} ${ARCHIVE_WIN} ${ARCHIVE_LIN} ${ARCHIVE_MAC})
121 read_version(${archive} ${VERSION_REGEX} "${NAME_OF_CMAKE_VAR}_VERSION")
125 elseif (DEFINED GITHUB_PULL_REQUEST)
126 resolve_pull_request(${GITHUB_PULL_REQUEST} ${TARGET_PATH})
128 message(FATAL_ERROR "Dependency of unknowntype, SHOULD set one of ARCHIVE_WIN, ARCHIVE, ARCHIVE_LIN, ARCHIVE_MAC, GITHUB_PULL_REQUEST")
131 endfunction(RESOLVE_DEPENDENCY)