From 42befe3149981be8f5eeb5833c5cdd00d80f97d6 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Mon, 19 Jan 2015 10:49:04 +0100
Subject: [PATCH] OGS version information is now handled by its git tag.

When the current commit is also a tag then the version is the tag name,
e.g. "6.0.1". When the current commit is not a tag then the ogs version
is the last tag + number of commits since then + current commit short
hash, e.g. "6.0.1-140-g80ac475".

This info is available in BaseLib::BuildInfo::git_describe. Use it to
uniquely set the OGS version.
---
 Applications/CLI/ogs.cpp                            |  2 +-
 Applications/DataExplorer/main.cpp                  |  3 +--
 Applications/DataExplorer/mainwindow.cpp            |  6 +++---
 Applications/Utils/FileConverter/TIN2VTK.cpp        |  2 +-
 Applications/Utils/FileConverter/VTK2TIN.cpp        |  2 +-
 Applications/Utils/MeshEdit/checkMesh.cpp           |  2 +-
 Applications/Utils/MeshEdit/reviseMesh.cpp          |  2 +-
 .../SimpleMeshCreation/generateStructuredMesh.cpp   |  2 +-
 BaseLib/BuildInfo.cpp.in                            |  2 +-
 BaseLib/BuildInfo.h                                 |  2 +-
 CMakeLists.txt                                      | 13 -------------
 FileIO/GMSHInterface.cpp                            |  4 ++--
 scripts/cmake/CMakeSetup.cmake                      | 13 +++++++++++++
 scripts/cmake/cmake/GetGitRevisionDescription.cmake |  5 +++++
 scripts/cmake/packaging/Pack.cmake                  |  4 ++--
 15 files changed, 34 insertions(+), 30 deletions(-)

diff --git a/Applications/CLI/ogs.cpp b/Applications/CLI/ogs.cpp
index 1b35788142c..58bf2289204 100644
--- a/Applications/CLI/ogs.cpp
+++ b/Applications/CLI/ogs.cpp
@@ -49,7 +49,7 @@ int main(int argc, char *argv[])
 			"See accompanying file LICENSE.txt or "
 			"http://www.opengeosys.org/project/license",
 		' ',
-		BaseLib::BuildInfo::git_version_sha1);
+		BaseLib::BuildInfo::git_describe);
 
 	TCLAP::UnlabeledValueArg<std::string> project_arg(
 		"project-file",
diff --git a/Applications/DataExplorer/main.cpp b/Applications/DataExplorer/main.cpp
index f4c6d16682f..88b73df9541 100644
--- a/Applications/DataExplorer/main.cpp
+++ b/Applications/DataExplorer/main.cpp
@@ -36,8 +36,7 @@ int main(int argc, char* argv[])
 	QLocale::setDefault(QLocale::German);
 	MainWindow* w = new MainWindow();
 	w->setWindowTitle( w->windowTitle() + " - " +
-		QString::fromStdString(BaseLib::BuildInfo::ogs_version_and_persons) +
-		" - FirstFloor");
+		QString::fromStdString(BaseLib::BuildInfo::git_describe));
 	w->show();
 	int returncode = a.exec();
 	delete w;
