ExternalProjectFlags.cmake 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. include(CMakeParseArguments)
  15. # Assemble the git-related arguments to an external project making use of the
  16. # latest features where available but avoiding them when run under CMake
  17. # versions that don't support them.
  18. #
  19. # The complete set of git-related arguments are stored as a list in the
  20. # variable named by RESULT_VAR in the calling scope.
  21. #
  22. # Currently this handles:
  23. # * GIT_SUBMODULES -- added on CMake 3.0 or later. Earlier CMakes will
  24. # check out all submodules.
  25. # * GIT_SHALLOW -- added by default on CMake 3.6 or later. Disable by passing
  26. # GIT_SHALLOW OFF
  27. # * GIT_PROGRESS -- added by default on CMake 3.8 or later. Disable by
  28. # passing GIT_PROGRESS OFF
  29. function(ExternalProject_GitSource RESULT_VAR)
  30. # Parse arguments
  31. set(options "")
  32. set(single_value GIT_REPOSITORY GIT_TAG GIT_PROGRESS GIT_SHALLOW)
  33. set(multi_value GIT_SUBMODULES)
  34. cmake_parse_arguments(EP "${options}" "${single_value}" "${multi_value}" ${ARGN})
  35. set(
  36. result
  37. GIT_REPOSITORY ${EP_GIT_REPOSITORY}
  38. GIT_TAG ${EP_GIT_TAG}
  39. ${EP_UNPARSED_ARGUMENTS}
  40. )
  41. # CMake 3.0 added support for constraining the set of submodules to clone
  42. if(NOT (CMAKE_VERSION VERSION_LESS "3.0") AND EP_GIT_SUBMODULES)
  43. list(APPEND result GIT_SUBMODULES ${EP_GIT_SUBMODULES})
  44. endif()
  45. # CMake 3.6 added support for shallow git clones. Use a shallow clone if
  46. # available
  47. if(NOT (CMAKE_VERSION VERSION_LESS "3.6"))
  48. if(NOT EP_GIT_SHALLOW)
  49. set(EP_GIT_SHALLOW ON)
  50. endif()
  51. list(APPEND result GIT_SHALLOW ${EP_GIT_SHALLOW})
  52. endif()
  53. # CMake 3.8 added support for showing progress for large downloads
  54. if(NOT (CMAKE_VERSION VERSION_LESS "3.8"))
  55. if(NOT EP_GIT_PROGRESS)
  56. set(EP_GIT_PROGRESS ON)
  57. endif()
  58. list(APPEND result GIT_PROGRESS ${EP_GIT_PROGRESS})
  59. endif()
  60. set(${RESULT_VAR} ${result} PARENT_SCOPE)
  61. endfunction()