hgclone.cmake.in 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 ${CMAKE_VERSION}) # this file comes with cmake
  4. if(EXISTS "@hgclone_stampfile@" AND EXISTS "@hgclone_infofile@" AND
  5. "@hgclone_stampfile@" IS_NEWER_THAN "@hgclone_infofile@")
  6. message(VERBOSE
  7. "Avoiding repeated hg clone, stamp file is up to date: "
  8. "'@hgclone_stampfile@'"
  9. )
  10. return()
  11. endif()
  12. # Even at VERBOSE level, we don't want to see the commands executed, but
  13. # enabling them to be shown for DEBUG may be useful to help diagnose problems.
  14. cmake_language(GET_MESSAGE_LOG_LEVEL active_log_level)
  15. if(active_log_level MATCHES "DEBUG|TRACE")
  16. set(maybe_show_command COMMAND_ECHO STDOUT)
  17. else()
  18. set(maybe_show_command "")
  19. endif()
  20. execute_process(
  21. COMMAND ${CMAKE_COMMAND} -E rm -rf "@source_dir@"
  22. RESULT_VARIABLE error_code
  23. ${maybe_show_command}
  24. )
  25. if(error_code)
  26. message(FATAL_ERROR "Failed to remove directory: '@source_dir@'")
  27. endif()
  28. execute_process(
  29. COMMAND "@hg_EXECUTABLE@" clone -U "@hg_repository@" "@src_name@"
  30. WORKING_DIRECTORY "@work_dir@"
  31. RESULT_VARIABLE error_code
  32. ${maybe_show_command}
  33. )
  34. if(error_code)
  35. message(FATAL_ERROR "Failed to clone repository: '@hg_repository@'")
  36. endif()
  37. execute_process(
  38. COMMAND "@hg_EXECUTABLE@" update @hg_tag@
  39. WORKING_DIRECTORY "@work_dir@/@src_name@"
  40. RESULT_VARIABLE error_code
  41. ${maybe_show_command}
  42. )
  43. if(error_code)
  44. message(FATAL_ERROR "Failed to checkout tag: '@hg_tag@'")
  45. endif()
  46. # Complete success, update the script-last-run stamp file:
  47. #
  48. execute_process(
  49. COMMAND ${CMAKE_COMMAND} -E copy "@hgclone_infofile@" "@hgclone_stampfile@"
  50. RESULT_VARIABLE error_code
  51. ${maybe_show_command}
  52. )
  53. if(error_code)
  54. message(FATAL_ERROR "Failed to copy script-last-run stamp file: '@hgclone_stampfile@'")
  55. endif()