Last active
January 29, 2021 05:52
-
-
Save cmcqueen/122ecdfb64d584a6f1dafd38fe2e009d to your computer and use it in GitHub Desktop.
FindSubversion.cmake w\ git-svn support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# - Extract information from a subversion working copy | |
# The module defines the following variables: | |
# 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 | |
# SUBVERSION_FOUND - same as Subversion_FOUND, set for compatiblity reasons | |
# | |
# The minimum required version of Subversion can be specified using the | |
# standard syntax, e.g. FIND_PACKAGE(Subversion 1.4) | |
# | |
# If the command line client executable is found two macros are defined: | |
# 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>' | |
# Subversion_WC_LOG retrieves the log message of the base revision of a | |
# subversion working copy at a given location. This macro defines the | |
# variable: | |
# <var-prefix>_LAST_CHANGED_LOG - last log of base revision | |
# Example usage: | |
# 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(SUBVERSION_FOUND) | |
#============================================================================= | |
#CMake - Cross Platform Makefile Generator | |
#Copyright 2000-2009 Kitware, Inc., Insight Software Consortium | |
#All rights reserved. | |
# | |
#Redistribution and use in source and binary forms, with or without | |
#modification, are permitted provided that the following conditions | |
#are met: | |
# | |
#* Redistributions of source code must retain the above copyright | |
# notice, this list of conditions and the following disclaimer. | |
# | |
#* Redistributions in binary form must reproduce the above copyright | |
# notice, this list of conditions and the following disclaimer in the | |
# documentation and/or other materials provided with the distribution. | |
# | |
#* Neither the names of Kitware, Inc., the Insight Software Consortium, | |
# nor the names of their contributors may be used to endorse or promote | |
# products derived from this software without specific prior written | |
# permission. | |
# | |
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
#A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
#HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
#SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
#LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
#DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
#THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
# | |
#------------------------------------------------------------------------------ | |
# | |
#The above copyright and license notice applies to distributions of | |
#CMake in source and binary form. Some source files contain additional | |
#notices of original copyright by their contributors; see each source | |
#for details. Third-party software packages supplied with CMake under | |
#compatible licenses provide their own copyright notices documented in | |
#corresponding subdirectories. | |
# | |
#------------------------------------------------------------------------------ | |
# | |
#CMake was initially developed by Kitware with the following sponsorship: | |
# | |
# * National Library of Medicine at the National Institutes of Health | |
# as part of the Insight Segmentation and Registration Toolkit (ITK). | |
# | |
# * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel | |
# Visualization Initiative. | |
# | |
# * National Alliance for Medical Image Computing (NAMIC) is funded by the | |
# National Institutes of Health through the NIH Roadmap for Medical Research, | |
# Grant U54 EB005149. | |
# | |
# * Kitware, Inc. | |
FIND_PROGRAM(Subversion_SVN_EXECUTABLE svn | |
DOC "subversion command line client") | |
MARK_AS_ADVANCED(Subversion_SVN_EXECUTABLE) | |
IF(Subversion_SVN_EXECUTABLE) | |
# the subversion commands should be executed with the C locale, otherwise | |
# the message (which are parsed) may be translated, Alex | |
SET(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}") | |
SET(ENV{LC_ALL} C) | |
EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} --version | |
OUTPUT_VARIABLE Subversion_VERSION_SVN | |
OUTPUT_STRIP_TRAILING_WHITESPACE) | |
# restore the previous LC_ALL | |
SET(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL}) | |
STRING(REGEX REPLACE "^(.*\n)?svn, version ([.0-9]+).*" | |
"\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}") | |
MACRO(Subversion_WC_INFO dir prefix) | |
# the subversion commands should be executed with the C locale, otherwise | |
# the message (which are parsed) may be translated, Alex | |
SET(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}") | |
SET(ENV{LC_ALL} C) | |
EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} info ${dir} | |
OUTPUT_VARIABLE ${prefix}_WC_INFO | |
ERROR_VARIABLE Subversion_svn_info_error | |
RESULT_VARIABLE Subversion_svn_info_result | |
OUTPUT_STRIP_TRAILING_WHITESPACE) | |
IF(NOT ${Subversion_svn_info_result} EQUAL 0) | |
EXECUTE_PROCESS(COMMAND /usr/bin/git svn info . | |
OUTPUT_VARIABLE ${prefix}_WC_INFO | |
ERROR_VARIABLE Subversion_svn_info_error | |
RESULT_VARIABLE Subversion_svn_info_result | |
WORKING_DIRECTORY ${dir} | |
OUTPUT_STRIP_TRAILING_WHITESPACE) | |
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}") | |
ENDIF(NOT ${Subversion_svn_info_result} EQUAL 0) | |
ENDIF(NOT ${Subversion_svn_info_result} EQUAL 0) | |
IF(${Subversion_svn_info_result} EQUAL 0) | |
STRING(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*" | |
"\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}") | |
STRING(REGEX REPLACE "^(.*\n)?Repository Root: ([^\n]+).*" | |
"\\2" ${prefix}_WC_ROOT "${${prefix}_WC_INFO}") | |
STRING(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*" | |
"\\2" ${prefix}_WC_REVISION "${${prefix}_WC_INFO}") | |
STRING(REGEX REPLACE "^(.*\n)?Last Changed Author: ([^\n]+).*" | |
"\\2" ${prefix}_WC_LAST_CHANGED_AUTHOR "${${prefix}_WC_INFO}") | |
STRING(REGEX REPLACE "^(.*\n)?Last Changed Rev: ([^\n]+).*" | |
"\\2" ${prefix}_WC_LAST_CHANGED_REV "${${prefix}_WC_INFO}") | |
STRING(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*" | |
"\\2" ${prefix}_WC_LAST_CHANGED_DATE "${${prefix}_WC_INFO}") | |
ENDIF(${Subversion_svn_info_result} EQUAL 0) | |
# restore the previous LC_ALL | |
SET(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL}) | |
ENDMACRO(Subversion_WC_INFO) | |
MACRO(Subversion_WC_LOG dir prefix) | |
# 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 | |
EXECUTE_PROCESS(COMMAND | |
${Subversion_SVN_EXECUTABLE} log -r BASE ${dir} | |
OUTPUT_VARIABLE ${prefix}_LAST_CHANGED_LOG | |
ERROR_VARIABLE Subversion_svn_log_error | |
RESULT_VARIABLE Subversion_svn_log_result | |
OUTPUT_STRIP_TRAILING_WHITESPACE) | |
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}") | |
ENDIF(NOT ${Subversion_svn_log_result} EQUAL 0) | |
ENDMACRO(Subversion_WC_LOG) | |
ENDIF(Subversion_SVN_EXECUTABLE) | |
#INCLUDE("${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake") | |
INCLUDE("${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake") | |
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Subversion REQUIRED_VARS Subversion_SVN_EXECUTABLE | |
VERSION_VAR Subversion_VERSION_SVN ) | |
# for compatibility | |
SET(Subversion_FOUND ${SUBVERSION_FOUND}) | |
SET(Subversion_SVN_FOUND ${SUBVERSION_FOUND}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment