Skip to content

Commit

Permalink
ENH: First pass at adding version control
Browse files Browse the repository at this point in the history
Attempt to uniformly provide version information from
BRAINSTools.  Following conventions from http://semver.org

Semantic Versioning 2.0.0

Summary

Given a version number MAJOR.MINOR.PATCH, increment the:

MAJOR version when you make incompatible API changes,
MINOR version when you add functionality in a backwards-compatible manner, and
PATCH version when you make backwards-compatible bug fixes.
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
  • Loading branch information
hjmjohnson committed Jan 14, 2015
1 parent d7e73ee commit ea04d47
Show file tree
Hide file tree
Showing 11 changed files with 522 additions and 1 deletion.
71 changes: 71 additions & 0 deletions BRAINSCommonLib/BRAINSToolsVersion.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*=========================================================================
* Modified from BRAINSTools reference
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* 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.
*
*=========================================================================*/
#include "BRAINSToolsVersion.h"
#include "BRAINSToolsVersionConfig.h"

#include <iostream> // std::cout, std::ios
#include <sstream> // std::ostringstream

namespace
{

std::string MakeExtendedVersionString()
{
std::ostringstream v;
v << "BRAINSTools Version: " << BRAINSTools::Version::VersionString() << std::endl
<< "Compiled: " << BRAINSTools::Version::BuildDate() << std::endl;
return v.str();
}

static const std::string extendedVersionString = MakeExtendedVersionString();

}

namespace BRAINSTools
{
unsigned int Version::MajorVersion()
{
return BRAINSTools_VERSION_MAJOR;
}
unsigned int Version::MinorVersion()
{
return BRAINSTools_VERSION_MINOR;
}
unsigned int Version::PatchVersion()
{
return BRAINSTools_VERSION_PATCH;
}
unsigned int Version::TweakVersion()
{
return 0;
}
const std::string &Version::VersionString()
{
static const std::string v( BRAINSTools_VERSION );
return v;
}
const std::string &Version::BuildDate()
{
static const std::string v( __DATE__ " " __TIME__ );
return v;
}
const std::string &Version::ExtendedVersionString()
{
return extendedVersionString;
}
}
47 changes: 47 additions & 0 deletions BRAINSCommonLib/BRAINSToolsVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* 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.
*
*=========================================================================*/
#ifndef __BRAINSToolsVersion_h
#define __BRAINSToolsVersion_h

//NOTE: Windows magic needed here
#define BRAINSToolsCommon_EXPORT

#include <string>

namespace BRAINSTools
{

/** \class Version
* \brief Version info for BRAINSTools
*/
class BRAINSToolsCommon_EXPORT Version
{
public:
static unsigned int MajorVersion();
static unsigned int MinorVersion();
static unsigned int PatchVersion();
static unsigned int TweakVersion();
static const std::string &VersionString();
static const std::string &BuildDate();

static const std::string &ExtendedVersionString();
std::string ToString() { return Version::ExtendedVersionString(); }
};
}

#endif
23 changes: 23 additions & 0 deletions BRAINSCommonLib/BRAINSToolsVersionConfig.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* 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.
*
*=========================================================================*/

#define BRAINSTools_VERSION_MAJOR @BRAINSTools_VERSION_MAJOR@
#define BRAINSTools_VERSION_MINOR @BRAINSTools_VERSION_MINOR@
#define BRAINSTools_VERSION_PATCH @BRAINSTools_VERSION_PATCH@
#define BRAINSTools_VERSION_TWEAK @BRAINSTools_VERSION_TWEAK@
#define BRAINSTools_VERSION "@BRAINSTools_VERSION@"
6 changes: 6 additions & 0 deletions BRAINSCommonLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ LIST_CONTAINS(ITK_HAS_MGHIO MGHIO ${ITK_MODULES_ENABLED})
if (NOT ITK_HAS_MGHIO)
message(STATUS "WARNING: ITK_MODULES_ENABLED does not contain MGHIO, so programs will not be able to process .mgz formatted files")
endif()

