Added spectrum2 --version + handle SPECTRUM_VERSION cmake variable

This commit is contained in:
Jan Kaluza 2011-11-16 09:39:29 +01:00
parent ee674bfe6b
commit 29b5b7d27f
2 changed files with 25 additions and 2 deletions

View file

@ -64,6 +64,25 @@ ADD_DEFINITIONS(-DBOOST_FILESYSTEM_VERSION=2)
message(" Supported features")
message("-----------------------")
if (SPECTRUM_VERSION)
ADD_DEFINITIONS(-DSPECTRUM_VERSION="${SPECTRUM_VERSION}")
else (SPECTRUM_VERSION)
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
execute_process(COMMAND git "--git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git" rev-parse --short HEAD
OUTPUT_VARIABLE GIT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(SPECTRUM_VERSION 2.0.0-beta-git-${GIT_REVISION})
ADD_DEFINITIONS(-DSPECTRUM_VERSION="${SPECTRUM_VERSION}")
else (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
set(SPECTRUM_VERSION 2.0.0-alpha)
ADD_DEFINITIONS(-DSPECTRUM_VERSION="${SPECTRUM_VERSION}")
endif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
endif (SPECTRUM_VERSION)
message("Version : " ${SPECTRUM_VERSION})
if (SQLITE3_FOUND)
ADD_DEFINITIONS(-DWITH_SQLITE)
include_directories(${SQLITE3_INCLUDE_DIR})

View file

@ -138,13 +138,14 @@ int main(int argc, char **argv)
return -1;
}
#endif
boost::program_options::options_description desc("Usage: spectrum [OPTIONS] <config_file.cfg>\nAllowed options");
boost::program_options::options_description desc(std::string("Spectrum version: ") + SPECTRUM_VERSION + "\nUsage: spectrum [OPTIONS] <config_file.cfg>\nAllowed options");
desc.add_options()
("help,h", "help")
("no-daemonize,n", "Do not run spectrum as daemon")
("no-debug,d", "Create coredumps on crash")
("jid,j", boost::program_options::value<std::string>(&jid)->default_value(""), "Specify JID of transport manually")
("config", boost::program_options::value<std::string>(&config_file)->default_value(""), "Config file")
("version,v", "Shows Spectrum version")
;
try
{
@ -154,7 +155,10 @@ int main(int argc, char **argv)
options(desc).positional(p).run(), vm);
boost::program_options::notify(vm);
if (vm.count("version")) {
std::cout << SPECTRUM_VERSION << "\n";
return 0;
}
if(vm.count("help"))
{