diff --git a/Applications/DataExplorer/mainwindow.cpp b/Applications/DataExplorer/mainwindow.cpp
index 0d0528832bb..d24e173c6a1 100644
--- a/Applications/DataExplorer/mainwindow.cpp
+++ b/Applications/DataExplorer/mainwindow.cpp
@@ -692,9 +692,9 @@ void MainWindow::showLicense()
 void MainWindow::about()
 {
 	QString about("<a href='http://www.opengeosys.org'>http://www.opengeosys.org</a><br /><br />");
-	QString ogsVersion = QString::fromStdString(
-		BaseLib::BuildInfo::ogs_version_and_persons);
-	about.append(QString("Version: %1<br /><br />").arg(ogsVersion));
+	about.append(QString("Version: <a href='https://github.com/ufz/ogs/releases/tag/%2'>%1</a><br /><br />")
+		.arg(QString::fromStdString(BaseLib::BuildInfo::git_describe))
+		.arg(QString::fromStdString(BaseLib::BuildInfo::ogs_version)));
 
 	about.append(QString("Git commit: <a href='https://github.com/ufz/ogs/commit/%1'>%1</a><br />")
 		.arg(QString::fromStdString(BaseLib::BuildInfo::git_version_sha1_short)));
diff --git a/Applications/Utils/FileConverter/TIN2VTK.cpp b/Applications/Utils/FileConverter/TIN2VTK.cpp
index 7942a55d02c..a30ea9ad786 100644
--- a/Applications/Utils/FileConverter/TIN2VTK.cpp
+++ b/Applications/Utils/FileConverter/TIN2VTK.cpp
@@ -42,7 +42,7 @@ int main (int argc, char* argv[])
 	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
 	logog_cout->SetFormatter(*custom_format);
 
-	TCLAP::CmdLine cmd("Converts TIN file into VTU file.", ' ', BaseLib::BuildInfo::git_version_sha1);
+	TCLAP::CmdLine cmd("Converts TIN file into VTU file.", ' ', BaseLib::BuildInfo::git_describe);
 	TCLAP::ValueArg<std::string> inArg("i", "input-tin-file",
 	                                     "the name of the file containing the input TIN", true,
 	                                     "", "string");
diff --git a/Applications/Utils/FileConverter/VTK2TIN.cpp b/Applications/Utils/FileConverter/VTK2TIN.cpp
index a74ffe1b8ec..2dbe838b286 100644
--- a/Applications/Utils/FileConverter/VTK2TIN.cpp
+++ b/Applications/Utils/FileConverter/VTK2TIN.cpp
@@ -43,7 +43,7 @@ int main (int argc, char* argv[])
 	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
 	logog_cout->SetFormatter(*custom_format);
 
-	TCLAP::CmdLine cmd("Converts VTK mesh into TIN file.", ' ', BaseLib::BuildInfo::git_version_sha1);
+	TCLAP::CmdLine cmd("Converts VTK mesh into TIN file.", ' ', BaseLib::BuildInfo::git_describe);
 	TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file",
 	                                     "the name of the file containing the input mesh", true,
 	                                     "", "file name of input mesh");
diff --git a/Applications/Utils/MeshEdit/checkMesh.cpp b/Applications/Utils/MeshEdit/checkMesh.cpp
index 623d69ca539..9bea61f02fb 100644
--- a/Applications/Utils/MeshEdit/checkMesh.cpp
+++ b/Applications/Utils/MeshEdit/checkMesh.cpp
@@ -37,7 +37,7 @@ int main(int argc, char *argv[])
 	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
 	logog_cout->SetFormatter(*custom_format);
 
-	TCLAP::CmdLine cmd("Checks mesh properties", ' ', BaseLib::BuildInfo::git_version_sha1);
+	TCLAP::CmdLine cmd("Checks mesh properties", ' ', BaseLib::BuildInfo::git_describe);
 	TCLAP::UnlabeledValueArg<std::string> mesh_arg("mesh-file","input mesh file",true,"","string");
 	cmd.add( mesh_arg );
 	TCLAP::SwitchArg valid_arg("v","validation","validate the mesh");
diff --git a/Applications/Utils/MeshEdit/reviseMesh.cpp b/Applications/Utils/MeshEdit/reviseMesh.cpp
index 7dc04e72d1a..3301e96e819 100644
--- a/Applications/Utils/MeshEdit/reviseMesh.cpp
+++ b/Applications/Utils/MeshEdit/reviseMesh.cpp
@@ -33,7 +33,7 @@ int main(int argc, char *argv[])
 	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
 	logog_cout->SetFormatter(*custom_format);
 
-	TCLAP::CmdLine cmd("Mesh revision tool", ' ', BaseLib::BuildInfo::git_version_sha1);
+	TCLAP::CmdLine cmd("Mesh revision tool", ' ', BaseLib::BuildInfo::git_describe);
 	TCLAP::ValueArg<std::string> input_arg("i", "input-mesh-file","input mesh file",true,"","string");
 	cmd.add( input_arg );
 	TCLAP::ValueArg<std::string> output_arg("o", "output-mesh-file","output mesh file",true,"","string");
