|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +include_guard() |
| 19 | + |
| 20 | +include(FetchContent) |
| 21 | + |
| 22 | +macro(parse_var arg key value) |
| 23 | + string(REGEX REPLACE "^(.+)=(.+)$" "\\1;\\2" REGEX_RESULT ${arg}) |
| 24 | + list(GET REGEX_RESULT 0 ${key}) |
| 25 | + list(GET REGEX_RESULT 1 ${value}) |
| 26 | +endmacro() |
| 27 | + |
| 28 | +function(FetchContent_MakeAvailableWithArgs dep) |
| 29 | + if(NOT ${dep}_POPULATED) |
| 30 | + FetchContent_Populate(${dep}) |
| 31 | + |
| 32 | + foreach(arg IN LISTS ARGN) |
| 33 | + parse_var(${arg} key value) |
| 34 | + set(${key}_OLD ${${key}}) |
| 35 | + set(${key} ${value} CACHE INTERNAL "") |
| 36 | + endforeach() |
| 37 | + |
| 38 | + add_subdirectory(${${dep}_SOURCE_DIR} ${${dep}_BINARY_DIR} EXCLUDE_FROM_ALL) |
| 39 | + |
| 40 | + foreach(arg IN LISTS ARGN) |
| 41 | + parse_var(${arg} key value) |
| 42 | + set(${key} ${${key}_OLD} CACHE INTERNAL "") |
| 43 | + endforeach() |
| 44 | + endif() |
| 45 | +endfunction() |
| 46 | + |
| 47 | +function(FetchContent_DeclareWithMirror dep url hash) |
| 48 | + FetchContent_Declare(${dep} |
| 49 | + URL ${DEPS_FETCH_PROXY}${url} |
| 50 | + URL_HASH ${hash} |
| 51 | + ) |
| 52 | +endfunction() |
| 53 | + |
| 54 | +function(FetchContent_DeclareGitHubWithMirror dep repo tag hash) |
| 55 | + FetchContent_DeclareWithMirror(${dep} |
| 56 | + https://github.com/${repo}/archive/${tag}.zip |
| 57 | + ${hash} |
| 58 | + ) |
| 59 | +endfunction() |
0 commit comments