From 5b4080b2f4d4b6980a5fa49582a837d90ea13bd7 Mon Sep 17 00:00:00 2001
From: Adam Radziszewski <adam.radziszewski@pwr.wroc.pl>
Date: Thu, 15 Sep 2011 13:21:56 +0200
Subject: [PATCH] version passed down to utils

---
 CMakeLists.txt              | 10 +++++-----
 libwccl/CMakeLists.txt      |  6 ++++--
 libwccl/version.in          |  9 +++++++++
 wccl-apps/CMakeLists.txt    |  1 +
 wccl-apps/wccl-features.cpp |  9 +++++++++
 wccl-apps/wccl-parser.cpp   |  9 +++++++++
 wccl-apps/wccl-rules.cpp    |  9 +++++++++
 wccl-apps/wccl-run.cpp      |  9 +++++++++
 8 files changed, 55 insertions(+), 7 deletions(-)
 create mode 100644 libwccl/version.in

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fee6e6c..020717a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,9 +1,11 @@
 PROJECT(WCCL)
 cmake_minimum_required(VERSION 2.8.0)
 
-set(ver_major "0")
-set(ver_minor "0")
-set(ver_patch "4")
+set(wccl_ver_major "0")
+set(wccl_ver_minor "1")
+set(wccl_ver_patch "1")
+
+set(LIBWCCL_VERSION "${wccl_ver_major}.${wccl_ver_minor}.${wccl_ver_patch}")
 
 # use some of our own Find* scripts
 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeScripts)
@@ -47,8 +49,6 @@ endif(CMAKE_COMPILER_IS_GNUCXX)
 set(LIBS "")
 include_directories(${WCCL_SOURCE_DIR})
 
-set(LIBWCCL_VERSION "${ver_major}.${ver_minor}.${ver_patch}")
-
 find_package(Boost 1.41 REQUIRED COMPONENTS program_options system filesystem regex)
 
 if(MSVC OR BORLAND)
diff --git a/libwccl/CMakeLists.txt b/libwccl/CMakeLists.txt
index a763a8f..bae27de 100644
--- a/libwccl/CMakeLists.txt
+++ b/libwccl/CMakeLists.txt
@@ -2,7 +2,9 @@
 
 PROJECT(wccl)
 
+configure_file(version.in include/libwccl/version.h)
 include_directories( ${CMAKE_CURRENT_BINARY_DIR}/include/ )
+add_definitions(-DHAVE_VERSION_H)
 
 find_package(Corpus2 1.0.12 REQUIRED)
 set(LIBS ${LIBS} ${Corpus2_LIBRARIES})
@@ -159,8 +161,8 @@ endif(WIN32)
 target_link_libraries ( wccl ${LIBS})
 
 set_target_properties(wccl PROPERTIES
-	VERSION "${ver_major}.${ver_minor}"
-	SOVERSION ${ver_major})
+	VERSION "${wccl_ver_major}.${wccl_ver_minor}"
+	SOVERSION ${wccl_ver_major})
 
 
 if(UNIX)
diff --git a/libwccl/version.in b/libwccl/version.in
new file mode 100644
index 0000000..51488ed
--- /dev/null
+++ b/libwccl/version.in
@@ -0,0 +1,9 @@
+#ifndef LIBWCCL_VERSION_H
+#define LIBWCCL_VERSION_H
+
+#define LIBWCCL_VERSION_MAJOR @wccl_ver_major@
+#define LIBWCCL_VERSION_MINOR @wccl_ver_minor@
+#define LIBWCCL_VERSION_PATCH @wccl_ver_patch@
+#define LIBWCCL_VERSION "@LIBWCCL_VERSION@"
+
+#endif
diff --git a/wccl-apps/CMakeLists.txt b/wccl-apps/CMakeLists.txt
index 9122f0f..85550bf 100644
--- a/wccl-apps/CMakeLists.txt
+++ b/wccl-apps/CMakeLists.txt
@@ -16,6 +16,7 @@ find_package(Loki REQUIRED QUIET)
 set(LIBS ${LIBS} loki)
 
 include_directories(${CMAKE_SOURCE_DIR})
+include_directories(${wccl_BINARY_DIR}/include)
 include_directories(${Boost_INCLUDE_DIR})
 link_directories(${Boost_LIBRARY_DIRS})
 
diff --git a/wccl-apps/wccl-features.cpp b/wccl-apps/wccl-features.cpp
index c1e8641..7bf41eb 100644
--- a/wccl-apps/wccl-features.cpp
+++ b/wccl-apps/wccl-features.cpp
@@ -11,6 +11,9 @@
 #include <libwccl/values/tset.h>
 #include <libwccl/values/strset.h>
 
