FindSubversion.cmake 5.5 KB

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