FindSubversion.cmake 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. # the subversion commands should be executed with the C locale, otherwise
  53. # the message (which are parsed) may be translated, Alex
  54. SET(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
  55. SET(ENV{LC_ALL} C)
  56. EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} --version
  57. OUTPUT_VARIABLE Subversion_VERSION_SVN
  58. OUTPUT_STRIP_TRAILING_WHITESPACE)
  59. # restore the previous LC_ALL
  60. SET(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
  61. STRING(REGEX REPLACE "^(.*\n)?svn, version ([.0-9]+).*"
  62. "\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}")
  63. MACRO(Subversion_WC_INFO dir prefix)
  64. # the subversion commands should be executed with the C locale, otherwise
  65. # the message (which are parsed) may be translated, Alex
  66. SET(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
  67. SET(ENV{LC_ALL} C)
  68. EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} info ${dir}
  69. OUTPUT_VARIABLE ${prefix}_WC_INFO
  70. ERROR_VARIABLE Subversion_svn_info_error
  71. RESULT_VARIABLE Subversion_svn_info_result
  72. OUTPUT_STRIP_TRAILING_WHITESPACE)
  73. IF(NOT ${Subversion_svn_info_result} EQUAL 0)
  74. MESSAGE(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}")
  75. ELSE(NOT ${Subversion_svn_info_result} EQUAL 0)
  76. STRING(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
  77. "\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}")
  78. STRING(REGEX REPLACE "^(.*\n)?Repository Root: ([^\n]+).*"
  79. "\\2" ${prefix}_WC_ROOT "${${prefix}_WC_INFO}")
  80. STRING(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
  81. "\\2" ${prefix}_WC_REVISION "${${prefix}_WC_INFO}")
  82. STRING(REGEX REPLACE "^(.*\n)?Last Changed Author: ([^\n]+).*"
  83. "\\2" ${prefix}_WC_LAST_CHANGED_AUTHOR "${${prefix}_WC_INFO}")
  84. STRING(REGEX REPLACE "^(.*\n)?Last Changed Rev: ([^\n]+).*"
  85. "\\2" ${prefix}_WC_LAST_CHANGED_REV "${${prefix}_WC_INFO}")
  86. STRING(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*"
  87. "\\2" ${prefix}_WC_LAST_CHANGED_DATE "${${prefix}_WC_INFO}")
  88. ENDIF(NOT ${Subversion_svn_info_result} EQUAL 0)
  89. # restore the previous LC_ALL
  90. SET(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
  91. ENDMACRO(Subversion_WC_INFO)
  92. MACRO(Subversion_WC_LOG dir prefix)
  93. # This macro can block if the certificate is not signed:
  94. # svn ask you to accept the certificate and wait for your answer
  95. # This macro requires a svn server network access (Internet most of the time)
  96. # and can also be slow since it access the svn server
  97. EXECUTE_PROCESS(COMMAND
  98. ${Subversion_SVN_EXECUTABLE} --non-interactive log -r BASE ${dir}
  99. OUTPUT_VARIABLE ${prefix}_LAST_CHANGED_LOG
  100. ERROR_VARIABLE Subversion_svn_log_error
  101. RESULT_VARIABLE Subversion_svn_log_result
  102. OUTPUT_STRIP_TRAILING_WHITESPACE)
  103. IF(NOT ${Subversion_svn_log_result} EQUAL 0)
  104. MESSAGE(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} log -r BASE ${dir}\" failed with output:\n${Subversion_svn_log_error}")
  105. ENDIF(NOT ${Subversion_svn_log_result} EQUAL 0)
  106. ENDMACRO(Subversion_WC_LOG)
  107. ENDIF(Subversion_SVN_EXECUTABLE)
  108. INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  109. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Subversion REQUIRED_VARS Subversion_SVN_EXECUTABLE
  110. VERSION_VAR Subversion_VERSION_SVN )
  111. # for compatibility
  112. SET(Subversion_FOUND ${SUBVERSION_FOUND})
  113. SET(Subversion_SVN_FOUND ${SUBVERSION_FOUND})