Commit 3425ca7d authored by jcfr's avatar jcfr
Browse files

ENH: Add SlicerMacroExtractRepositoryInfo

This macro allows to conveniently extract information associated with a
checkout of either git, git-svn or svn.

Note that CVS support still need to be added.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@16381 3bd1e089-480b-0410-8dfb-8563597acbee
parent 28e82c27
################################################################################
#
# Program: 3D Slicer
#
# Copyright (c) 2010 Kitware Inc.
#
# See Doc/copyright/copyright.txt
# or http://www.slicer.org/copyright/copyright.txt for details.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
# and was partially funded by NIH grant 3P41RR013218-12S1
#
################################################################################
#
# The following CMake macro will attempt to 'guess' which type of repository is
# associated with the current source directory. Then, base on the type of repository,
# it will extract its associated information.
#
#
# SlicerMacroExtractRepositoryInfo(VAR_PREFIX <var-prefix> [SOURCE_DIR <dir>])
#
# If no SOURCE_DIR is provided, it will default to CMAKE_CURRENT_SOURCE_DIR.
#
# The macro will define the following variables:
# <var-prefix>_WC_TYPE - Either 'git' or 'svn' - The type will also be 'svn' if 'git-svn' is used.
#
# If a GIT repository is associated with SOURCE_DIR, the macro
# will define the following variables:
# <var-prefix>_WC_URL - url of the repository (at SOURCE_DIR)
# <var-prefix>_WC_REVISION_NAME - url of the repository (at SOURCE_DIR)
# <var-prefix>_WC_REVISION_HASH - current revision
# <var-prefix>_WC_REVISION - Equal to <var-prefix>_WC_REVISION_HASH if not a git-svn repository
#
# If a SVN or GIT-SVN repository is associated with SOURCE_DIR, the macro
# will define the following variables:
# <var-prefix>_WC_URL - url of the repository (at SOURCE_DIR)
# <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
#
MACRO(SlicerMacroExtractRepositoryInfo)
SET(options)
SET(oneValueArgs VAR_PREFIX SOURCE_DIR)
SET(multiValueArgs)
cmake_parse_arguments(MY "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# Sanity checks
if("${MY_VAR_PREFIX}" STREQUAL "")
message(FATAL_ERROR "error: VAR_PREFIX should be specified !")
endif()
SET(wc_info_prefix ${MY_VAR_PREFIX})
if ("${MY_SOURCE_DIR}" STREQUAL "")
SET(MY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
endif()
# Clear variables
SET(${wc_info_prefix}_WC_TYPE)
SET(${wc_info_prefix}_WC_INFO)
# Clear SVN, GIT_SVN specific variables
SET(${wc_info_prefix}_WC_URL "NA")
SET(${wc_info_prefix}_WC_REVISION 0)
SET(${wc_info_prefix}_WC_LAST_CHANGED_AUTHOR)
SET(${wc_info_prefix}_WC_LAST_CHANGED_DATE)
SET(${wc_info_prefix}_WC_LAST_CHANGED_REV)
# Clear GIT specific variables
SET(${wc_info_prefix}_WC_REVISION_NAME "NA")
SET(${wc_info_prefix}_WC_REVISION_HASH "NA")
FIND_PACKAGE(Git REQUIRED)
# Is <SOURCE_DIR> a git working copy ?
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list -n 1 HEAD
WORKING_DIRECTORY ${MY_SOURCE_DIR}
RESULT_VARIABLE GIT_result
OUTPUT_QUIET
ERROR_QUIET)
IF(${GIT_result} EQUAL 0)
SET(${wc_info_prefix}_WC_TYPE git)
GIT_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} ${wc_info_prefix})
IF(${wc_info_prefix}_WC_GITSVN)
SET(${wc_info_prefix}_WC_TYPE svn)
ENDIF()
ELSE()
FIND_PACKAGE(Subversion REQUIRED)
# Is <SOURCE_DIR> a svn working copy ?
EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} info
WORKING_DIRECTORY ${MY_SOURCE_DIR}
RESULT_VARIABLE Subversion_result
OUTPUT_QUIET
ERROR_QUIET)
IF(${Subversion_result} EQUAL 0)
SET(${wc_info_prefix}_WC_TYPE svn)
Subversion_WC_INFO(${MY_SOURCE_DIR} ${wc_info_prefix})
ELSE()
FIND_PACKAGE(CVS REQUIRED)
# Is <SOURCE_DIR> a CVS working copy ?
IF(EXISTS ${MY_SOURCE_DIR}/CVS)
# TODO
MESSAGE(AUTHOR_WARNING "CVS info extraction not yet implemented !")
ELSE()
MESSAGE(WARNING "warning: Failed to extract repository info associated with SOURCE_DIR:${MY_SOURCE_DIR}")
ENDIF()
ENDIF()
ENDIF()
ENDMACRO()
......@@ -39,6 +39,7 @@ SET(Slicer_CMAKE_DIR "${Slicer_SOURCE_DIR}/CMake" CACHE INTERNAL "")
INCLUDE(CMakeParseArguments)
INCLUDE(Slicer3PluginsMacros)
INCLUDE(SlicerMacroDiscoverSystemNameAndBits)
INCLUDE(SlicerMacroExtractRepositoryInfo)
INCLUDE(SlicerMacroParseArguments)
INCLUDE(SlicerMacroBuildCLI)
INCLUDE(SlicerMacroEmptyExternalProject)
......@@ -518,34 +519,18 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} ${Slicer_REQUIRED_CXX_FLAGS} ${ITK_
# Generate SlicerVersion.txt
#-----------------------------------------------------------------------------
# Note that Slicer_BUILD is set above
SET(Slicer_WC_URL NA)
SET(Slicer_WC_REVISION 0)
SET(slicer_version_file_source ${CMAKE_CURRENT_SOURCE_DIR}/SlicerVersion.txt.in)
SET(slicer_version_file_binary ${Slicer_HOME}/lib/Slicer3/SlicerVersion.txt)
SlicerMacroExtractRepositoryInfo(VAR_PREFIX Slicer)
# Case where Slicer is checkout using SVN
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.svn)
Subversion_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} Slicer)
CONFIGURE_FILE(
${slicer_version_file_source}
${slicer_version_file_binary}
)
ENDIF()
SET(slicer_version_file ${Slicer_HOME}/lib/Slicer3/SlicerVersion.txt)
# Case where Slicer is checkout using Git-SVN
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/svn/refs/remotes)
GIT_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} Slicer)
CONFIGURE_FILE(
${slicer_version_file_source}
${slicer_version_file_binary}
)
ENDIF()
# Note that Slicer_BUILD is set above
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/SlicerVersion.txt.in
${slicer_version_file}
)
INSTALL(FILES
${slicer_version_file_binary}
${slicer_version_file}
DESTINATION ${Slicer_INSTALL_LIB_DIR}
COMPONENT Development
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment