Added the --version switch;

The project now embeds the git sha1 of the source it's built from (this implies a cmake regen of wordref if the current sha1 changes)
This commit is contained in:
King_DuckZ 2013-08-22 12:07:38 +02:00
parent b213cacd50
commit f307656bda
4 changed files with 32 additions and 0 deletions

View file

@ -10,6 +10,7 @@ set_property (GLOBAL PROPERTY DEBUG_CONFIGURATIONS "Debug;Release")
project (WordReference CXX) project (WordReference CXX)
message(STATUS "Configuring ${PROJECT_NAME} for ${CMAKE_BUILD_TYPE}") message(STATUS "Configuring ${PROJECT_NAME} for ${CMAKE_BUILD_TYPE}")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/includes/")
add_definitions("-DUNICODE") add_definitions("-DUNICODE")
set (${PROJECT_NAME}_Version_Major 0) set (${PROJECT_NAME}_Version_Major 0)

View file

@ -1,11 +1,24 @@
project (wordreference CXX) 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(CURL REQUIRED)
find_package(Boost 1.32.0 REQUIRED program_options) find_package(Boost 1.32.0 REQUIRED program_options)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DJSON_DEBUG") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DJSON_DEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") 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 include_directories(SYSTEM
${CURL_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
@ -13,6 +26,7 @@ include_directories(SYSTEM
include_directories( include_directories(
src/ src/
../libjson/ ../libjson/
${PROJECT_BINARY_DIR}
) )
link_directories( link_directories(
${Boost_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS}

10
wordref/cmake_gen.h.in Normal file
View file

@ -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

View file

@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "main.hpp" #include "main.hpp"
#include "WordReference.hpp" #include "WordReference.hpp"
#include "CharConv.hpp" #include "CharConv.hpp"
#include "cmake_gen.h"
#include <iostream> #include <iostream>
#include <boost/program_options/cmdline.hpp> #include <boost/program_options/cmdline.hpp>
#include <boost/program_options/variables_map.hpp> #include <boost/program_options/variables_map.hpp>
@ -66,6 +67,7 @@ namespace {
desc.add_options() desc.add_options()
("help,h", "show this help screen") ("help,h", "show this help screen")
("listlanguages,l", "list available languages with their codes") ("listlanguages,l", "list available languages with their codes")
("version,v", "show the version of th program and exit")
; ;
boost::program_options::options_description commandLine; boost::program_options::options_description commandLine;
@ -78,6 +80,11 @@ namespace {
std::cout << desc << "\n"; std::cout << desc << "\n";
shownSomething = true; 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; return shownSomething;
} }
} //unnamed namespace } //unnamed namespace