You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.6 KiB

2 months ago
  1. # Copyright (c) 2011-2013 Thomas Heller
  2. # Modified by Tom van Dijk
  3. #
  4. # Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. find_package(Git)
  7. if(NOT GIT_FOUND)
  8. message(FATAL_ERROR "Git not found!")
  9. endif()
  10. if(NOT GHPAGES_REPOSITORY)
  11. set(GHPAGES_REPOSITORY git@github.com:trolando/sylvan.git --branch gh-pages)
  12. endif()
  13. if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/gh-pages")
  14. execute_process(
  15. COMMAND "${GIT_EXECUTABLE}" pull --rebase
  16. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gh-pages"
  17. RESULT_VARIABLE git_pull_result)
  18. if(NOT "${git_pull_result}" EQUAL "0")
  19. message(FATAL_ERROR "Updating the GitHub pages branch failed.")
  20. endif()
  21. else()
  22. execute_process(
  23. COMMAND "${GIT_EXECUTABLE}" clone ${GHPAGES_REPOSITORY} gh-pages
  24. RESULT_VARIABLE git_clone_result)
  25. if(NOT "${git_clone_result}" EQUAL "0")
  26. message(FATAL_ERROR "Cloning the GitHub pages branch failed. Trying to clone ${GHPAGES_REPOSITORY}")
  27. endif()
  28. endif()
  29. # first delete all files
  30. file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/gh-pages/*")
  31. # copy all documentation files to target branch
  32. file(COPY "${CMAKE_CURRENT_BINARY_DIR}/html/"
  33. DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/gh-pages"
  34. PATTERN ".doctrees" EXCLUDE
  35. PATTERN ".buildinfo" EXCLUDE
  36. )
  37. # git add -A *
  38. execute_process(
  39. COMMAND "${GIT_EXECUTABLE}" add -A *
  40. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gh-pages"
  41. RESULT_VARIABLE git_add_result)
  42. if(NOT "${git_add_result}" EQUAL "0")
  43. message(FATAL_ERROR "Adding files to the GitHub pages branch failed.")
  44. endif()
  45. # check if there are changes to commit
  46. execute_process(
  47. COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD
  48. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gh-pages"
  49. RESULT_VARIABLE git_diff_index_result)
  50. if(NOT "${git_diff_index_result}" EQUAL "0")
  51. # commit changes
  52. execute_process(
  53. COMMAND "${GIT_EXECUTABLE}" commit -m "Updated documentation"
  54. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gh-pages"
  55. RESULT_VARIABLE git_commit_result)
  56. if(NOT "${git_commit_result}" EQUAL "0")
  57. message(FATAL_ERROR "Commiting to the GitHub pages branch failed.")
  58. endif()
  59. # push everything up to github
  60. execute_process(
  61. COMMAND "${GIT_EXECUTABLE}" push
  62. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gh-pages"
  63. RESULT_VARIABLE git_push_result)
  64. if(NOT "${git_push_result}" EQUAL "0")
  65. message(FATAL_ERROR "Pushing to the GitHub pages branch failed.")
  66. endif()
  67. endif()