Commit d7e90ba1 authored by Brian Panneton's avatar Brian Panneton
Browse files

ENH: Added Xdmf Versioning

parent e0c4fa30
# Version Suite
# Author: Brian Panneton
# Descrition: This small suite allows you to add support
# for versioning in your projects
# This allows you to turn on and off the auto
# update of the (project name)Version.hpp file
SET(VERSION_CONTROL_AUTOUPDATE ON CACHE BOOL "Automaticaly Update The Version")
MARK_AS_ADVANCED(VERSION_CONTROL_AUTOUPDATE)
# We need to make sure we have the header file
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/CMake/VersionSuite)
# Default incase CalculateVerison is not called
SET(vMajor "0")
SET(vMinor "0")
# This Macro allows you to set the rewrite number
MACRO(VersionMajorSet versionMajor)
SET(vMajor ${versionMajor})
ENDMACRO(VersionMajorSet)
# This Macro calculates the number of tags from your git repo
MACRO(VersionCalculate)
EXEC_PROGRAM(git ${CMAKE_SOURCE_DIR} ARGS tag OUTPUT_VARIABLE return)
STRING(REGEX REPLACE "\n" ";" return "${return}")
SET(count 0)
FOREACH(r ${return})
MATH(EXPR count "${count} + 1")
ENDFOREACH(r ${return})
SET(vMinor ${count})
ENDMACRO(VersionCalculate)
# This Macro writes your hpp file
MACRO(VersionWrite versionProjectName)
FILE(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/${versionProjectName}Version.hpp
"/*Current Version of ${versionProjectName}*/
\#define VersionMajor ${vMajor}
\#define VersionMinor ${vMinor}
\#include \"Version.hpp\"\n"
)
ENDMACRO(VersionWrite)
/* Version Suite Class
* Author: Brian Panneton
*/
#include <string>
#include <sstream>
/**
* @brief Version Suite to assist in adding versioning to your project
*
* A simple way to have the library contain its own version.
*/
class Version {
public:
/**
* Create a Version class object
*
* @param name of the project
*/
Version(std::string cProjectName) {
setProjectName(cProjectName);
setMajor(VersionMajor);
setMinor(VersionMinor);
}
/**
* Get the version string
*
* @return the Version in "ProjectName Major.Minor" string format
*/
std::string getVersion() {
return getProjectName()+std::string(" ")+
getMajorStr()+std::string(".")+
getMinorStr();
}
/**
* Get the shorter version string
*
* @return the Version in "Major.Minor" string format
*/
std::string getVersionShort() {
return getMajorStr()+std::string(".")+
getMinorStr();
}
/**
* Get the version objects project name
*
* @return the project name in string format
*/
std::string getProjectName() { return ProjectName; }
/**
* Get the Version Major
*
* @return the Version Major in string format
*/
std::string getMajorStr()
{ return IntToStr(Major); }
/**
* Get the Version Minor
*
* @return the Version Minor in string format
*/
std::string getMinorStr()
{ return IntToStr(Minor); }
/**
* Get the Version Major
*
* @return the Version Major in int format
*/
int getMajor() { return Major; }
/**
* Get the Version Minor
*
* @return the Version Minor in int format
*/
int getMinor() { return Minor; }
private:
std::string ProjectName;
int Major, Minor;
std::string IntToStr(int number) {
std::stringstream s;
s << number;
return s.str();
}
void setProjectName(std::string iProjectName)
{ ProjectName = iProjectName; }
void setMajor(int iMajor) { Major = iMajor; }
void setMinor(int iMinor) { Minor = iMinor; }
};
......@@ -13,7 +13,9 @@ SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_MODULE_PATH
${CMAKE_SOURCE_DIR}/CMake
${CMAKE_SOURCE_DIR}/CMake/TestingSuite)
${CMAKE_SOURCE_DIR}/CMake/TestingSuite
${CMAKE_SOURCE_DIR}/CMake/VersionSuite
)
# Should we build with documentation
option(XDMF_BUILD_DOCUMENTATION OFF)
......
project(XdmfCore)
cmake_minimum_required(VERSION 2.6)
include(SetUpVersion)
if(VERSION_CONTROL_AUTOUPDATE)
VersionMajorSet("2")
VersionCalculate()
VersionWrite("Xdmf")
endif(VERSION_CONTROL_AUTOUPDATE)
set(BUILD_SHARED_LIBS true)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
......
/*Current Version of Xdmf*/
#define VersionMajor 2
#define VersionMinor 0
#include "Version.hpp"
......@@ -18,6 +18,7 @@ if(XDMF_BUILD_DSM)
ADD_TEST_CXX(TestXdmfHDF5WriterDSM)
endif(XDMF_BUILD_DSM)
ADD_TEST_CXX(TestXdmfInformation)
ADD_TEST_CXX(TestXdmfVersion)
# Add any cxx cleanup here:
# Note: We don't want to use a foreach loop to test the files incase we
......@@ -34,3 +35,4 @@ if(XDMF_BUILD_DSM)
CLEAN_TEST_CXX(TestXdmfHDF5WriterDSM)
endif(XDMF_BUILD_DSM)
CLEAN_TEST_CXX(TestXdmfInformation)
CLEAN_TEST_CXX(TestXdmfVersion)
#include <iostream>
#include "XdmfVersion.hpp"
int main() {
Version *v = new Version("Xdmf");
if(v->getVersion() == "")
exit(-1);
if(v->getVersionShort() == "")
exit(-1);
std::cout << v->getVersion() << std::endl;
std::cout << v->getVersionShort();
return 0;
}
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