From 2d5c8be24111cd379a0b10b9f6a197f93695971c Mon Sep 17 00:00:00 2001 From: Andrey Fedorov Date: Sun, 12 Aug 2012 09:17:43 -0400 Subject: [PATCH] ENH: adding versioning information at configure time --- .../ReportingMacroExtractRepositoryInfo.cmake | 132 ++++++++++++++++++ CMake/vtkReportingVersionConfigure.h.in | 18 +++ CMakeLists.txt | 10 ++ qSlicerReportingModule.cxx | 5 +- 4 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 CMake/ReportingMacroExtractRepositoryInfo.cmake create mode 100644 CMake/vtkReportingVersionConfigure.h.in diff --git a/CMake/ReportingMacroExtractRepositoryInfo.cmake b/CMake/ReportingMacroExtractRepositoryInfo.cmake new file mode 100644 index 0000000..3cc1ee0 --- /dev/null +++ b/CMake/ReportingMacroExtractRepositoryInfo.cmake @@ -0,0 +1,132 @@ +################################################################################ +# +# Program: 3D Slicer +# +# Copyright (c) Kitware Inc. +# +# See 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 [SOURCE_DIR ]) +# +# If no SOURCE_DIR is provided, it will default to CMAKE_CURRENT_SOURCE_DIR. +# +# The macro will define the following variables: +# _WC_TYPE - Either 'git', 'svn' or 'local' - 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: +# _WC_URL - url of the repository (at SOURCE_DIR) +# _WC_ROOT - Same value as working copy URL +# _WC_REVISION_NAME - url of the repository (at SOURCE_DIR) +# _WC_REVISION_HASH - current revision +# _WC_REVISION - Equal to _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: +# _WC_URL - url of the repository (at SOURCE_DIR) +# _WC_ROOT - root url of the associated SVN repository +# _WC_REVISION - current revision +# _WC_LAST_CHANGED_AUTHOR - author of last commit +# _WC_LAST_CHANGED_DATE - date of last commit +# _WC_LAST_CHANGED_REV - revision of last commit +# _WC_INFO +# + +macro(SlicerMacroExtractRepositoryInfo) + include(CMakeParseArguments) + 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(NOT EXISTS "${MY_SOURCE_DIR}") + set(MY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + endif() + + # Clear variables + set(${wc_info_prefix}_WC_TYPE local) + set(${wc_info_prefix}_WC_INFO) + + # Clear SVN, GIT_SVN specific variables + set(${wc_info_prefix}_WC_URL "NA") + set(${wc_info_prefix}_WC_ROOT "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 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(${MY_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 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() + + # Is a CVS working copy ? + if(EXISTS ${MY_SOURCE_DIR}/CVS) + + message(AUTHOR_WARNING "CVS info extraction *NOT* implemented !") + + endif() + endif() + endif() +endmacro() + + diff --git a/CMake/vtkReportingVersionConfigure.h.in b/CMake/vtkReportingVersionConfigure.h.in new file mode 100644 index 0000000..9ad4578 --- /dev/null +++ b/CMake/vtkReportingVersionConfigure.h.in @@ -0,0 +1,18 @@ +/*=auto========================================================================= + + Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH) + All Rights Reserved. + + See COPYRIGHT.txt + or http://www.slicer.org/copyright/copyright.txt for details. + + Program: 3D Reporting + +=========================================================================auto=*/ + +#ifndef __vtkReportingVersionConfigure_h +#define __vtkReportingVersionConfigure_h + +#define Reporting_WC_REVISION "@Reporting_WC_REVISION@" + +#endif // __vtkReportingVersionConfigure_h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e65621..1b24ed1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,16 @@ if(NOT Slicer_SOURCE_DIR) include(${Slicer_USE_FILE}) endif() +set(CMAKE_MODULE_PATH + ${CMAKE_CURRENT_SOURCE_DIR}/CMake + ${CMAKE_MODULE_PATH} +) + +include(SlicerMacroExtractRepositoryInfo) + +SlicerMacroExtractRepositoryInfo(VAR_PREFIX Reporting) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMake/vtkReportingVersionConfigure.h.in + ${CMAKE_CURRENT_BINARY_DIR}/vtkReportingVersionConfigure.h) #----------------------------------------------------------------------------- add_subdirectory(MRML) diff --git a/qSlicerReportingModule.cxx b/qSlicerReportingModule.cxx index 960554a..0c98ce0 100644 --- a/qSlicerReportingModule.cxx +++ b/qSlicerReportingModule.cxx @@ -26,6 +26,7 @@ // Reporting includes #include "qSlicerReportingModule.h" +#include "vtkReportingVersionConfigure.h" // SlicerQT includes #include @@ -73,8 +74,8 @@ QString qSlicerReportingModule::helpText()const return "The Reporting module provides support for structured markup and annotation, and " "some support of AIM import/export.
" "Select a markup and right click to jump slice viewers to that location.
" - "This is a work in progress. " - "" + "This is a work in progress (revision " + QString(Reporting_WC_REVISION)+ + "). " "Usage instructions."; }