summaryrefslogtreecommitdiffstats
path: root/libversion/gitversion.cpp.in
blob: 242dd59e23761ec532925e1ce844c866855e1cf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <string.h>
#include <version.h>

/* - On some systems git is not installed or
 *   installed on a place where FindGit.cmake cannot find it
 * - No git information is present (no .git directory)
 * in those cases clear the gitVersionString (would have string GIT-NOTFOUND).
 */
const char *getGitVersion(void)
{
#define BUF_SIZE 100
  static char gitVersionString[BUF_SIZE];
  static bool init = false;
  if (!init)
  {
    strncpy(gitVersionString,"@GIT_HEAD_SHA1@",BUF_SIZE-1);
    strncat(gitVersionString,!strcmp("@GIT_IS_DIRTY@","true")?"*":"",BUF_SIZE-1);
    if (!strcmp("@GIT_HEAD_SHA1@", "GIT-NOTFOUND")) gitVersionString[0] = '\0';
    gitVersionString[BUF_SIZE-1]='\0';
    init = true;
  }
  return gitVersionString;
}