FindSubversion.cmake 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # - Extract information from a subversion working copy
  2. # The module defines the following variables:
  3. # Subversion_SVN_EXECUTABLE - path to svn command line client
  4. # Subversion_VERSION_SVN - version of svn command line client
  5. # Subversion_FOUND - true if the command line client was found
  6. # If the command line client executable is found the macro
  7. # Subversion_WC_INFO(<dir> <var-prefix>)
  8. # is defined to extract information of a subversion working copy at
  9. # a given location. The macro defines the following variables:
  10. # <var-prefix>_WC_URL - url of the repository (at <dir>)
  11. # <var-prefix>_WC_ROOT - root url of the repository
  12. # <var-prefix>_WC_REVISION - current revision
  13. # <var-prefix>_WC_LAST_CHANGED_AUTHOR - author of last commit
  14. # <var-prefix>_WC_LAST_CHANGED_DATE - date of last commit
  15. # <var-prefix>_WC_LAST_CHANGED_REV - revision of last commit
  16. # <var-prefix>_WC_LAST_CHANGED_LOG - last log of base revision
  17. # <var-prefix>_WC_INFO - output of command `svn info <dir>'
  18. # Example usage:
  19. # FIND_PACKAGE(Subversion)
  20. # IF(Subversion_FOUND)
  21. # Subversion_WC_INFO(${PROJECT_SOURCE_DIR} Project)
  22. # MESSAGE("Current revision is ${Project_WC_REVISION}")
  23. # Subversion_WC_LOG(${PROJECT_SOURCE_DIR} Project)
  24. # MESSAGE("Last changed log is ${Project_LAST_CHANGED_LOG}")
  25. # ENDIF(Subversion_FOUND)
  26. #=============================================================================
  27. # Copyright 2006-2009 Kitware, Inc.
  28. # Copyright 2006 Tristan Carel
  29. #
  30. # Distributed under the OSI-approved BSD License (the "License");
  31. # see accompanying file Copyright.txt for details.
  32. #
  33. # This software is distributed WITHOUT ANY WARRANTY; without even the
  34. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  35. # See the License for more information.
  36. #=============================================================================
  37. # (To distributed this file outside of CMake, substitute the full
  38. # License text for the above reference.)
  39. SET(Subversion_FOUND FALSE)
  40. SET(Subversion_SVN_FOUND FALSE)
  41. FIND_PROGRAM(Subversion_SVN_EXECUTABLE svn
  42. DOC "subversion command line client")
  43. MARK_AS_ADVANCED(Subversion_SVN_EXECUTABLE)
  44. IF(Subversion_SVN_EXECUTABLE)
  45. SET(Subversion_SVN_FOUND TRUE)
  46. SET(Subversion_FOUND TRUE)
  47. MACRO(Subversion_WC_INFO dir prefix)
  48. # the subversion commands should be executed with the C locale, otherwise
  49. # the message (which are parsed) may be translated, Alex
  50. SET(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
  51. SET(ENV{LC_ALL} C)
  52. EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} --version
  53. WORKING_DIRECTORY ${dir}
  54. OUTPUT_VARIABLE Subversion_VERSION_SVN
  55. OUTPUT_STRIP_TRAILING_WHITESPACE)
  56. EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} info ${dir}
  57. OUTPUT_VARIABLE ${prefix}_WC_INFO
  58. ERROR_VARIABLE Subversion_svn_info_error
  59. RESULT_VARIABLE Subversion_svn_info_result
  60. OUTPUT_STRIP_TRAILING_WHITESPACE)
  61. IF(NOT ${Subversion_svn_info_result} EQUAL 0)
  62. MESSAGE(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}")
  63. ELSE(NOT ${Subversion_svn_info_result} EQUAL 0)
  64. STRING(REGEX REPLACE "^(.*\n)?svn, version ([.0-9]+).*"
  65. "\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}")
  66. STRING(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
  67. "\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}")
  68. STRING(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
  69. "\\2" ${prefix}_WC_REVISION "${${prefix}_WC_INFO}")
  70. STRING(REGEX REPLACE "^(.*\n)?Last Changed Author: ([^\n]+).*"
  71. "\\2" ${prefix}_WC_LAST_CHANGED_AUTHOR "${${prefix}_WC_INFO}")
  72. STRING(REGEX REPLACE "^(.*\n)?Last Changed Rev: ([^\n]+).*"
  73. "\\2" ${prefix}_WC_LAST_CHANGED_REV "${${prefix}_WC_INFO}")
  74. STRING(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*"
  75. "\\2" ${prefix}_WC_LAST_CHANGED_DATE "${${prefix}_WC_INFO}")
  76. ENDIF(NOT ${Subversion_svn_info_result} EQUAL 0)
  77. # restore the previous LC_ALL
  78. SET(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
  79. ENDMACRO(Subversion_WC_INFO)
  80. MACRO(Subversion_WC_LOG dir prefix)
  81. # This macro can block if the certificate is not signed:
  82. # svn ask you to accept the certificate and wait for your answer
  83. # This macro requires a svn server network access (Internet most of the time)
  84. # and can also be slow since it access the svn server
  85. EXECUTE_PROCESS(COMMAND
  86. ${Subversion_SVN_EXECUTABLE} log -r BASE ${dir}
  87. OUTPUT_VARIABLE ${prefix}_LAST_CHANGED_LOG
  88. ERROR_VARIABLE Subversion_svn_log_error
  89. RESULT_VARIABLE Subversion_svn_log_result
  90. OUTPUT_STRIP_TRAILING_WHITESPACE)
  91. IF(NOT ${Subversion_svn_log_result} EQUAL 0)
  92. MESSAGE(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} log -r BASE ${dir}\" failed with output:\n${Subversion_svn_log_error}")
  93. ENDIF(NOT ${Subversion_svn_log_result} EQUAL 0)
  94. ENDMACRO(Subversion_WC_LOG)
  95. ENDIF(Subversion_SVN_EXECUTABLE)
  96. IF(NOT Subversion_FOUND)
  97. IF(NOT Subversion_FIND_QUIETLY)
  98. MESSAGE(STATUS "Subversion was not found.")
  99. ELSE(NOT Subversion_FIND_QUIETLY)
  100. IF(Subversion_FIND_REQUIRED)
  101. MESSAGE(FATAL_ERROR "Subversion was not found.")
  102. ENDIF(Subversion_FIND_REQUIRED)
  103. ENDIF(NOT Subversion_FIND_QUIETLY)
  104. ENDIF(NOT Subversion_FOUND)
  105. # FindSubversion.cmake ends here.