FindSubversion.cmake 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #.rst:
  2. # FindSubversion
  3. # --------------
  4. #
  5. # Extract information from a subversion working copy
  6. #
  7. # The module defines the following variables:
  8. #
  9. # ::
  10. #
  11. # Subversion_SVN_EXECUTABLE - path to svn command line client
  12. # Subversion_VERSION_SVN - version of svn command line client
  13. # Subversion_FOUND - true if the command line client was found
  14. # SUBVERSION_FOUND - same as Subversion_FOUND, set for compatibility reasons
  15. #
  16. #
  17. #
  18. # The minimum required version of Subversion can be specified using the
  19. # standard syntax, e.g. find_package(Subversion 1.4)
  20. #
  21. # If the command line client executable is found two macros are defined:
  22. #
  23. # ::
  24. #
  25. # Subversion_WC_INFO(<dir> <var-prefix>)
  26. # Subversion_WC_LOG(<dir> <var-prefix>)
  27. #
  28. # Subversion_WC_INFO extracts information of a subversion working copy
  29. # at a given location. This macro defines the following variables:
  30. #
  31. # ::
  32. #
  33. # <var-prefix>_WC_URL - url of the repository (at <dir>)
  34. # <var-prefix>_WC_ROOT - root url of the repository
  35. # <var-prefix>_WC_REVISION - current revision
  36. # <var-prefix>_WC_LAST_CHANGED_AUTHOR - author of last commit
  37. # <var-prefix>_WC_LAST_CHANGED_DATE - date of last commit
  38. # <var-prefix>_WC_LAST_CHANGED_REV - revision of last commit
  39. # <var-prefix>_WC_INFO - output of command `svn info <dir>'
  40. #
  41. # Subversion_WC_LOG retrieves the log message of the base revision of a
  42. # subversion working copy at a given location. This macro defines the
  43. # variable:
  44. #
  45. # ::
  46. #
  47. # <var-prefix>_LAST_CHANGED_LOG - last log of base revision
  48. #
  49. # Example usage:
  50. #
  51. # ::
  52. #
  53. # find_package(Subversion)
  54. # if(SUBVERSION_FOUND)
  55. # Subversion_WC_INFO(${PROJECT_SOURCE_DIR} Project)
  56. # message("Current revision is ${Project_WC_REVISION}")
  57. # Subversion_WC_LOG(${PROJECT_SOURCE_DIR} Project)
  58. # message("Last changed log is ${Project_LAST_CHANGED_LOG}")
  59. # endif()
  60. #=============================================================================
  61. # Copyright 2006-2009 Kitware, Inc.
  62. # Copyright 2006 Tristan Carel
  63. #
  64. # Distributed under the OSI-approved BSD License (the "License");
  65. # see accompanying file Copyright.txt for details.
  66. #
  67. # This software is distributed WITHOUT ANY WARRANTY; without even the
  68. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  69. # See the License for more information.
  70. #=============================================================================
  71. # (To distribute this file outside of CMake, substitute the full
  72. # License text for the above reference.)
  73. find_program(Subversion_SVN_EXECUTABLE svn
  74. PATHS
  75. [HKEY_LOCAL_MACHINE\\Software\\TortoiseSVN;Directory]/bin
  76. DOC "subversion command line client")
  77. mark_as_advanced(Subversion_SVN_EXECUTABLE)
  78. if(Subversion_SVN_EXECUTABLE)
  79. # the subversion commands should be executed with the C locale, otherwise
  80. # the message (which are parsed) may be translated, Alex
  81. set(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
  82. set(ENV{LC_ALL} C)
  83. execute_process(COMMAND ${Subversion_SVN_EXECUTABLE} --version
  84. OUTPUT_VARIABLE Subversion_VERSION_SVN
  85. OUTPUT_STRIP_TRAILING_WHITESPACE)
  86. # restore the previous LC_ALL
  87. set(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
  88. string(REGEX REPLACE "^(.*\n)?svn, version ([.0-9]+).*"
  89. "\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}")
  90. macro(Subversion_WC_INFO dir prefix)
  91. # the subversion commands should be executed with the C locale, otherwise
  92. # the message (which are parsed) may be translated, Alex
  93. set(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
  94. set(ENV{LC_ALL} C)
  95. execute_process(COMMAND ${Subversion_SVN_EXECUTABLE} info ${dir}
  96. OUTPUT_VARIABLE ${prefix}_WC_INFO
  97. ERROR_VARIABLE Subversion_svn_info_error
  98. RESULT_VARIABLE Subversion_svn_info_result
  99. OUTPUT_STRIP_TRAILING_WHITESPACE)
  100. if(NOT ${Subversion_svn_info_result} EQUAL 0)
  101. message(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}")
  102. else()
  103. string(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
  104. "\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}")
  105. string(REGEX REPLACE "^(.*\n)?Repository Root: ([^\n]+).*"
  106. "\\2" ${prefix}_WC_ROOT "${${prefix}_WC_INFO}")
  107. string(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
  108. "\\2" ${prefix}_WC_REVISION "${${prefix}_WC_INFO}")
  109. string(REGEX REPLACE "^(.*\n)?Last Changed Author: ([^\n]+).*"
  110. "\\2" ${prefix}_WC_LAST_CHANGED_AUTHOR "${${prefix}_WC_INFO}")
  111. string(REGEX REPLACE "^(.*\n)?Last Changed Rev: ([^\n]+).*"
  112. "\\2" ${prefix}_WC_LAST_CHANGED_REV "${${prefix}_WC_INFO}")
  113. string(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*"
  114. "\\2" ${prefix}_WC_LAST_CHANGED_DATE "${${prefix}_WC_INFO}")
  115. endif()
  116. # restore the previous LC_ALL
  117. set(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
  118. endmacro()
  119. macro(Subversion_WC_LOG dir prefix)
  120. # This macro can block if the certificate is not signed:
  121. # svn ask you to accept the certificate and wait for your answer
  122. # This macro requires a svn server network access (Internet most of the time)
  123. # and can also be slow since it access the svn server
  124. execute_process(COMMAND
  125. ${Subversion_SVN_EXECUTABLE} --non-interactive log -r BASE ${dir}
  126. OUTPUT_VARIABLE ${prefix}_LAST_CHANGED_LOG
  127. ERROR_VARIABLE Subversion_svn_log_error
  128. RESULT_VARIABLE Subversion_svn_log_result
  129. OUTPUT_STRIP_TRAILING_WHITESPACE)
  130. if(NOT ${Subversion_svn_log_result} EQUAL 0)
  131. message(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} log -r BASE ${dir}\" failed with output:\n${Subversion_svn_log_error}")
  132. endif()
  133. endmacro()
  134. endif()
  135. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  136. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Subversion REQUIRED_VARS Subversion_SVN_EXECUTABLE
  137. VERSION_VAR Subversion_VERSION_SVN )
  138. # for compatibility
  139. set(Subversion_FOUND ${SUBVERSION_FOUND})
  140. set(Subversion_SVN_FOUND ${SUBVERSION_FOUND})