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>'
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)
27 # Copyright (c) 2006, Tristan Carel
28 # All rights reserved.
29 # Redistribution and use in source and binary forms, with or without
30 # modification, are permitted provided that the following conditions are met:
32 # * Redistributions of source code must retain the above copyright
33 # notice, this list of conditions and the following disclaimer.
34 # * Redistributions in binary form must reproduce the above copyright
35 # notice, this list of conditions and the following disclaimer in the
36 # documentation and/or other materials provided with the distribution.
37 # * Neither the name of the University of California, Berkeley nor the
38 # names of its contributors may be used to endorse or promote products
39 # derived from this software without specific prior written permission.
41 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
42 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
43 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44 # DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
45 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
46 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
50 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 <<<<<<< FindSubversion.cmake
53 <<<<<<< FindSubversion.cmake
54 # $Id: FindSubversion.cmake,v 1.2 2008/01/14 22:19:20 alex Exp $
56 # $Id: FindSubversion.cmake,v 1.3 2008-03-20 15:44:25 david.cole Exp $
59 # $Id: FindSubversion.cmake,v 1.4 2008-05-19 14:03:59 king Exp $
62 SET(Subversion_FOUND FALSE)
63 SET(Subversion_SVN_FOUND FALSE)
65 FIND_PROGRAM(Subversion_SVN_EXECUTABLE svn
66 DOC "subversion command line client")
67 MARK_AS_ADVANCED(Subversion_SVN_EXECUTABLE)
69 IF(Subversion_SVN_EXECUTABLE)
70 SET(Subversion_SVN_FOUND TRUE)
71 SET(Subversion_FOUND TRUE)
73 MACRO(Subversion_WC_INFO dir prefix)
74 # the subversion commands should be executed with the C locale, otherwise
75 # the message (which are parsed) may be translated, Alex
76 SET(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
79 EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} --version
80 WORKING_DIRECTORY ${dir}
81 OUTPUT_VARIABLE Subversion_VERSION_SVN
82 OUTPUT_STRIP_TRAILING_WHITESPACE)
84 EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} info ${dir}
85 OUTPUT_VARIABLE ${prefix}_WC_INFO
86 ERROR_VARIABLE Subversion_svn_info_error
87 RESULT_VARIABLE Subversion_svn_info_result
88 OUTPUT_STRIP_TRAILING_WHITESPACE)
90 IF(NOT ${Subversion_svn_info_result} EQUAL 0)
91 MESSAGE(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}")
92 ELSE(NOT ${Subversion_svn_info_result} EQUAL 0)
94 STRING(REGEX REPLACE "^(.*\n)?svn, version ([.0-9]+).*"
95 "\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}")
96 STRING(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
97 "\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}")
98 STRING(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
99 "\\2" ${prefix}_WC_REVISION "${${prefix}_WC_INFO}")
100 STRING(REGEX REPLACE "^(.*\n)?Last Changed Author: ([^\n]+).*"
101 "\\2" ${prefix}_WC_LAST_CHANGED_AUTHOR "${${prefix}_WC_INFO}")
102 STRING(REGEX REPLACE "^(.*\n)?Last Changed Rev: ([^\n]+).*"
103 "\\2" ${prefix}_WC_LAST_CHANGED_REV "${${prefix}_WC_INFO}")
104 STRING(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*"
105 "\\2" ${prefix}_WC_LAST_CHANGED_DATE "${${prefix}_WC_INFO}")
107 ENDIF(NOT ${Subversion_svn_info_result} EQUAL 0)
109 # restore the previous LC_ALL
110 SET(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
112 ENDMACRO(Subversion_WC_INFO)
114 MACRO(Subversion_WC_LOG dir prefix)
115 # This macro can block if the certificate is not signed:
116 # svn ask you to accept the certificate and wait for your answer
117 # This macro requires a svn server network access (Internet most of the time)
118 # and can also be slow since it access the svn server
119 EXECUTE_PROCESS(COMMAND
120 ${Subversion_SVN_EXECUTABLE} log -r BASE ${dir}
121 OUTPUT_VARIABLE ${prefix}_LAST_CHANGED_LOG
122 ERROR_VARIABLE Subversion_svn_log_error
123 RESULT_VARIABLE Subversion_svn_log_result
124 OUTPUT_STRIP_TRAILING_WHITESPACE)
126 IF(NOT ${Subversion_svn_log_result} EQUAL 0)
127 MESSAGE(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} log -r BASE ${dir}\" failed with output:\n${Subversion_svn_log_error}")
128 ENDIF(NOT ${Subversion_svn_log_result} EQUAL 0)
129 ENDMACRO(Subversion_WC_LOG)
131 ENDIF(Subversion_SVN_EXECUTABLE)
133 IF(NOT Subversion_FOUND)
134 IF(NOT Subversion_FIND_QUIETLY)
135 MESSAGE(STATUS "Subversion was not found.")
136 ELSE(NOT Subversion_FIND_QUIETLY)
137 IF(Subversion_FIND_REQUIRED)
138 MESSAGE(FATAL_ERROR "Subversion was not found.")
139 ENDIF(Subversion_FIND_REQUIRED)
140 ENDIF(NOT Subversion_FIND_QUIETLY)
141 ENDIF(NOT Subversion_FOUND)
143 # FindSubversion.cmake ends here.