configure_file("BRAINSToolsVersionConfig.h.in" "BRAINSToolsVersionConfig.h" @ONLY IMMEDIATE)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/BRAINSToolsVersionConfig.h"
DESTINATION "${BRAINSTools_CLI_INSTALL_ARCHIVE_DESTINATION}/include" COMPONENT Development)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/BRAINSCommonLib.h.in
${CMAKE_CURRENT_BINARY_DIR}/BRAINSCommonLib.h
Expand All @@ -63,6 +68,7 @@ set(BRAINSCommonLib_SRCS
itkOrthogonalize3DRotationMatrix.cxx
BRAINSThreadControl.cxx
ExtractSingleLargestRegion.cxx
BRAINSToolsVersion.cxx
)

## Always build BRAINSCommonLib as static
Expand Down
9 changes: 9 additions & 0 deletions BRAINSFit/BRAINSFit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "BRAINSFitHelper.h"
#include "BRAINSFitCLP.h"

#include "BRAINSToolsVersion.h"


// This program was modified from
// Insight/Examples/Registration/ImageRegistration8.cxx
Expand Down Expand Up @@ -105,6 +107,13 @@ DebugImageViewerClient DebugImageDisplaySender;
int main(int argc, char *argv[])
{
PARSE_ARGS;

if(printVersionInfo)
{
std::cout << BRAINSTools::Version::ExtendedVersionString() << std::endl;
return EXIT_SUCCESS;
}

BRAINSRegisterAlternateIO();

#ifdef USE_DebugImageViewer
Expand Down
7 changes: 6 additions & 1 deletion BRAINSFit/BRAINSFit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<license>https://www.nitrc.org/svn/brains/BuildScripts/trunk/License.txt</license>
<contributor>Hans J. Johnson, hans-johnson -at- uiowa.edu, http://www.psychiatry.uiowa.edu</contributor>
<acknowledgements><![CDATA[Hans Johnson(1,3,4); Kent Williams(1); Gregory Harris(1), Vincent Magnotta(1,2,3); Andriy Fedorov(5) 1=University of Iowa Department of Psychiatry, 2=University of Iowa Department of Radiology, 3=University of Iowa Department of Biomedical Engineering, 4=University of Iowa Department of Electrical and Computer Engineering, 5=Surgical Planning Lab, Harvard]]> </acknowledgements>
<version>3.0.0</version>
<version>4.2.0</version>

<parameters advanced="false">
<label>Input Images</label>
Expand Down Expand Up @@ -529,6 +529,11 @@
<description>A file to write out final information report in CSV file: MetricName,MetricValue,FixedImageName,FixedMaskName,MovingImageName,MovingMaskName</description>
<channel>output</channel>
</file>
<boolean>
<name>printVersionInfo</name>
<flag>v</flag>
<default>false</default>
</boolean>
</parameters>

</executable>
29 changes: 29 additions & 0 deletions BRAINSTools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@ set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
)

#-----------------------------------------------------------------------------
# Version information
include(Version.cmake)

set(${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}")
if(DEFINED ${PROJECT_NAME}_VERSION_PATCH)
set(${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION}.${${PROJECT_NAME}_VERSION_PATCH}")
if(DEFINED ${PROJECT_NAME}_VERSION_TWEAK)
set(${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION}.${${PROJECT_NAME}_VERSION_TWEAK}")
endif()
endif()

if(DEFINED ${PROJECT_NAME}_VERSION_RC)
set(${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION}${${PROJECT_NAME}_VERSION_RC}")
endif()
if(DEFINED ${PROJECT_NAME}_VERSION_POST)
set(${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION}.post${${PROJECT_NAME}_VERSION_POST}")
elseif(DEFINED ${PROJECT_NAME}_VERSION_DEV)
set(${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION}.dev${${PROJECT_NAME}_VERSION_DEV}")
endif()

option( ${PROJECT_NAME}_BUILD_DISTRIBUTE "Remove '-g#####' from version. ( for official distribution only )" OFF )
mark_as_advanced( ${PROJECT_NAME}_BUILD_DISTRIBUTE )
if( NOT ${PROJECT_NAME}_BUILD_DISTRIBUTE )
set(${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION}-g${${PROJECT_NAME}_VERSION_HASH}")
endif()

message(STATUS "Building ${PROJECT_NAME} version \"${${PROJECT_NAME}_VERSION}\"")

include(FindITKUtil)
include(FindVTKUtil)
# #-----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit ea04d47

Please sign in to comment.