diff --git a/lib/git.pri b/lib/git.pri new file mode 100644 index 0000000..a0664ee --- /dev/null +++ b/lib/git.pri @@ -0,0 +1,15 @@ +# Need to discard STDERR so get path to NULL device +win32 { + NULL_DEVICE = NUL # Windows doesn't have /dev/null but has NUL +} else { + NULL_DEVICE = /dev/null +} + +# Need to call git with manually specified paths to repository +BASE_GIT_COMMAND = git --git-dir $$PWD/../.git rev-parse --short HEAD + +# Get the short git sha +GIT_SHA = $$system($$BASE_GIT_COMMAND 2> $$NULL_DEVICE) + +# Adding C preprocessor #DEFINE so we can use it in C++ code +DEFINES += GIT_SHA=\\\"$$GIT_SHA\\\" diff --git a/lib/version.h b/lib/version.h new file mode 100644 index 0000000..48b8c03 --- /dev/null +++ b/lib/version.h @@ -0,0 +1,43 @@ +/* + This file is part of Allie Chess. + Copyright (C) 2018, 2019 Adam Treat + + Allie Chess is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Allie Chess is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Allie Chess. If not, see . + + Additional permission under GNU GPL version 3 section 7 +*/ + +#ifndef VERSION_H +#define VERSION_H + +#include + +static int s_majorVersion = 0; +static int s_minorVersion = 2; +static bool s_isDev = true; + +static QString versionString() +{ + const QString maj = QString::number(s_majorVersion); + const QString min = QString::number(s_minorVersion); +#if defined(GIT_SHA) + const QString git = QString("(%0)").arg(GIT_SHA); +#else + const QString git = QString(); +#endif + const QString dev = s_isDev ? QLatin1String("-dev") : QLatin1String(""); + return QString("v%0.%1%2 %3").arg(maj).arg(min).arg(dev).arg(git); +} + +#endif // VERSION_H diff --git a/src/main.cpp b/src/main.cpp index be4519c..4f6bc99 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,10 +30,10 @@ #include "options.h" #include "searchengine.h" #include "uciengine.h" +#include "version.h" #include "zobrist.h" #define APP_NAME "Allie" -#define APP_VERSION "0.2" int main(int argc, char *argv[]) { @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) QCoreApplication a(argc, argv); a.setApplicationName(APP_NAME); - a.setApplicationVersion(APP_VERSION); + a.setApplicationVersion(versionString()); a.setOrganizationName("Adam Treat"); QCommandLineParser parser; @@ -75,7 +75,10 @@ int main(int argc, char *argv[]) " / _` | | | |/ _ \\\n" "| (_| | | | | __/ \n" " \\__,_|_|_|_|\\___|"); - fprintf(stderr, "%s %s uci chess engine\n", ascii.toLatin1().constData(), APP_VERSION); + fprintf(stderr, "%s %s built on %s at %s\n", ascii.toLatin1().constData(), + QString("%0").arg(a.applicationVersion()).toLatin1().constData(), + QString("%0").arg(__DATE__).toLatin1().constData(), + QString("%0").arg(__TIME__).toLatin1().constData()); Zobrist::globalInstance(); Movegen::globalInstance(); diff --git a/src/src.pro b/src/src.pro index be537c6..8ca2bfa 100644 --- a/src/src.pro +++ b/src/src.pro @@ -6,6 +6,8 @@ DESTDIR=../bin QT -= gui network CONFIG += c++14 console +include($$PWD/../lib/git.pri) + CONFIG(release, debug|release) { CONFIG += optimize_full } @@ -18,6 +20,9 @@ DEFINES += QT_DEPRECATED_WARNINGS INCLUDEPATH += $$PWD/../lib +HEADERS += \ + $$PWD/../lib/version.h + SOURCES += \ main.cpp diff --git a/tests/main.cpp b/tests/main.cpp index 8ea6059..1dc2be1 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -26,16 +26,19 @@ #include "nn.h" #include "options.h" #include "testgames.h" +#include "version.h" #include "zobrist.h" -#define APP_NAME "Allie" +#define APP_NAME "AllieTests" int main(int argc, char* argv[]) { - QCoreApplication app(argc, argv); - app.setApplicationName(APP_NAME); + QCoreApplication a(argc, argv); + a.setApplicationName(APP_NAME); + a.setApplicationVersion(versionString()); - Options::globalInstance()->setOption("SyzygyPath", QCoreApplication::applicationDirPath() + QDir::separator() + "../../syzygy/"); + Options::globalInstance()->setOption("SyzygyPath", + QCoreApplication::applicationDirPath() + QDir::separator() + "../../syzygy/"); int rc = 0; TestGames test1; diff --git a/tests/tests.pro b/tests/tests.pro index efce742..dc8f449 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -7,6 +7,8 @@ QT += testlib QT -= gui network CONFIG += c++14 console +include($$PWD/../lib/git.pri) + CONFIG(release, debug|release) { CONFIG += optimize_full } @@ -21,6 +23,7 @@ INCLUDEPATH += $$PWD/../lib HEADERS += \ testgames.h + $$PWD/../lib/version.h SOURCES += \ main.cpp \