diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9f29ce3..6358858 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -10,6 +10,7 @@ set_property (GLOBAL PROPERTY DEBUG_CONFIGURATIONS "Debug;Release")
project (WordReference CXX)
message(STATUS "Configuring ${PROJECT_NAME} for ${CMAKE_BUILD_TYPE}")
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/includes/")
add_definitions("-DUNICODE")
set (${PROJECT_NAME}_Version_Major 0)
diff --git a/wordref/CMakeLists.txt b/wordref/CMakeLists.txt
index e6dfa82..fa04683 100644
--- a/wordref/CMakeLists.txt
+++ b/wordref/CMakeLists.txt
@@ -1,11 +1,24 @@
project (wordreference CXX)
+# http://stackoverflow.com/questions/1435953/how-can-i-pass-git-sha1-to-compiler-as-definition-using-cmake
+include(GetGitRevisionDescription)
+
find_package(CURL REQUIRED)
find_package(Boost 1.32.0 REQUIRED program_options)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DJSON_DEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
+set(PROJ_VER_MAJOR "0")
+set(PROJ_VER_MINOR "1")
+set(PROJ_VER_REVISION "1")
+get_git_head_revision(GIT_REFSPEC PROJ_GIT_SHA1)
+
+configure_file (
+ ${PROJECT_SOURCE_DIR}/cmake_gen.h.in
+ ${PROJECT_BINARY_DIR}/cmake_gen.h
+)
+
include_directories(SYSTEM
${CURL_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
@@ -13,6 +26,7 @@ include_directories(SYSTEM
include_directories(
src/
../libjson/
+ ${PROJECT_BINARY_DIR}
)
link_directories(
${Boost_LIBRARY_DIRS}
diff --git a/wordref/cmake_gen.h.in b/wordref/cmake_gen.h.in
new file mode 100644
index 0000000..15bbd61
--- /dev/null
+++ b/wordref/cmake_gen.h.in
@@ -0,0 +1,10 @@
+#ifndef id21852921F3D842438F1282E46979CCB2
+#define id21852921F3D842438F1282E46979CCB2
+
+#define APP_NAME "@PROJECT_NAME@"
+#define APP_VER_MAJOR @PROJ_VER_MAJOR@
+#define APP_VER_MINOR @PROJ_VER_MINOR@
+#define APP_VER_REVISION @PROJ_VER_REVISION@
+#define APP_VER_GIT "@PROJ_GIT_SHA1@"
+
+#endif
diff --git a/wordref/src/main.cpp b/wordref/src/main.cpp
index 7f9a457..6178690 100644
--- a/wordref/src/main.cpp
+++ b/wordref/src/main.cpp
@@ -19,6 +19,7 @@ along with this program. If not, see .
#include "main.hpp"
#include "WordReference.hpp"
#include "CharConv.hpp"
+#include "cmake_gen.h"
#include
#include
#include
@@ -66,6 +67,7 @@ namespace {
desc.add_options()
("help,h", "show this help screen")
("listlanguages,l", "list available languages with their codes")
+ ("version,v", "show the version of th program and exit")
;
boost::program_options::options_description commandLine;
@@ -78,6 +80,11 @@ namespace {
std::cout << desc << "\n";
shownSomething = true;
}
+ else if (parVarMap.count("version")) {
+ std::cout << APP_NAME << " v" << APP_VER_MAJOR << "." << APP_VER_MINOR << "." << APP_VER_REVISION << "\n";
+ std::cout << "rev: " << APP_VER_GIT << "\n";
+ shownSomething = true;
+ }
return shownSomething;
}
} //unnamed namespace