Add "ExtraVersion" version number information.

The "ExtraVersion" can be used for things like Git commit Id,
release tag (version control), release date etc. If the string
is empty, nothing is printed.
This commit is contained in:
Kimmo Varis 2011-08-11 17:34:59 +03:00
parent 04d4215116
commit 9e2dd553fb
3 changed files with 24 additions and 2 deletions

View File

@ -24,6 +24,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <cstdlib> // EXIT_SUCCESS and EXIT_FAILURE #include <cstdlib> // EXIT_SUCCESS and EXIT_FAILURE
#include <cstring>
#include "cmdlineparser.h" #include "cmdlineparser.h"
#include "filelister.h" #include "filelister.h"
#include "path.h" #include "path.h"
@ -50,7 +51,12 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
{ {
if (parser.GetShowVersion() && !parser.GetShowErrorMessages()) if (parser.GetShowVersion() && !parser.GetShowErrorMessages())
{ {
std::cout << "Cppcheck " << cppcheck->version() << std::endl; const char * extraVersion = cppcheck->extraVersion();
if (strlen(extraVersion) > 0)
std::cout << "Cppcheck " << cppcheck->version() << " ("
<< extraVersion << ")" << std::endl;
else
std::cout << "Cppcheck " << cppcheck->version() << std::endl;
} }
if (parser.GetShowErrorMessages()) if (parser.GetShowErrorMessages())

View File

@ -35,6 +35,9 @@
#include <pcre.h> #include <pcre.h>
#endif #endif
static const char Version[] = "1.49";
static const char ExtraVersion[] = "";
static TimerResults S_timerResults; static TimerResults S_timerResults;
CppCheck::CppCheck(ErrorLogger &errorLogger, bool useGlobalSuppressions) CppCheck::CppCheck(ErrorLogger &errorLogger, bool useGlobalSuppressions)
@ -56,7 +59,12 @@ void CppCheck::settings(const Settings &currentSettings)
const char * CppCheck::version() const char * CppCheck::version()
{ {
return "1.49"; return Version;
}
const char * CppCheck::extraVersion()
{
return ExtraVersion;
} }
unsigned int CppCheck::check(const std::string &path) unsigned int CppCheck::check(const std::string &path)

View File

@ -105,6 +105,14 @@ public:
*/ */
static const char * version(); static const char * version();
/**
* @brief Returns extra version info as a string.
* This is for returning extra version info, like Git commit id, build
* time/date etc.
* @return extra version info, e.g. "04d42151" (Git commit id).
*/
static const char * extraVersion();
virtual void reportStatus(unsigned int fileindex, unsigned int filecount, long sizedone, long sizetotal); virtual void reportStatus(unsigned int fileindex, unsigned int filecount, long sizedone, long sizetotal);
/** /**