FindSubversion.cmake 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 the macro
  12. # Subversion_WC_INFO(<dir> <var-prefix>)
  13. # is defined to extract information of a subversion working copy at
  14. # a given location. The macro defines the following variables:
  15. # <var-prefix>_WC_URL - url of the repository (at <dir>)
  16. # <var-prefix>_WC_ROOT - root url of the repository
  17. # <var-prefix>_WC_REVISION - current revision
  18. # <var-prefix>_WC_LAST_CHANGED_AUTHOR - author of last commit
  19. # <var-prefix>_WC_LAST_CHANGED_DATE - date of last commit
  20. # <var-prefix>_WC_LAST_CHANGED_REV - revision of last commit
  21. # <var-prefix>_WC_LAST_CHANGED_LOG - last log of base revision
  22. # <var-prefix>_WC_INFO - output of command `svn info <dir>'
  23. # Example usage:
  24. # FIND_PACKAGE(Subversion)
  25. # IF(SUBVERSION_FOUND)
  26. # Subversion_WC_INFO(${PROJECT_SOURCE_DIR} Project)
  27. # MESSAGE("Current revision is ${Project_WC_REVISION}")
  28. # Subversion_WC_LOG(${PROJECT_SOURCE_DIR} Project)
  29. # MESSAGE("Last changed log is ${Project_LAST_CHANGED_LOG}")
  30. # ENDIF(SUBVERSION_FOUND)
  31. #=============================================================================
  32. # Copyright 2006-2009 Kitware, Inc.
  33. # Copyright 2006 Tristan Carel
  34. #
  35. # Distributed under the OSI-approved BSD License (the "License");
  36. # see accompanying file Copyright.txt for details.
  37. #
  38. # This software is distributed WITHOUT ANY WARRANTY; without even the
  39. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  40. # See the License for more information.
  41. #=============================================================================
  42. # (To distribute this file outside of CMake, substitute the full
  43. # License text for the above reference.)
  44. FIND_PROGRAM(Subversion_SVN_EXECUTABLE svn
  45. DOC "subversion command line client")
  46. MARK_AS_ADVANCED(Subversion_SVN_EXECUTABLE)
  47. IF(Subversion_SVN_EXECUTABLE)
  48. EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} --version
  49. OUTPUT_VARIABLE Subversion_VERSION_SVN
  50. OUTPUT_STRIP_TRAILING_WHITESPACE)
  51. STRING(REGEX REPLACE "^(.*\n)?svn, version ([.0-9]+).*"
  52. "\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}")
  53. MACRO(Subversion_WC_INFO dir prefix)
  54. # the subversion commands should be executed with the C locale, otherwise
  55. # the message (which are parsed) may be translated, Alex
  56. SET(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
  57. SET(ENV{LC_ALL} C)
  58. EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} info ${dir}
  59. OUTPUT_VARIABLE ${prefix}_WC_INFO
  60. ERROR_VARIABLE Subversion_svn_info_error
  61. RESULT_VARIABLE Subversion_svn_info_result
  62. OUTPUT_STRIP_TRAILING_WHITESPACE)
  63. IF(NOT ${Subversion_svn_info_result} EQUAL 0)
  64. MESSAGE(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}")
  65. ELSE(NOT ${Subversion_svn_info_result} EQUAL 0)
  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. INCLUDE(FindPackageHandleStandardArgs)
  97. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Subversion REQUIRED_VARS Subversion_SVN_EXECUTABLE
  98. VERSION_VAR Subversion_VERSION_SVN )
  99. # for compatibility
  100. SET(Subversion_FOUND ${SUBVERSION_FOUND})
  101. SET(Subversion_SVN_FOUND ${SUBVERSION_FOUND})