FindSubversion.cmake 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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, kept around for compatibility
  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 distributed this file outside of CMake, substitute the full
  43. # License text for the above reference.)
  44. SET(Subversion_SVN_FOUND FALSE)
  45. FIND_PROGRAM(Subversion_SVN_EXECUTABLE svn
  46. DOC "subversion command line client")
  47. MARK_AS_ADVANCED(Subversion_SVN_EXECUTABLE)
  48. IF(Subversion_SVN_EXECUTABLE)
  49. SET(Subversion_SVN_FOUND TRUE)
  50. EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} --version
  51. OUTPUT_VARIABLE Subversion_VERSION_SVN
  52. OUTPUT_STRIP_TRAILING_WHITESPACE)
  53. STRING(REGEX REPLACE "^(.*\n)?svn, version ([.0-9]+).*"
  54. "\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}")
  55. MACRO(Subversion_WC_INFO dir prefix)
  56. # the subversion commands should be executed with the C locale, otherwise
  57. # the message (which are parsed) may be translated, Alex
  58. SET(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
  59. SET(ENV{LC_ALL} C)
  60. EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} info ${dir}
  61. OUTPUT_VARIABLE ${prefix}_WC_INFO
  62. ERROR_VARIABLE Subversion_svn_info_error
  63. RESULT_VARIABLE Subversion_svn_info_result
  64. OUTPUT_STRIP_TRAILING_WHITESPACE)
  65. IF(NOT ${Subversion_svn_info_result} EQUAL 0)
  66. MESSAGE(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}")
  67. ELSE(NOT ${Subversion_svn_info_result} EQUAL 0)
  68. STRING(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
  69. "\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}")
  70. STRING(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
  71. "\\2" ${prefix}_WC_REVISION "${${prefix}_WC_INFO}")
  72. STRING(REGEX REPLACE "^(.*\n)?Last Changed Author: ([^\n]+).*"
  73. "\\2" ${prefix}_WC_LAST_CHANGED_AUTHOR "${${prefix}_WC_INFO}")
  74. STRING(REGEX REPLACE "^(.*\n)?Last Changed Rev: ([^\n]+).*"
  75. "\\2" ${prefix}_WC_LAST_CHANGED_REV "${${prefix}_WC_INFO}")
  76. STRING(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*"
  77. "\\2" ${prefix}_WC_LAST_CHANGED_DATE "${${prefix}_WC_INFO}")
  78. ENDIF(NOT ${Subversion_svn_info_result} EQUAL 0)
  79. # restore the previous LC_ALL
  80. SET(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
  81. ENDMACRO(Subversion_WC_INFO)
  82. MACRO(Subversion_WC_LOG dir prefix)
  83. # This macro can block if the certificate is not signed:
  84. # svn ask you to accept the certificate and wait for your answer
  85. # This macro requires a svn server network access (Internet most of the time)
  86. # and can also be slow since it access the svn server
  87. EXECUTE_PROCESS(COMMAND
  88. ${Subversion_SVN_EXECUTABLE} log -r BASE ${dir}
  89. OUTPUT_VARIABLE ${prefix}_LAST_CHANGED_LOG
  90. ERROR_VARIABLE Subversion_svn_log_error
  91. RESULT_VARIABLE Subversion_svn_log_result
  92. OUTPUT_STRIP_TRAILING_WHITESPACE)
  93. IF(NOT ${Subversion_svn_log_result} EQUAL 0)
  94. MESSAGE(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} log -r BASE ${dir}\" failed with output:\n${Subversion_svn_log_error}")
  95. ENDIF(NOT ${Subversion_svn_log_result} EQUAL 0)
  96. ENDMACRO(Subversion_WC_LOG)
  97. ENDIF(Subversion_SVN_EXECUTABLE)
  98. INCLUDE(FindPackageHandleStandardArgs)
  99. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Subversion REQUIRED_VARS Subversion_SVN_EXECUTABLE
  100. VERSION_VAR Subversion_VERSION_SVN )
  101. SET(Subversion_FOUND ${SUBVERSION_FOUND})