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 # ENDIF(Subversion_FOUND)
25 # Copyright (c) 2006, Tristan Carel
26 # All rights reserved.
27 # Redistribution and use in source and binary forms, with or without
28 # modification, are permitted provided that the following conditions are met:
30 # * Redistributions of source code must retain the above copyright
31 # notice, this list of conditions and the following disclaimer.
32 # * Redistributions in binary form must reproduce the above copyright
33 # notice, this list of conditions and the following disclaimer in the
34 # documentation and/or other materials provided with the distribution.
35 # * Neither the name of the University of California, Berkeley nor the
36 # names of its contributors may be used to endorse or promote products
37 # derived from this software without specific prior written permission.
39 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
40 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
41 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42 # DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
43 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
44 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
46 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
48 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 # $Id: FindSubversion.cmake,v 1.2 2008-01-14 22:19:20 alex Exp $
52 SET(Subversion_FOUND FALSE)
53 SET(Subversion_SVN_FOUND FALSE)
55 # the subversion commands should be executed with the C locale, otherwise
56 # the message (which are parsed) may be translated, Alex
57 SET(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}" )
60 FIND_PROGRAM(Subversion_SVN_EXECUTABLE svn
61 DOC "subversion command line client")
62 MARK_AS_ADVANCED(Subversion_SVN_EXECUTABLE)
64 IF(Subversion_SVN_EXECUTABLE)
65 SET(Subversion_SVN_FOUND TRUE)
66 SET(Subversion_FOUND TRUE)
68 MACRO(Subversion_WC_INFO dir prefix)
69 EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} --version
70 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
71 OUTPUT_VARIABLE Subversion_VERSION_SVN
72 OUTPUT_STRIP_TRAILING_WHITESPACE)
74 EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} info ${dir}
75 OUTPUT_VARIABLE ${prefix}_WC_INFO
76 ERROR_VARIABLE Subversion_svn_info_error
77 RESULT_VARIABLE Subversion_svn_info_result
78 OUTPUT_STRIP_TRAILING_WHITESPACE)
80 IF(NOT ${Subversion_svn_info_result} EQUAL 0)
81 MESSAGE(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}")
82 ELSE(NOT ${Subversion_svn_info_result} EQUAL 0)
84 STRING(REGEX REPLACE "^(.*\n)?svn, version ([.0-9]+).*"
85 "\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}")
86 STRING(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
87 "\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}")
88 STRING(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
89 "\\2" ${prefix}_WC_REVISION "${${prefix}_WC_INFO}")
90 STRING(REGEX REPLACE "^(.*\n)?Last Changed Author: ([^\n]+).*"
91 "\\2" ${prefix}_WC_LAST_CHANGED_AUTHOR "${${prefix}_WC_INFO}")
92 STRING(REGEX REPLACE "^(.*\n)?Last Changed Rev: ([^\n]+).*"
93 "\\2" ${prefix}_WC_LAST_CHANGED_REV "${${prefix}_WC_INFO}")
94 STRING(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*"
95 "\\2" ${prefix}_WC_LAST_CHANGED_DATE "${${prefix}_WC_INFO}")
97 ENDIF(NOT ${Subversion_svn_info_result} EQUAL 0)
99 EXECUTE_PROCESS(COMMAND
100 ${Subversion_SVN_EXECUTABLE} log -r BASE ${dir}
101 OUTPUT_VARIABLE Subversion_LAST_CHANGED_LOG
102 ERROR_VARIABLE Subversion_svn_log_error
103 RESULT_VARIABLE Subversion_svn_log_result
104 OUTPUT_STRIP_TRAILING_WHITESPACE)
106 IF(NOT ${Subversion_svn_log_result} EQUAL 0)
107 MESSAGE(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} log -r BASE ${dir}\" failed with output:\n${Subversion_svn_log_error}")
108 ENDIF(NOT ${Subversion_svn_log_result} EQUAL 0)
109 ENDMACRO(Subversion_WC_INFO)
111 ENDIF(Subversion_SVN_EXECUTABLE)
113 # restore the previous LC_ALL
114 SET(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
116 IF(NOT Subversion_FOUND)
117 IF(NOT Subversion_FIND_QUIETLY)
118 MESSAGE(STATUS "Subversion was not found.")
119 ELSE(NOT Subversion_FIND_QUIETLY)
120 IF(Subversion_FIND_REQUIRED)
121 MESSAGE(FATAL_ERROR "Subversion was not found.")
122 ENDIF(Subversion_FIND_REQUIRED)
123 ENDIF(NOT Subversion_FIND_QUIETLY)
124 ENDIF(NOT Subversion_FOUND)
126 # FindSubversion.cmake ends here.