+// not checking for HAVE_VERSION..., no reason for its absence
+#include <libwccl/version.h>
+
 #include <boost/bind.hpp>
 #include <boost/algorithm/string.hpp>
 #include <boost/make_shared.hpp>
@@ -444,6 +447,7 @@ int main(int argc, char** argv)
 			("output-header,H", value(&output_header),
 			 "Output table header")
 			("help,h", "Show help")
+			("version", "print version string")
 			;
 	boost::program_options::variables_map vm;
 	boost::program_options::positional_options_description p;
@@ -468,6 +472,11 @@ int main(int argc, char** argv)
 		return 1;
 	}
 
+	if (vm.count("version")) {
+		std::cout << "wccl-features (libwccl) " << LIBWCCL_VERSION << "\n";
+		return 0;
+	}
+
 	foreach (const std::string& f, files) {
 		if (f == "-") {
 			corpus_stdin = true;
diff --git a/wccl-apps/wccl-parser.cpp b/wccl-apps/wccl-parser.cpp
index 1251246..39867f1 100644
--- a/wccl-apps/wccl-parser.cpp
+++ b/wccl-apps/wccl-parser.cpp
@@ -7,6 +7,9 @@
 #include <libwccl/parser/Parser.h>
 #include <libcorpus2/tagsetmanager.h>
 
+// not checking for HAVE_VERSION..., no reason for its absence
+#include <libwccl/version.h>
+
 #include <boost/bind.hpp>
 #include <boost/make_shared.hpp>
 #include <boost/program_options.hpp>
@@ -246,6 +249,7 @@ int main(int argc, char** argv)
 			("variables,V", value(&dump_variables)->zero_tokens(),
 			 "Dump variables after running each query\n")
 			("help,h", "Show help")
+			("version", "print version string")
 			;
 	boost::program_options::variables_map vm;
 	boost::program_options::positional_options_description p;
@@ -266,6 +270,11 @@ int main(int argc, char** argv)
 		return 1;
 	}
 
+	if (vm.count("version")) {
+		std::cout << "wccl-parser (libwccl) " << LIBWCCL_VERSION << "\n";
+		return 0;
+	}
+
 	try {
 		const Corpus2::Tagset& tagset = Corpus2::get_named_tagset(tagset_load);
 		boost::shared_ptr<Corpus2::Sentence> sentence;
diff --git a/wccl-apps/wccl-rules.cpp b/wccl-apps/wccl-rules.cpp
index 758f7d9..327fec4 100644
--- a/wccl-apps/wccl-rules.cpp
+++ b/wccl-apps/wccl-rules.cpp
@@ -15,6 +15,9 @@
 #include <libcorpus2/io/reader.h>
 #include <libcorpus2/io/writer.h>
 
+// not checking for HAVE_VERSION..., no reason for its absence
+#include <libwccl/version.h>
+
 namespace {
 	bool quiet = false;
 
@@ -206,6 +209,7 @@ int main(int argc, char** argv)
 			("first-sentence-only,1", value(&opts.first)->zero_tokens(),
 			 "Only process first sentence\n")
 			("help,h", "Show help")
+			("version", "print version string")
 			;
 	boost::program_options::variables_map vm;
 	boost::program_options::positional_options_description p;
@@ -227,6 +231,11 @@ int main(int argc, char** argv)
 		return 1;
 	}
 
+	if (vm.count("version")) {
+		std::cout << "wccl-rules (libwccl) " << LIBWCCL_VERSION << "\n";
+		return 0;
+	}
+
 	foreach (const std::string& f, files) {
 		if (f == "-") {
 			corpus_stdin = true;
diff --git a/wccl-apps/wccl-run.cpp b/wccl-apps/wccl-run.cpp
index 3fa18fb..0fde1e5 100644
--- a/wccl-apps/wccl-run.cpp
+++ b/wccl-apps/wccl-run.cpp
@@ -20,6 +20,9 @@
 #include <antlr/NoViableAltException.hpp>
 #include <antlr/MismatchedTokenException.hpp>
 
+// not checking for HAVE_VERSION..., no reason for its absence
+#include <libwccl/version.h>
+
 namespace {
 	bool quiet = false;
 	bool tabs = false;
@@ -390,6 +393,7 @@ int main(int argc, char** argv)
 			("progress,p", value(&progress)->zero_tokens(),
 			 "Show progress info")
 			("help,h", "Show help")
+			("version", "print version string")
 			;
 	boost::program_options::variables_map vm;
 	boost::program_options::positional_options_description p;
@@ -414,6 +418,11 @@ int main(int argc, char** argv)
 		return 1;
 	}
 
+	if (vm.count("version")) {
+		std::cout << "wccl-run (libwccl) " << LIBWCCL_VERSION << "\n";
+		return 0;
+	}
+
 	foreach (const std::string& f, files) {
 		if (f == "-") {
 			corpus_stdin = true;
-- 
GitLab