diff --git a/Applications/Utils/SimpleMeshCreation/generateStructuredMesh.cpp b/Applications/Utils/SimpleMeshCreation/generateStructuredMesh.cpp
index 7adb50c64cd..1a285df599f 100644
--- a/Applications/Utils/SimpleMeshCreation/generateStructuredMesh.cpp
+++ b/Applications/Utils/SimpleMeshCreation/generateStructuredMesh.cpp
@@ -76,7 +76,7 @@ int main (int argc, char* argv[])
 			"See accompanying file LICENSE.txt or "
 			"http://www.opengeosys.org/project/license",
 		' ',
-		BaseLib::BuildInfo::git_version_sha1);
+		BaseLib::BuildInfo::git_describe);
 
 	std::unique_ptr<BaseLib::TCLAPCustomOutput> tclapOutput(new BaseLib::TCLAPCustomOutput());
 	cmd.setOutput(tclapOutput.get());
diff --git a/BaseLib/BuildInfo.cpp.in b/BaseLib/BuildInfo.cpp.in
index 2715eb783aa..4e6a624a38c 100644
--- a/BaseLib/BuildInfo.cpp.in
+++ b/BaseLib/BuildInfo.cpp.in
@@ -27,8 +27,8 @@ namespace BuildInfo
     const std::string git_version_sha1("@GIT_SHA1@");
     const std::string git_version_sha1_short("@GIT_SHA1_SHORT@");
 
+    const std::string git_describe("@GIT_DESCRIBE@");
     const std::string ogs_version("@OGS_VERSION@");
-    const std::string ogs_version_and_persons("@OGS_VERSION_AND_PERSONS@");
 
     const std::string source_path("@CMAKE_CURRENT_SOURCE_DIR@");
     const std::string tests_tmp_path("@PROJECT_BINARY_DIR@/Tests/");
diff --git a/BaseLib/BuildInfo.h b/BaseLib/BuildInfo.h
index bd398c28418..00bb4637e03 100644
--- a/BaseLib/BuildInfo.h
+++ b/BaseLib/BuildInfo.h
@@ -29,8 +29,8 @@ namespace BuildInfo
     extern const std::string git_version_sha1;
     extern const std::string git_version_sha1_short;
 
+    extern const std::string git_describe;
     extern const std::string ogs_version;
-    extern const std::string ogs_version_and_persons;
 
     extern const std::string source_path;
     extern const std::string tests_tmp_path;
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 06049bc26f8..48539dc9a6b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,19 +14,6 @@ ENDIF()
 # Project name
 PROJECT( OGS-6 )
 
-###########################################################################
-### OGS version information. Adjust these if you release a new version. ###
-###########################################################################
-SET (OGS_VERSION_MAJOR 6)
-SET (OGS_VERSION_MINOR 0)
-SET (OGS_VERSION_PATCH 0)
-SET (OSG_VERSION_STATUS "Beta") # Can be words like Alpha, Beta, Prerelease or ""
-SET (OGS_RELEASE_PERSONS "Core developers")
-SET (OGS_VERSION "${OGS_VERSION_MAJOR}.${OGS_VERSION_MINOR}.${OGS_VERSION_PATCH}")
-SET (OGS_VERSION_AND_PERSONS "${OGS_VERSION} ${OSG_VERSION_STATUS} (${OGS_RELEASE_PERSONS})")
-SET (OGS_DATE "2012-08-20")
-
-
 ###########################
 ### Preliminary Options ###
 ###########################
diff --git a/FileIO/GMSHInterface.cpp b/FileIO/GMSHInterface.cpp
index 988a6ada656..82546573aa6 100644
--- a/FileIO/GMSHInterface.cpp
+++ b/FileIO/GMSHInterface.cpp
@@ -200,7 +200,7 @@ void GMSHInterface::readNodeIDs(std::ifstream &in,
 }
 
 MeshLib::Element* GMSHInterface::readElement(std::ifstream &in, std::vector<MeshLib::Node*> const& nodes, std::map<unsigned, unsigned> const& id_map)
