gitclone.cmake.in 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. cmake_minimum_required(VERSION 3.5)
  4. set(quiet "@quiet@")
  5. set(script_dir "@CMAKE_CURRENT_FUNCTION_LIST_DIR@/ExternalProject")
  6. include(${script_dir}/captured_process_setup.cmake)
  7. if(NOT "@gitclone_infofile@" IS_NEWER_THAN "@gitclone_stampfile@")
  8. if(NOT quiet)
  9. message(STATUS
  10. "Avoiding repeated git clone, stamp file is up to date: "
  11. "'@gitclone_stampfile@'"
  12. )
  13. endif()
  14. return()
  15. endif()
  16. execute_process(
  17. COMMAND ${CMAKE_COMMAND} -E rm -rf "@source_dir@"
  18. RESULT_VARIABLE error_code
  19. ${capture_output}
  20. )
  21. _ep_command_check_result(
  22. error_code "Failed to remove directory: '@source_dir@'"
  23. )
  24. # try the clone 3 times in case there is an odd git clone issue
  25. set(error_code 1)
  26. set(number_of_tries 0)
  27. while(error_code AND number_of_tries LESS 3)
  28. # If you are seeing the following call hang and you have QUIET enabled, try
  29. # turning QUIET off to show any output immediately. The command may be
  30. # blocking while waiting for user input (e.g. a password to a SSH key).
  31. execute_process(
  32. COMMAND "@git_EXECUTABLE@" @git_options@
  33. clone @git_clone_options@ "@git_repository@" "@src_name@"
  34. WORKING_DIRECTORY "@work_dir@"
  35. RESULT_VARIABLE error_code
  36. ${capture_output}
  37. )
  38. if(NOT "${out_var}" STREQUAL "")
  39. string(APPEND accumulated_output "${out_var}\n")
  40. endif()
  41. math(EXPR number_of_tries "${number_of_tries} + 1")
  42. endwhile()
  43. if(number_of_tries GREATER 1)
  44. set(msg "Had to git clone more than once: ${number_of_tries} times.")
  45. if(quiet)
  46. string(APPEND accumulated_output "${msg}\n")
  47. else()
  48. message(STATUS "${msg}")
  49. endif()
  50. endif()
  51. _ep_command_check_result(
  52. error_code "Failed to clone repository: '@git_repository@'"
  53. )
  54. execute_process(
  55. COMMAND "@git_EXECUTABLE@" @git_options@
  56. checkout "@git_tag@" @git_checkout_explicit--@
  57. WORKING_DIRECTORY "@work_dir@/@src_name@"
  58. RESULT_VARIABLE error_code
  59. ${capture_output}
  60. )
  61. _ep_command_check_result(error_code "Failed to checkout tag: '@git_tag@'")
  62. set(init_submodules @init_submodules@)
  63. if(init_submodules)
  64. execute_process(
  65. COMMAND "@git_EXECUTABLE@" @git_options@
  66. submodule update @git_submodules_recurse@ --init @git_submodules@
  67. WORKING_DIRECTORY "@work_dir@/@src_name@"
  68. RESULT_VARIABLE error_code
  69. ${capture_output}
  70. )
  71. _ep_command_check_result(
  72. error_code "Failed to update submodules in: '@work_dir@/@src_name@'"
  73. )
  74. endif()
  75. # Complete success, update the script-last-run stamp file:
  76. #
  77. execute_process(
  78. COMMAND ${CMAKE_COMMAND} -E copy "@gitclone_infofile@" "@gitclone_stampfile@"
  79. RESULT_VARIABLE error_code
  80. ${capture_output}
  81. )
  82. _ep_command_check_result(
  83. error_code "Failed to copy script-last-run stamp file: '@gitclone_stampfile@'"
  84. )