FindSubversion.cmake 5.0 KB

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