-{	
+{
 	unsigned idx, type, n_tags, dummy, mat_id;
 	std::vector<unsigned> node_ids;
 	std::vector<MeshLib::Node*> elem_nodes;
@@ -275,7 +275,7 @@ MeshLib::Element* GMSHInterface::readElement(std::ifstream &in, std::vector<Mesh
 
 bool GMSHInterface::write()
 {
-	_out << "// GMSH input file created by OpenGeoSys " << BaseLib::BuildInfo::ogs_version_and_persons;
+	_out << "// GMSH input file created by OpenGeoSys " << BaseLib::BuildInfo::git_describe;
 #ifdef BUILD_TIMESTAMP
 	_out << " built on " << BaseLib::BuildInfo::build_timestamp;
 #endif
diff --git a/scripts/cmake/CMakeSetup.cmake b/scripts/cmake/CMakeSetup.cmake
index 3704b5143ca..37c5ecee672 100644
--- a/scripts/cmake/CMakeSetup.cmake
+++ b/scripts/cmake/CMakeSetup.cmake
@@ -17,6 +17,19 @@ SET(NUM_PROCESSORS ${NUM_PROCESSORS} CACHE STRING "Processor count")
 INCLUDE(GetGitRevisionDescription)
 GET_GIT_HEAD_REVISION(GIT_REFSPEC GIT_SHA1)
 STRING(SUBSTRING ${GIT_SHA1} 0 8 GIT_SHA1_SHORT)
+GIT_GET_TAG(GIT_DESCRIBE)
+
+STRING(REGEX MATCH ^[0-9|\\.]* GIT_TAG ${GIT_DESCRIBE})
+SET(OGS_VERSION ${GIT_TAG})
+IF(GIT_DESCRIBE MATCHES ".*-.*-.*")
+	# Commit is not a tag
+	SET(OGS_IS_RELEASE FALSE)
+	STRING(REGEX MATCH "-([0-9]+)-" GIT_COMMITS_AFTER_TAG ${GIT_DESCRIBE})
+ELSE()
+	SET(OGS_VERSION_STATUS "")
+	SET(OGS_IS_RELEASE TRUE)
+	MESSAGE(STATUS "OGS version: ${OGS_VERSION}")
+ENDIF()
 
 # Get the hostname
 SITE_NAME(HOSTNAME)
diff --git a/scripts/cmake/cmake/GetGitRevisionDescription.cmake b/scripts/cmake/cmake/GetGitRevisionDescription.cmake
index c8d27f2e8ce..4da5f1d7f10 100644
--- a/scripts/cmake/cmake/GetGitRevisionDescription.cmake
+++ b/scripts/cmake/cmake/GetGitRevisionDescription.cmake
@@ -128,3 +128,8 @@ function(git_get_exact_tag _var)
 	git_describe(out --exact-match ${ARGN})
 	set(${_var} "${out}" PARENT_SCOPE)
 endfunction()
+
+function(git_get_tag _var)
+	git_describe(out --tags ${ARGN})
+	set(${_var} "${out}" PARENT_SCOPE)
+endfunction()
diff --git a/scripts/cmake/packaging/Pack.cmake b/scripts/cmake/packaging/Pack.cmake
index 96256c584a0..3b4cff42914 100644
--- a/scripts/cmake/packaging/Pack.cmake
+++ b/scripts/cmake/packaging/Pack.cmake
@@ -12,10 +12,10 @@ SET(CPACK_PACKAGE_VERSION_MAJOR "${OGS_VERSION_MAJOR}")
 SET(CPACK_PACKAGE_VERSION_MINOR "${OGS_VERSION_MINOR}")
 SET(CPACK_PACKAGE_VERSION_PATCH "${OGS_VERSION_PATCH}")
 IF(APPLE)
-	SET(CPACK_PACKAGE_FILE_NAME "ogs-${OGS_VERSION}-OSX-${OSX_VERSION}-x${BITS}")
+	SET(CPACK_PACKAGE_FILE_NAME "ogs-${GIT_DESCRIBE}-OSX-${OSX_VERSION}-x${BITS}")
 	SET(CPACK_SOURCE_PACKAGE_FILE_NAME ${CPACK_PACKAGE_FILE_NAME})
 ELSE()
-	SET(CPACK_PACKAGE_FILE_NAME "ogs-${OGS_VERSION}-${CMAKE_SYSTEM}-x${BITS}")
+	SET(CPACK_PACKAGE_FILE_NAME "ogs-${GIT_DESCRIBE}-${CMAKE_SYSTEM}-x${BITS}")
 ENDIF()
 
 #SET(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
-- 
GitLab