2016-09-27 22:01:08 +03:00
|
|
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
# file Copyright.txt or https://cmake.org/licensing for details.
|
|
|
|
|
2013-10-15 19:17:36 +04:00
|
|
|
#.rst:
|
|
|
|
# FindSubversion
|
|
|
|
# --------------
|
|
|
|
#
|
|
|
|
# Extract information from a subversion working copy
|
|
|
|
#
|
2006-10-30 23:30:59 +03:00
|
|
|
# The module defines the following variables:
|
2013-10-15 19:17:36 +04:00
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# Subversion_SVN_EXECUTABLE - path to svn command line client
|
|
|
|
# Subversion_VERSION_SVN - version of svn command line client
|
|
|
|
# Subversion_FOUND - true if the command line client was found
|
2016-03-29 21:24:20 +03:00
|
|
|
# SUBVERSION_FOUND - same as Subversion_FOUND, set for compatibility reasons
|
2013-10-15 19:17:36 +04:00
|
|
|
#
|
|
|
|
#
|
2010-08-08 01:00:31 +04:00
|
|
|
#
|
|
|
|
# The minimum required version of Subversion can be specified using the
|
2013-10-15 19:17:36 +04:00
|
|
|
# standard syntax, e.g. find_package(Subversion 1.4)
|
2010-08-08 01:00:31 +04:00
|
|
|
#
|
2010-09-13 15:13:12 +04:00
|
|
|
# If the command line client executable is found two macros are defined:
|
2013-10-15 19:17:36 +04:00
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# Subversion_WC_INFO(<dir> <var-prefix>)
|
|
|
|
# Subversion_WC_LOG(<dir> <var-prefix>)
|
|
|
|
#
|
|
|
|
# Subversion_WC_INFO extracts information of a subversion working copy
|
|
|
|
# at a given location. This macro defines the following variables:
|
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# <var-prefix>_WC_URL - url of the repository (at <dir>)
|
|
|
|
# <var-prefix>_WC_ROOT - root url of the repository
|
|
|
|
# <var-prefix>_WC_REVISION - current revision
|
|
|
|
# <var-prefix>_WC_LAST_CHANGED_AUTHOR - author of last commit
|
|
|
|
# <var-prefix>_WC_LAST_CHANGED_DATE - date of last commit
|
|
|
|
# <var-prefix>_WC_LAST_CHANGED_REV - revision of last commit
|
|
|
|
# <var-prefix>_WC_INFO - output of command `svn info <dir>'
|
|
|
|
#
|
2010-09-13 15:13:12 +04:00
|
|
|
# Subversion_WC_LOG retrieves the log message of the base revision of a
|
2013-10-15 19:17:36 +04:00
|
|
|
# subversion working copy at a given location. This macro defines the
|
2010-09-13 15:13:12 +04:00
|
|
|
# variable:
|
2013-10-15 19:17:36 +04:00
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# <var-prefix>_LAST_CHANGED_LOG - last log of base revision
|
|
|
|
#
|
2006-10-30 23:30:59 +03:00
|
|
|
# Example usage:
|
2013-10-15 19:17:36 +04:00
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# find_package(Subversion)
|
|
|
|
# if(SUBVERSION_FOUND)
|
|
|
|
# Subversion_WC_INFO(${PROJECT_SOURCE_DIR} Project)
|
|
|
|
# message("Current revision is ${Project_WC_REVISION}")
|
|
|
|
# Subversion_WC_LOG(${PROJECT_SOURCE_DIR} Project)
|
|
|
|
# message("Last changed log is ${Project_LAST_CHANGED_LOG}")
|
|
|
|
# endif()
|
2006-10-30 23:30:59 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
find_program(Subversion_SVN_EXECUTABLE svn
|
2013-12-11 16:59:44 +04:00
|
|
|
PATHS
|
|
|
|
[HKEY_LOCAL_MACHINE\\Software\\TortoiseSVN;Directory]/bin
|
2006-10-30 23:30:59 +03:00
|
|
|
DOC "subversion command line client")
|
2012-08-13 21:47:32 +04:00
|
|
|
mark_as_advanced(Subversion_SVN_EXECUTABLE)
|
2006-10-30 23:30:59 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(Subversion_SVN_EXECUTABLE)
|
2010-10-07 18:30:01 +04:00
|
|
|
# the subversion commands should be executed with the C locale, otherwise
|
|
|
|
# the message (which are parsed) may be translated, Alex
|
2012-08-13 21:47:32 +04:00
|
|
|
set(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
|
|
|
|
set(ENV{LC_ALL} C)
|
2006-10-30 23:30:59 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
execute_process(COMMAND ${Subversion_SVN_EXECUTABLE} --version
|
2010-08-08 01:00:31 +04:00
|
|
|
OUTPUT_VARIABLE Subversion_VERSION_SVN
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
2010-10-07 18:30:01 +04:00
|
|
|
# restore the previous LC_ALL
|
2012-08-13 21:47:32 +04:00
|
|
|
set(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
|
2010-10-07 18:30:01 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
string(REGEX REPLACE "^(.*\n)?svn, version ([.0-9]+).*"
|
2010-08-08 01:00:31 +04:00
|
|
|
"\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}")
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
macro(Subversion_WC_INFO dir prefix)
|
2008-05-19 18:03:59 +04:00
|
|
|
# the subversion commands should be executed with the C locale, otherwise
|
|
|
|
# the message (which are parsed) may be translated, Alex
|
2012-08-13 21:47:32 +04:00
|
|
|
set(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
|
|
|
|
set(ENV{LC_ALL} C)
|
2008-05-19 18:03:59 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
execute_process(COMMAND ${Subversion_SVN_EXECUTABLE} info ${dir}
|
2006-10-30 23:30:59 +03:00
|
|
|
OUTPUT_VARIABLE ${prefix}_WC_INFO
|
|
|
|
ERROR_VARIABLE Subversion_svn_info_error
|
|
|
|
RESULT_VARIABLE Subversion_svn_info_result
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(NOT ${Subversion_svn_info_result} EQUAL 0)
|
|
|
|
message(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2006-10-30 23:30:59 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
string(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
|
2006-10-30 23:30:59 +03:00
|
|
|
"\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}")
|
2012-08-13 21:47:32 +04:00
|
|
|
string(REGEX REPLACE "^(.*\n)?Repository Root: ([^\n]+).*"
|
2010-09-13 15:13:12 +04:00
|
|
|
"\\2" ${prefix}_WC_ROOT "${${prefix}_WC_INFO}")
|
2012-08-13 21:47:32 +04:00
|
|
|
string(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
|
2006-10-30 23:30:59 +03:00
|
|
|
"\\2" ${prefix}_WC_REVISION "${${prefix}_WC_INFO}")
|
2012-08-13 21:47:32 +04:00
|
|
|
string(REGEX REPLACE "^(.*\n)?Last Changed Author: ([^\n]+).*"
|
2006-10-30 23:30:59 +03:00
|
|
|
"\\2" ${prefix}_WC_LAST_CHANGED_AUTHOR "${${prefix}_WC_INFO}")
|
2012-08-13 21:47:32 +04:00
|
|
|
string(REGEX REPLACE "^(.*\n)?Last Changed Rev: ([^\n]+).*"
|
2006-10-30 23:30:59 +03:00
|
|
|
"\\2" ${prefix}_WC_LAST_CHANGED_REV "${${prefix}_WC_INFO}")
|
2012-08-13 21:47:32 +04:00
|
|
|
string(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*"
|
2006-10-30 23:30:59 +03:00
|
|
|
"\\2" ${prefix}_WC_LAST_CHANGED_DATE "${${prefix}_WC_INFO}")
|
|
|
|
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2006-10-30 23:30:59 +03:00
|
|
|
|
2008-05-19 18:03:59 +04:00
|
|
|
# restore the previous LC_ALL
|
2012-08-13 21:47:32 +04:00
|
|
|
set(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
|
2008-05-19 18:03:59 +04:00
|
|
|
|
2012-08-13 21:50:14 +04:00
|
|
|
endmacro()
|
2008-05-19 18:03:59 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
macro(Subversion_WC_LOG dir prefix)
|
2008-05-19 18:03:59 +04:00
|
|
|
# This macro can block if the certificate is not signed:
|
|
|
|
# svn ask you to accept the certificate and wait for your answer
|
|
|
|
# This macro requires a svn server network access (Internet most of the time)
|
|
|
|
# and can also be slow since it access the svn server
|
2012-08-13 21:47:32 +04:00
|
|
|
execute_process(COMMAND
|
2011-06-24 23:39:40 +04:00
|
|
|
${Subversion_SVN_EXECUTABLE} --non-interactive log -r BASE ${dir}
|
2008-05-19 18:03:59 +04:00
|
|
|
OUTPUT_VARIABLE ${prefix}_LAST_CHANGED_LOG
|
2006-10-30 23:30:59 +03:00
|
|
|
ERROR_VARIABLE Subversion_svn_log_error
|
|
|
|
RESULT_VARIABLE Subversion_svn_log_result
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(NOT ${Subversion_svn_log_result} EQUAL 0)
|
|
|
|
message(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} log -r BASE ${dir}\" failed with output:\n${Subversion_svn_log_error}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
|
|
|
endmacro()
|
2006-10-30 23:30:59 +03:00
|
|
|
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2006-10-30 23:30:59 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
|
2010-08-08 01:00:31 +04:00
|
|
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Subversion REQUIRED_VARS Subversion_SVN_EXECUTABLE
|
|
|
|
VERSION_VAR Subversion_VERSION_SVN )
|
2010-08-04 10:51:55 +04:00
|
|
|
|
|
|
|
# for compatibility
|
2012-08-13 21:47:32 +04:00
|
|
|
set(Subversion_FOUND ${SUBVERSION_FOUND})
|
|
|
|
set(Subversion_SVN_FOUND ${SUBVERSION_FOUND})
|