Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / FindSubversion.cmake
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()
35
36 #=============================================================================
37 # Copyright 2006-2009 Kitware, Inc.
38 # Copyright 2006 Tristan Carel
39 #
40 # Distributed under the OSI-approved BSD License (the "License");
41 # see accompanying file Copyright.txt for details.
42 #
43 # This software is distributed WITHOUT ANY WARRANTY; without even the
44 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
45 # See the License for more information.
46 #=============================================================================
47 # (To distribute this file outside of CMake, substitute the full
48 #  License text for the above reference.)
49
50 find_program(Subversion_SVN_EXECUTABLE svn
51   DOC "subversion command line client")
52 mark_as_advanced(Subversion_SVN_EXECUTABLE)
53
54 if(Subversion_SVN_EXECUTABLE)
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}")
58   set(ENV{LC_ALL} C)
59
60   execute_process(COMMAND ${Subversion_SVN_EXECUTABLE} --version
61     OUTPUT_VARIABLE Subversion_VERSION_SVN
62     OUTPUT_STRIP_TRAILING_WHITESPACE)
63
64   # restore the previous LC_ALL
65   set(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
66
67   string(REGEX REPLACE "^(.*\n)?svn, version ([.0-9]+).*"
68     "\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}")
69
70   macro(Subversion_WC_INFO dir prefix)
71     # the subversion commands should be executed with the C locale, otherwise
72     # the message (which are parsed) may be translated, Alex
73     set(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
74     set(ENV{LC_ALL} C)
75
76     execute_process(COMMAND ${Subversion_SVN_EXECUTABLE} info ${dir}
77       OUTPUT_VARIABLE ${prefix}_WC_INFO
78       ERROR_VARIABLE Subversion_svn_info_error
79       RESULT_VARIABLE Subversion_svn_info_result
80       OUTPUT_STRIP_TRAILING_WHITESPACE)
81
82     if(NOT ${Subversion_svn_info_result} EQUAL 0)
83       message(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}")
84     else()
85
86       string(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
87         "\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}")
88       string(REGEX REPLACE "^(.*\n)?Repository Root: ([^\n]+).*"
89         "\\2" ${prefix}_WC_ROOT "${${prefix}_WC_INFO}")
90       string(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
91         "\\2" ${prefix}_WC_REVISION "${${prefix}_WC_INFO}")
92       string(REGEX REPLACE "^(.*\n)?Last Changed Author: ([^\n]+).*"
93         "\\2" ${prefix}_WC_LAST_CHANGED_AUTHOR "${${prefix}_WC_INFO}")
94       string(REGEX REPLACE "^(.*\n)?Last Changed Rev: ([^\n]+).*"
95         "\\2" ${prefix}_WC_LAST_CHANGED_REV "${${prefix}_WC_INFO}")
96       string(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*"
97         "\\2" ${prefix}_WC_LAST_CHANGED_DATE "${${prefix}_WC_INFO}")
98
99     endif()
100
101     # restore the previous LC_ALL
102     set(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
103
104   endmacro()
105
106   macro(Subversion_WC_LOG dir prefix)
107     # This macro can block if the certificate is not signed:
108     # svn ask you to accept the certificate and wait for your answer
109     # This macro requires a svn server network access (Internet most of the time)
110     # and can also be slow since it access the svn server
111     execute_process(COMMAND
112       ${Subversion_SVN_EXECUTABLE} --non-interactive log -r BASE ${dir}
113       OUTPUT_VARIABLE ${prefix}_LAST_CHANGED_LOG
114       ERROR_VARIABLE Subversion_svn_log_error
115       RESULT_VARIABLE Subversion_svn_log_result
116       OUTPUT_STRIP_TRAILING_WHITESPACE)
117
118     if(NOT ${Subversion_svn_log_result} EQUAL 0)
119       message(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} log -r BASE ${dir}\" failed with output:\n${Subversion_svn_log_error}")
120     endif()
121   endmacro()
122
123 endif()
124
125 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
126 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Subversion REQUIRED_VARS Subversion_SVN_EXECUTABLE
127                                              VERSION_VAR Subversion_VERSION_SVN )
128
129 # for compatibility
130 set(Subversion_FOUND ${SUBVERSION_FOUND})
131 set(Subversion_SVN_FOUND ${SUBVERSION_FOUND})