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

FIX: Added default version if Git does not exist. (2.X)

parent 810800fe
......@@ -25,6 +25,12 @@ class ProjectVersion {
setMinor(iMinor);
}
ProjectVersion(std::string iProjectName,
std::string iMajor, std::string iMinor) {
setProjectName(iProjectName);
setMajorStr(iMajor);
setMinorStr(iMinor);
}
/**
* Get the version string
*
......@@ -59,7 +65,10 @@ class ProjectVersion {
* @return the Version Major in string format
*/
std::string getMajorStr()
{ return IntToStr(Major); }
{
if(Major != -1) return IntToStr(Major);
return("X");
}
/**
* Get the Version Minor
......@@ -67,7 +76,10 @@ class ProjectVersion {
* @return the Version Minor in string format
*/
std::string getMinorStr()
{ return IntToStr(Minor); }
{
if(Minor != -1) return IntToStr(Minor);
return("X");
}
/**
* Get the Version Major
......@@ -92,11 +104,23 @@ private:
s << number;
return s.str();
}
int StrToInt(std::string string) {
int i = 0;
std::stringstream s(string);
if(!(s >> i)) return -1;
return i;
}
void setProjectName(std::string iProjectName)
{ ProjectName = iProjectName; }
void setMajor(int iMajor) { Major = iMajor; }
void setMajorStr(std::string iMajor) {
Major = StrToInt(iMajor);
}
void setMinor(int iMinor) { Minor = iMinor; }
void setMinorStr(std::string iMinor) {
Minor = StrToInt(iMinor);
}
};
#endif //PROJECT_VERSION_HPP
......@@ -29,13 +29,18 @@ 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})
FIND_PACKAGE(Git)
IF(GIT_FOUND)
EXEC_PROGRAM(${GIT_EXECUTABLE} ${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})
ELSE(GIT_FOUND)
SET(vMinor "X")
ENDIF(GIT_FOUND)
ENDMACRO(VersionCalculate)
# This Macro writes your hpp/cpp files
......@@ -54,6 +59,6 @@ extern ProjectVersion ${vProjectName}Version;\n"
* Make sure to include this file in your built sources
*/
\#include \"${vProjectName}Version.hpp\"
ProjectVersion ${vProjectName}Version = ProjectVersion(\"${vProjectName}\", ${vMajor}, ${vMinor});\n"
ProjectVersion ${vProjectName}Version = ProjectVersion(\"${vProjectName}\", \"${vMajor}\", \"${vMinor}\");\n"
)
ENDMACRO(VersionWrite)
/* Current Version of Xdmf
* Make sure to include this file in your built sources
*/
#include "XdmfVersion.hpp"
ProjectVersion XdmfVersion = ProjectVersion("Xdmf", 2, 0);
/* Current Version of Xdmf
* Major is: 2
* Minor is: 0
*/
#include "ProjectVersion.hpp"
extern ProjectVersion XdmfVersion;
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