Introduce build config template buildconfig.h.in

refs #625
This commit is contained in:
Roland Winklmeier
2016-03-31 17:12:01 +02:00
parent 4e9c34b04a
commit d379f14133
45 changed files with 279 additions and 317 deletions

View File

@@ -8,7 +8,7 @@
*/
#include "audioutils.h"
#include "blackmisc/project.h"
#include "blackmisc/buildconfig.h"
#include <QProcess>
namespace BlackMisc
@@ -17,7 +17,7 @@ namespace BlackMisc
{
bool startWindowsMixer()
{
if (!CProject::isRunningOnWindowsNtPlatform()) { return false; }
if (!CBuildConfig::isRunningOnWindowsNtPlatform()) { return false; }
QStringList parameterlist;
return QProcess::startDetached("SndVol.exe", parameterlist);
}

View File

@@ -10,6 +10,10 @@ contains(BLACK_CONFIG, Static) {
CONFIG += staticlib
}
buildconfig.input = buildconfig.h.in
buildconfig.output = buildconfig.h
QMAKE_SUBSTITUTES += buildconfig
INCLUDEPATH += ..
# DEPENDPATH += . .. // BlackMisc should be independent
# PRECOMPILED_HEADER = stdpch.h
@@ -65,7 +69,7 @@ win32 {
DESTDIR = $$DestRoot/lib
DLLDESTDIR = $$DestRoot/bin
OTHER_FILES += $$TRANSLATIONS readme.txt
OTHER_FILES += $$TRANSLATIONS readme.txt buildconfig.h.in
win32 {
dlltarget.path = $$PREFIX/bin

View File

@@ -38,16 +38,4 @@
# define BLACKMISC_EXPORT_TEMPLATE
#endif
//! \cond
// helper define
#define BLACK_STRINGIFY_X(v) #v
//! \endcond
/*!
* \def BLACK_STRINGIFY
* Value in quotes (normally to be used then with QString)
*/
#define BLACK_STRINGIFY(v) BLACK_STRINGIFY_X(v)
#endif // guard

View File

@@ -9,7 +9,7 @@
//! \cond PRIVATE
#include "project.h"
#include "buildconfig.h"
#include "blackmisc/fileutils.h"
#include "blackmisc/stringutils.h"
#include "blackmisc/simulation/simulatorinfo.h"
@@ -19,17 +19,9 @@
#include <QProcessEnvironment>
#include <QStandardPaths>
#if !defined(BLACK_VERSION)
#error Missing version
#endif
#if !defined(BLACK_EOL)
#error Missing EOL
#endif
namespace BlackMisc
{
bool CProject::isCompiledWithBlackCore()
bool CBuildConfig::isCompiledWithBlackCore()
{
#ifdef WITH_BLACKCORE
return true;
@@ -38,7 +30,7 @@ namespace BlackMisc
#endif
}
bool CProject::isCompiledWithBlackSound()
bool CBuildConfig::isCompiledWithBlackSound()
{
#ifdef WITH_BLACKSOUND
return true;
@@ -47,7 +39,7 @@ namespace BlackMisc
#endif
}
bool CProject::isCompiledWithBlackInput()
bool CBuildConfig::isCompiledWithBlackInput()
{
#ifdef WITH_BLACKINPUT
return true;
@@ -56,7 +48,7 @@ namespace BlackMisc
#endif
}
bool CProject::isCompiledWithFs9Support()
bool CBuildConfig::isCompiledWithFs9Support()
{
#ifdef WITH_FS9
return true;
@@ -65,7 +57,7 @@ namespace BlackMisc
#endif
}
bool CProject::isCompiledWithFsxSupport()
bool CBuildConfig::isCompiledWithFsxSupport()
{
#ifdef WITH_FSX
return true;
@@ -74,17 +66,17 @@ namespace BlackMisc
#endif
}
bool CProject::isCompiledWithP3DSupport()
bool CBuildConfig::isCompiledWithP3DSupport()
{
return isCompiledWithFsxSupport();
}
bool CProject::isCompiledWithMsFlightSimulatorSupport()
bool CBuildConfig::isCompiledWithMsFlightSimulatorSupport()
{
return isCompiledWithFs9Support() || isCompiledWithFsxSupport() || isCompiledWithP3DSupport();
}
bool CProject::isCompiledWithXPlaneSupport()
bool CBuildConfig::isCompiledWithXPlaneSupport()
{
#ifdef WITH_XPLANE
return true;
@@ -93,12 +85,12 @@ namespace BlackMisc
#endif
}
bool CProject::isCompiledWithFlightSimulatorSupport()
bool CBuildConfig::isCompiledWithFlightSimulatorSupport()
{
return isCompiledWithFsxSupport() || isCompiledWithXPlaneSupport();
}
bool BlackMisc::CProject::isCompiledWithGui()
bool CBuildConfig::isCompiledWithGui()
{
#ifdef WITH_BLACKGUI
return true;
@@ -107,60 +99,7 @@ namespace BlackMisc
#endif
}
const BlackMisc::Simulation::CSimulatorInfo &CProject::simulators()
{
static const BlackMisc::Simulation::CSimulatorInfo simInfo(
isCompiledWithFsxSupport(),
isCompiledWithFs9Support(),
isCompiledWithXPlaneSupport(),
isCompiledWithP3DSupport()
);
return simInfo;
}
const char *CProject::simulatorsChar()
{
static const QByteArray sims(simulators().toQString().toUtf8());
return sims.constData();
}
const QString &CProject::version()
{
#ifdef BLACK_VERSION
static const QString v(BLACK_STRINGIFY(BLACK_VERSION));
#else
static const QString v("?");
#endif
return v;
}
int CProject::versionMajor()
{
return getMajorMinor(0);
}
int CProject::versionMinor()
{
return getMajorMinor(1);
}
bool CProject::isNewerVersion(const QString &versionString)
{
if (versionString.isEmpty()) { return false; }
if (CProject::version() == versionString) { return false; }
QList<int> newer(getVersionParts(versionString));
QList<int> current(getVersionParts(version()));
for (int i = 0; i < current.length(); i++)
{
if (newer.length() <= i) { return false; }
if (current.at(i) > newer.at(i)) { return false; }
if (current.at(i) < newer.at(i)) { return true; }
}
return false;
}
bool CProject::isDebugBuild()
bool CBuildConfig::isDebugBuild()
{
#ifdef QT_DEBUG
return true;
@@ -169,7 +108,7 @@ namespace BlackMisc
#endif
}
bool CProject::isReleaseBuild()
bool CBuildConfig::isReleaseBuild()
{
#ifdef QT_NO_DEBUG
return true;
@@ -178,7 +117,7 @@ namespace BlackMisc
#endif
}
bool CProject::isBetaTest()
bool CBuildConfig::isBetaTest()
{
#ifdef SWIFT_BETA
return true;
@@ -187,13 +126,13 @@ namespace BlackMisc
#endif
}
bool CProject::canRunInDeveloperEnvironment()
bool CBuildConfig::canRunInDeveloperEnvironment()
{
if (isBetaTest()) { return true; }
return !isShippedVersion();
}
bool CProject::isShippedVersion()
bool CBuildConfig::isShippedVersion()
{
#ifdef SWIFT_SHIPPED
return true;
@@ -202,7 +141,7 @@ namespace BlackMisc
#endif
}
bool CProject::isRunningOnWindowsNtPlatform()
bool CBuildConfig::isRunningOnWindowsNtPlatform()
{
#ifdef Q_OS_WIN
// QSysInfo::WindowsVersion only available on Win platforms
@@ -212,58 +151,32 @@ namespace BlackMisc
#endif
}
QList<int> CProject::getVersionParts(const QString &versionString)
{
QStringList parts = versionString.split('.');
QList<int> partsInt;
for (const QString &p : parts)
{
bool ok = false;
int pInt = p.toInt(&ok);
partsInt.append(ok ? pInt : -1);
}
return partsInt;
}
int CProject::getMajorMinor(int index)
{
QList<int> partsInt(getVersionParts(version()));
if (index >= partsInt.length()) { return -1; }
return partsInt[index];
}
const QString &CProject::swiftGuiExecutableName()
const QString &CBuildConfig::swiftGuiExecutableName()
{
static const QString s("swiftguistd");
return s;
}
const QString &CProject::swiftCoreExecutableName()
const QString &CBuildConfig::swiftCoreExecutableName()
{
static const QString s("swiftcore");
return s;
}
const QString &CProject::swiftDataExecutableName()
const QString &CBuildConfig::swiftDataExecutableName()
{
static const QString s("swiftdata");
return s;
}
const QStringList &CProject::swiftTeamDefaultServers()
const QStringList &CBuildConfig::swiftTeamDefaultServers()
{
static const QStringList s({ "https://vatsim-germany.org:50443/mapping/public/shared", "http://ubuntu12/public/bootstrap/shared"});
static const QStringList s({ "https://vatsim-germany.org:50443/mapping/public/shared",
"http://ubuntu12/public/bootstrap/shared"});
return s;
}
const QDateTime &CProject::getEol()
{
static const QString eol(BLACK_STRINGIFY(BLACK_EOL));
static const QDateTime dt(eol.isEmpty() ? QDateTime() : QDateTime::fromString(eol, "yyyyMMdd"));
return dt;
}
bool CProject::isLifetimeExpired()
bool CBuildConfig::isLifetimeExpired()
{
if (getEol().isValid())
{
@@ -282,7 +195,7 @@ namespace BlackMisc
return p.absolutePath();
}
const QString &CProject::getApplicationDir()
const QString &CBuildConfig::getApplicationDir()
{
static const QString s(getApplicationDirImpl());
return s;
@@ -290,7 +203,7 @@ namespace BlackMisc
QString getSwiftResourceDirImpl()
{
QDir dir(CProject::getApplicationDir());
QDir dir(CBuildConfig::getApplicationDir());
if (dir.cdUp())
{
Q_ASSERT_X(dir.exists(), Q_FUNC_INFO, "missing dir");
@@ -300,7 +213,7 @@ namespace BlackMisc
return "";
}
const QString &CProject::getSwiftResourceDir()
const QString &CBuildConfig::getSwiftResourceDir()
{
static const QString s(getSwiftResourceDirImpl());
return s;
@@ -308,14 +221,14 @@ namespace BlackMisc
const QString getBootstrapResourceFileImpl()
{
const QString d(CProject::getSwiftResourceDir());
const QString d(CBuildConfig::getSwiftResourceDir());
if (d.isEmpty()) { return ""; }
const QFile file(CFileUtils::appendFilePaths(d, "shared/boostrap/boostrap.json"));
Q_ASSERT_X(file.exists(), Q_FUNC_INFO, "missing dir");
return QFileInfo(file).absoluteFilePath();
}
const QString &CProject::getBootstrapResourceFile()
const QString &CBuildConfig::getBootstrapResourceFile()
{
static const QString s(getBootstrapResourceFileImpl());
return s;
@@ -323,14 +236,14 @@ namespace BlackMisc
QString getSwiftStaticDbFilesDirImpl()
{
const QString d(CProject::getSwiftResourceDir());
const QString d(CBuildConfig::getSwiftResourceDir());
if (d.isEmpty()) { return ""; }
QDir dir(CFileUtils::appendFilePaths(d, "shared/dbdata"));
Q_ASSERT_X(dir.exists(), Q_FUNC_INFO, "missing dir");
return dir.absolutePath();
}
const QString &CProject::getSwiftStaticDbFilesDir()
const QString &CBuildConfig::getSwiftStaticDbFilesDir()
{
static QString s(getSwiftStaticDbFilesDirImpl());
return s;
@@ -338,13 +251,13 @@ namespace BlackMisc
QString getImagesDirImpl()
{
const QString d(CProject::getSwiftResourceDir());
const QString d(CBuildConfig::getSwiftResourceDir());
QDir dir(CFileUtils::appendFilePaths(d, "data/images"));
Q_ASSERT_X(dir.exists(), Q_FUNC_INFO, "missing dir");
return dir.absolutePath();
}
const QString &CProject::getImagesDir()
const QString &CBuildConfig::getImagesDir()
{
static const QString s(getImagesDirImpl());
return s;
@@ -360,13 +273,13 @@ namespace BlackMisc
return pathes.first();
}
const QString &CProject::getDocumentationDirectory()
const QString &CBuildConfig::getDocumentationDirectory()
{
static const QString d(getDocumentationDirectoryImpl());
return d;
}
const QString &CProject::compiledWithInfo(bool shortVersion)
const QString &CBuildConfig::compiledWithInfo(bool shortVersion)
{
if (shortVersion)
{
@@ -405,6 +318,38 @@ namespace BlackMisc
return infoLong;
}
}
bool CVersion::isNewerVersion(const QString &versionString)
{
if (versionString.isEmpty()) { return false; }
if (CVersion::version() == versionString) { return false; }
QList<int> newer(getVersionParts(versionString));
QList<int> current(getVersionParts(version()));
for (int i = 0; i < current.length(); i++)
{
if (newer.length() <= i) { return false; }
if (current.at(i) > newer.at(i)) { return false; }
if (current.at(i) < newer.at(i)) { return true; }
}
return false;
}
QList<int> CVersion::getVersionParts(const QString &versionString)
{
QStringList parts = versionString.split('.');
QList<int> partsInt;
for (const QString &p : parts)
{
bool ok = false;
int pInt = p.toInt(&ok);
partsInt.append(ok ? pInt : -1);
}
return partsInt;
}
} // ns
//! \endcond

View File

@@ -1,5 +1,5 @@
/* Copyright (C) 2013
* swift Project Community / Contributors
/* Copyright (C) 2016
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
@@ -9,19 +9,30 @@
//! \file
#ifndef BLACKMISC_CPROJECT_H
#define BLACKMISC_CPROJECT_H
#ifndef BLACKMISC_BUILDCONFIG_H
#define BLACKMISC_BUILDCONFIG_H
#include "blackmiscexport.h"
#include "blackmisc/simulation/simulatorinfo.h"
#include \"blackmisc/blackmiscexport.h\"
#include <QString>
#include <QDateTime>
$$DEFINE_WITH_BLACKCORE#define WITH_BLACKCORE
$$DEFINE_WITH_BLACKSOUND#define WITH_BLACKSOUND
$$DEFINE_WITH_BLACKINPUT#define WITH_BLACKINPUT
$$DEFINE_WITH_BLACKGUI#define WITH_BLACKGUI
$$DEFINE_WITH_SWIFTDATA#define WITH_SWIFTDATA
$$DEFINE_WITH_SWIFTGUI#define WITH_SWIFTGUI
$$DEFINE_WITH_SWIFTCORE#define WITH_SWIFTCORE
$$DEFINE_WITH_FSX#define WITH_FSX
$$DEFINE_WITH_FS9#define WITH_FS9
$$DEFINE_WITH_XPLANE#define WITH_XPLANE
$$DEFINE_SWIFT_BETA#define SWIFT_BETA
$$DEFINE_SWIFT_SHIPPED#define SWIFT_SHIPPED
namespace BlackMisc
{
/*!
* Metadata about the project
*/
class BLACKMISC_EXPORT CProject
class BLACKMISC_EXPORT CBuildConfig
{
public:
//! with BlackCore?
@@ -54,24 +65,6 @@ namespace BlackMisc
//! with GUI?
static bool isCompiledWithGui();
//! Simulator String info
static const BlackMisc::Simulation::CSimulatorInfo &simulators();
//! Simulator String info
static const char *simulatorsChar();
//! Version info
static const QString &version();
//! Version major
static int versionMajor();
//! Version minor
static int versionMinor();
//! Is the given string representing a newer version?
static bool isNewerVersion(const QString &versionString);
//! Debug build?
static bool isDebugBuild();
@@ -91,6 +84,7 @@ namespace BlackMisc
static bool isRunningOnWindowsNtPlatform();
//! Application directory where current application is located
//! \todo Move to to CApplication
static const QString &getApplicationDir();
//! Where resource files (static DB files, ...) etc are located
@@ -111,9 +105,6 @@ namespace BlackMisc
//! Info string about compilation
static const QString &compiledWithInfo(bool shortVersion = true);
//! Whole info
static QString convertToQString(const QString &separator = QString("\n"));
//! Executable name for swift GUI, no(!) appendix
static const QString &swiftGuiExecutableName();
@@ -127,21 +118,61 @@ namespace BlackMisc
static const QStringList &swiftTeamDefaultServers();
//! End of lifetime
static const QDateTime &getEol();
static const QDateTime &getEol()
{
static const QString eol(\"$$BLACK_EOL\");
static const QDateTime dt(eol.isEmpty() ? QDateTime() : QDateTime::fromString(eol, \"yyyyMMdd\"));
return dt;
}
//! Lifetime ended?
static bool isLifetimeExpired();
private:
//! Constructor
CProject() {}
//! Vatsim client id
static int vatsimClientId()
{
static const int id { $$VATSIM_CLIENT_ID };
return id;
}
//! Vatsim client key
static const QString &vatsimPrivateKey()
{
static const auto pk = QString { \"$$VATSIM_CLIENT_PRIVATE_KEY\" };
return pk;
}
};
class BLACKMISC_EXPORT CVersion
{
public:
//! Version info
static const QString &version()
{
static const QString version(\"$$BLACK_VERSION\");
Q_ASSERT(!version.isEmpty());
return version;
}
//! Version major
static int versionMajor() { return $$BLACK_VER_MAJ; }
//! Version minor
static int versionMinor() { return $$BLACK_VER_MIN; }
//! Version patch
static int versionPatch() { return $$BLACK_VER_PAT; }
//! Is the given string representing a newer version?
static bool isNewerVersion(const QString &versionString);
private:
//! Parts of version string 1.0.2
static QList<int> getVersionParts(const QString &versionString);
//! Split version
static int getMajorMinor(int index);
};
} // ns
#endif // guard
}
#endif // BLACKCONFIG_H

View File

@@ -9,7 +9,7 @@
#include "blackmisc/worker.h"
#include "fileutils.h"
#include "project.h"
#include "buildconfig.h"
#include <QFile>
#include <QCoreApplication>
@@ -113,7 +113,7 @@ namespace BlackMisc
Qt::CaseSensitivity CFileUtils::osFileNameCaseSensitivity()
{
return CProject::isRunningOnWindowsNtPlatform() ? Qt::CaseInsensitive : Qt::CaseSensitive;
return CBuildConfig::isRunningOnWindowsNtPlatform() ? Qt::CaseInsensitive : Qt::CaseSensitive;
}
bool CFileUtils::matchesExcludeDirectory(const QString &directoryPath, const QString &excludeDirectory, Qt::CaseSensitivity cs)

View File

@@ -16,6 +16,7 @@
#include <QObject>
#include <QDebug>
#include <QDir>
#include <functional>
namespace BlackMisc
{

View File

@@ -10,8 +10,8 @@
//! \cond PRIVATE
#include "icons.h"
#include "blackmisc/project.h"
#include "blackmisc/fileutils.h"
#include "buildconfig.h"
#include <QImage>
#include <QIcon>
#include <QPainter>
@@ -1126,7 +1126,7 @@ namespace BlackMisc
Q_ASSERT_X(!fileName.isEmpty(), Q_FUNC_INFO, "missing filename");
if (!getResourceFileCache().contains(fileName))
{
QString path = CFileUtils::appendFilePaths(CProject::getImagesDir(), fileName);
QString path = CFileUtils::appendFilePaths(CBuildConfig::getImagesDir(), fileName);
QPixmap pm;
bool s = pm.load(path);
if (s)

View File

@@ -7,7 +7,7 @@
* contained in the LICENSE file.
*/
#include "blackmisc/project.h"
#include "blackmisc/buildconfig.h"
#include "fscommonutil.h"
#include <QSettings>
#include <QDir>
@@ -25,7 +25,7 @@ namespace BlackMisc
QString CFsCommonUtil::fsxDirFromRegistry()
{
QString fsxPath;
if (CProject::isCompiledWithFsxSupport())
if (CBuildConfig::isCompiledWithFsxSupport())
{
FsRegistryPathPair fsxRegistryPathPairs =
{
@@ -102,7 +102,7 @@ namespace BlackMisc
QString CFsCommonUtil::fs9DirFromRegistry()
{
QString fs9Path;
if (CProject::isCompiledWithFs9Support())
if (CBuildConfig::isCompiledWithFs9Support())
{
FsRegistryPathPair fs9RegistryPathPairs =
{

View File

@@ -9,7 +9,7 @@
#include "fsxsimulatorsetup.h"
#include "blackmisc/project.h"
#include "buildconfig.h"
#include "blackmisc/simulation/fscommon/fscommonutil.h"
#include "blackmisc/simulation/fsx/simconnectutilities.h"
@@ -30,7 +30,7 @@ namespace BlackMisc
CSimulatorSetup s;
s.setValue(KeyLocalSimConnectCfgFilename(), CSimConnectUtilities::getLocalSimConnectCfgFilename());
if (CProject::isCompiledWithFsxSupport())
if (CBuildConfig::isCompiledWithFsxSupport())
{
// set FSX path
QString fsxPath = CFsCommonUtil::fsxDirFromRegistry();

View File

@@ -8,7 +8,7 @@
*/
#include "simulatorinfo.h"
#include "blackmisc/project.h"
#include "buildconfig.h"
#include "blackmisc/comparefunctions.h"
#include "blackmisc/simulation/fscommon/fscommonutil.h"
#include <algorithm>
@@ -170,15 +170,15 @@ namespace BlackMisc
//! \todo add XP, ...
CSimulatorInfo sim;
bool fs9 =
CProject::isRunningOnWindowsNtPlatform() &&
CBuildConfig::isRunningOnWindowsNtPlatform() &&
!CFsCommonUtil::fs9AircraftDir().isEmpty() &&
!CFsCommonUtil::fs9Dir().isEmpty();
bool fsx =
CProject::isRunningOnWindowsNtPlatform() &&
CBuildConfig::isRunningOnWindowsNtPlatform() &&
!CFsCommonUtil::fsxSimObjectsDir().isEmpty() &&
!CFsCommonUtil::fsxDir().isEmpty();
bool p3d =
CProject::isRunningOnWindowsNtPlatform() &&
CBuildConfig::isRunningOnWindowsNtPlatform() &&
!CFsCommonUtil::p3dDir().isEmpty() &&
!CFsCommonUtil::p3dSimObjectsDir().isEmpty();
bool xp = true; //! \todo XP resolution