|
| 1 | +# Copyright 2018 Google |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +include(CMakeParseArguments) |
| 16 | + |
| 17 | +# Assemble the git-related arguments to an external project making use of the |
| 18 | +# latest features where available but avoiding them when run under CMake |
| 19 | +# versions that don't support them. |
| 20 | +# |
| 21 | +# The complete set of git-related arguments are stored as a list in the |
| 22 | +# variable named by RESULT_VAR in the calling scope. |
| 23 | +# |
| 24 | +# Currently this handles: |
| 25 | +# * GIT_SUBMODULES -- added on CMake 3.0 or later. Earlier CMakes will |
| 26 | +# check out all submodules. |
| 27 | +# * GIT_SHALLOW -- added by default on CMake 3.6 or later. Disable by passing |
| 28 | +# GIT_SHALLOW OFF |
| 29 | +# * GIT_PROGRESS -- added by default on CMake 3.8 or later. Disable by |
| 30 | +# passing GIT_PROGRESS OFF |
| 31 | +function(ExternalProject_GitSource RESULT_VAR) |
| 32 | + # Parse arguments |
| 33 | + set(options "") |
| 34 | + set(single_value GIT_REPOSITORY GIT_TAG GIT_PROGRESS GIT_SHALLOW) |
| 35 | + set(multi_value GIT_SUBMODULES) |
| 36 | + cmake_parse_arguments(EP "${options}" "${single_value}" "${multi_value}" ${ARGN}) |
| 37 | + |
| 38 | + set( |
| 39 | + result |
| 40 | + GIT_REPOSITORY ${EP_GIT_REPOSITORY} |
| 41 | + GIT_TAG ${EP_GIT_TAG} |
| 42 | + ${EP_UNPARSED_ARGUMENTS} |
| 43 | + ) |
| 44 | + |
| 45 | + # CMake 3.0 added support for constraining the set of submodules to clone |
| 46 | + if(NOT (CMAKE_VERSION VERSION_LESS "3.0") AND EP_GIT_SUBMODULES) |
| 47 | + list(APPEND result GIT_SUBMODULES ${EP_GIT_SUBMODULES}) |
| 48 | + endif() |
| 49 | + |
| 50 | + # CMake 3.6 added support for shallow git clones. Use a shallow clone if |
| 51 | + # available |
| 52 | + if(NOT (CMAKE_VERSION VERSION_LESS "3.6")) |
| 53 | + if(NOT EP_GIT_SHALLOW) |
| 54 | + set(EP_GIT_SHALLOW ON) |
| 55 | + endif() |
| 56 | + |
| 57 | + list(APPEND result GIT_SHALLOW ${EP_GIT_SHALLOW}) |
| 58 | + endif() |
| 59 | + |
| 60 | + # CMake 3.8 added support for showing progress for large downloads |
| 61 | + if(NOT (CMAKE_VERSION VERSION_LESS "3.8")) |
| 62 | + if(NOT EP_GIT_PROGRESS) |
| 63 | + set(EP_GIT_PROGRESS ON) |
| 64 | + endif() |
| 65 | + |
| 66 | + list(APPEND result GIT_PROGRESS ${EP_GIT_PROGRESS}) |
| 67 | + endif() |
| 68 | + |
| 69 | + set(${RESULT_VAR} ${result} PARENT_SCOPE) |
| 70 | + |
| 71 | +endfunction() |
0 commit comments