mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-21 19:55:20 -05:00
Aligned CMake built auto fetch svn revision with old qmake $Id: one.
git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3951 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
a9f0dd0efe
commit
3918916025
76
CMake/Modules/FindGitSubversion.cmake
Normal file
76
CMake/Modules/FindGitSubversion.cmake
Normal file
@ -0,0 +1,76 @@
|
||||
# - Extract information from a git-svn working copy
|
||||
# The module defines the following variables:
|
||||
#
|
||||
# If the command line client executable is found two macros are defined:
|
||||
# GitSubversion_WC_INFO(<dir> <var-prefix>)
|
||||
# GitSubversion_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>'
|
||||
# Example usage:
|
||||
# find_package(Subversion)
|
||||
# if(SUBVERSION_FOUND)
|
||||
# GitSubversion_WC_INFO(${PROJECT_SOURCE_DIR} Project)
|
||||
# message("Current revision is ${Project_WC_REVISION}")
|
||||
# endif()
|
||||
|
||||
find_package (Git)
|
||||
|
||||
if(GIT_FOUND)
|
||||
# the git-svn 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(GitSubversion_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 ${GIT_EXECUTABLE} --git-dir=${dir}/.git --work-tree=${dir} svn info
|
||||
OUTPUT_VARIABLE ${prefix}_WC_INFO
|
||||
ERROR_VARIABLE Git_git_svn_info_error
|
||||
RESULT_VARIABLE Git_git_svn_info_result
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
if(NOT ${Git_git_svn_info_result} EQUAL 0)
|
||||
message(SEND_ERROR "Command \"${GIT_EXECUTABLE} --git-dir=${dir}/.git --work-tree=${dir} svn info\" failed with output:\n${Git_git_svn_info_error}")
|
||||
else()
|
||||
|
||||
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}")
|
||||
message (STATUS "Revision: ${${prefix}_WC_REVISION}")
|
||||
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()
|
||||
|
||||
# restore the previous LC_ALL
|
||||
set(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
|
||||
|
||||
endmacro()
|
||||
|
||||
endif()
|
@ -22,7 +22,28 @@ if (Subversion_FOUND AND EXISTS "${SOURCE_DIR}/.svn")
|
||||
file (WRITE svnversion.h.txt "#define SVNVERSION r${MY_WC_REVISION}\n")
|
||||
else (Subversion_FOUND AND EXISTS "${SOURCE_DIR}/.svn")
|
||||
file (WRITE svnversion.h.txt "#define SVNVERSION local\n")
|
||||
endif (Subversion_FOUND AND EXISTS "${SOURCE_DIR}/.svn")
|
||||
endif ()
|
||||
|
||||
if (Subversion_FOUND AND EXISTS "${SOURCE_DIR}/.git")
|
||||
# the FindSubversion.cmake module is part of the standard distribution
|
||||
include (${SOURCE_DIR}/CMake/Modules/FindGitSubversion.cmake)
|
||||
# extract working copy information for SOURCE_DIR into MY_XXX variables
|
||||
GitSubversion_WC_INFO (${SOURCE_DIR} MY)
|
||||
message ("${MY_WC_INFO}")
|
||||
# try and determine if the working copy has outstanding changes
|
||||
execute_process (COMMAND ${GIT_EXECUTABLE} --git-dir=${SOURCE_DIR}/.git --work-tree=${SOURCE_DIR} svn dcommit --dry-run
|
||||
RESULT_VARIABLE __git_svn_status
|
||||
OUTPUT_FILE "${OUTPUT_DIR}/svn_status.txt"
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
message (STATUS "git-svn status: ${__git_svn_status}")
|
||||
if (NOT ${__git_svn_status} EQUAL 0)
|
||||
set (MY_WC_REVISION "${MY_WC_REVISION}-dirty")
|
||||
endif ()
|
||||
# write a file with the SVNVERSION define
|
||||
file (WRITE svnversion.h.txt "#define SVNVERSION r${MY_WC_REVISION}\n")
|
||||
else (Subversion_FOUND AND EXISTS "${SOURCE_DIR}/.svn")
|
||||
file (WRITE svnversion.h.txt "#define SVNVERSION local\n")
|
||||
endif ()
|
||||
|
||||
# copy the file to the final header only if the version changes
|
||||
# reduces needless rebuilds
|
||||
|
Loading…
Reference in New Issue
Block a user