From 2f8953ec6d3febfddf9a2f77c2c53a71cfc4b5e5 2017-05-16 07:59:29 From: mperrinel Date: 2017-05-16 07:59:29 Subject: [PATCH] Ajout de la version --- diff --git a/sqpcore/resources/Version.cpp.in b/sqpcore/resources/Version.cpp.in new file mode 100644 index 0000000..2a27649 --- /dev/null +++ b/sqpcore/resources/Version.cpp.in @@ -0,0 +1,78 @@ +#include "Version.h" + +/*************************************************** + * @SCIQLOP_CMAKE_GENERATION_WARNING@ * + ***************************************************/ + +#include +#include + +namespace sciqlop { + +const char *Version::VERSION_SUFFIX = "@SCIQLOP_VERSION_SUFFIX@"; + +/** + * From the C99 standard: + * __DATE__: The date of translation of the preprocessing translation unit: + * a character string literal of the form "Mmm dd yyyy", where the names of + * the months are the same as those generated by the asctime function, and + * the first character of dd is a space character if the value is less than + * 10. If the date of translation is not available, an + * implementation-defined valid date shall be supplied. + */ +const char *Version::BUILD_DATE = __DATE__; +/** + * From the C99 standard: + * __TIME__: The time of translation of the preprocessing translation unit: + * a character string literal of the form "hh:mm:ss" as in the time + * generated by the asctime function. If the time of translation is not + * available, an implementation-defined valid time shall be supplied. + */ +const char *Version::BUILD_TIME = __TIME__; + +QDateTime Version::buildDateTime() +{ + static QDateTime buildDateTime; + if (!buildDateTime.isValid()) { + // Convert BUILD_DATE to a QDate + // The __DATE__ macro return the month name with the asctime() function, + // which doesn't support localization, the month names returned are + // always the same. On the contrary, the "MMM" format on + // QDate::fromString() is localized, so this method can't be used to + // retrieve the month and we must manually do it instead. + QString buildDateStr = QString(BUILD_DATE); + QString buildMonthStr = buildDateStr.left(3); + QString buildDayAndYearStr = buildDateStr.mid(4).trimmed(); + + QDate buildDate = QDate::fromString(buildDayAndYearStr, "d yyyy"); + QStringList monthList = QStringList() << "Jan" + << "Feb" + << "Mar" + << "Apr" + << "May" + << "Jun" + << "Jul" + << "Aug" + << "Sep" + << "Oct" + << "Nov" + << "Dec"; + for (int i = 0; i < monthList.size(); ++i) { + if (buildMonthStr == monthList.at(i)) { + buildDate.setDate(buildDate.year(), i + 1, buildDate.day()); + break; + } + } + + // Convert BUILD_TIME to a QTime + QTime buildTime = QTime::fromString(BUILD_TIME, "hh:mm:ss"); + + // Set the buildDateTime + buildDateTime.setDate(buildDate); + buildDateTime.setTime(buildTime); + } + + return buildDateTime; +} + +} // namespace sciqlop diff --git a/sqpcore/resources/Version.h.in b/sqpcore/resources/Version.h.in new file mode 100644 index 0000000..cf7a260 --- /dev/null +++ b/sqpcore/resources/Version.h.in @@ -0,0 +1,98 @@ +// TODO copyright +/** + * @file Version.h + */ +#ifndef SCIQLOP_VERSION_H +#define SCIQLOP_VERSION_H + +/*************************************************** + * @SCIQLOP_CMAKE_GENERATION_WARNING@ * + ***************************************************/ + +//#include "SciqlopExport.h" +#include + +class QDateTime; + +namespace sciqlop { + +/** + * Holds the version of Sciqlop. + * + * @attention Don't update this class directly, it is generated from the + * `resources/Version.h.in` and `resources/Version.cpp.in` files, along with + * the cmake variables defined in the `cmake/sciqlop_version.cmake` file. + * + * To change the Sciqlop version number, update the `cmake/sciqlop_version.cmake` + * file, and to change this class other than to change the version number, + * update the `resources/Version.h.in` and `resources/Version.cpp.in` files. + * @ingroup Utils + */ +class /*SCIQLOP_API*/ Version { +public: + /** + * Retrieve the version of Sciqlop. + * + * The version is of the form MAJOR.MINOR.PATCH. If a suffix has been + * provided to the version, it is appended after the PATCH. + * + * The version can be modified by updating the cmake/sciqlop_version.cmake + * file. + * + * @return The version of Sciqlop as a QString. + */ + static QString version() + { + static const QString v("@SCIQLOP_VERSION@"); + return v; + } + + /** + * @return The datetime of the build. + */ + static QDateTime buildDateTime(); + + /** + * Major version. + */ + static const int VERSION_MAJOR = @SCIQLOP_VERSION_MAJOR@; + /** + * Minor version. + */ + static const int VERSION_MINOR = @SCIQLOP_VERSION_MINOR@; + /** + * Patch version. + */ + static const int VERSION_PATCH = @SCIQLOP_VERSION_PATCH@; + /** + * Suffix version. + */ + static const char *VERSION_SUFFIX; + + /** + * Compile date computed with the __DATE__ macro. + * + * From the C99 standard: + * __DATE__: The date of translation of the preprocessing translation unit: + * a character string literal of the form "Mmm dd yyyy", where the names of + * the months are the same as those generated by the asctime function, and + * the first character of dd is a space character if the value is less than + * 10. If the date of translation is not available, an + * implementation-defined valid date shall be supplied. + */ + static const char *BUILD_DATE; + /** + * Compile time computed with the __TIME__ macro. + * + * From the C99 standard: + * __TIME__: The time of translation of the preprocessing translation unit: + * a character string literal of the form "hh:mm:ss" as in the time + * generated by the asctime function. If the time of translation is not + * available, an implementation-defined valid time shall be supplied. + */ + static const char *BUILD_TIME; +}; + +} // namespace sciqlop + +#endif // SCIQLOP_VERSION_H