Link CBuildConfig and CVersion into static library blackconfig

CBuildConfig including private keys etc. should not be part of a
public library API. Therefore link it into a static library, which
is not available to end users.

refs #645
This commit is contained in:
Roland Winklmeier
2016-05-24 13:12:23 +02:00
parent 26a78ac2a6
commit 2d8f56a598
40 changed files with 135 additions and 86 deletions

View File

@@ -7,12 +7,14 @@
* contained in the LICENSE file.
*/
#include "audioutils.h"
#include "blackmisc/buildconfig.h"
#include "blackconfig/buildconfig.h"
#include "blackmisc/audio/audioutils.h"
#include <QProcess>
#include <QStringList>
using namespace BlackConfig;
namespace BlackMisc
{
namespace Audio

View File

@@ -4,17 +4,12 @@ QT += network dbus xml
TARGET = blackmisc
TEMPLATE = lib
CONFIG += c++11
CONFIG += blackconfig
contains(BLACK_CONFIG, Static) {
CONFIG += staticlib
}
buildconfig.input = buildconfig.cpp.in
buildconfig.output = $$DestRoot/buildconfig_gen.cpp
GENERATED_SOURCES += $$DestRoot/buildconfig_gen.cpp
QMAKE_SUBSTITUTES += buildconfig
INCLUDEPATH += ..
# DEPENDPATH += . .. // BlackMisc should be independent
# PRECOMPILED_HEADER = stdpch.h

View File

@@ -1,346 +0,0 @@
/* Copyright (C) 2013
* 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,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \cond PRIVATE
#include "buildconfig.h"
#include "blackmisc/buildconfig.h"
#include "blackmisc/fileutils.h"
#include "blackmisc/stringutils.h"
#include <QCoreApplication>
#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QStandardPaths>
#include <QStringList>
#include <QtGlobal>
namespace BlackMisc
{
bool CBuildConfig::isCompiledWithP3DSupport()
{
return CBuildConfig::isCompiledWithFsxSupport();
}
bool CBuildConfig::isCompiledWithMsFlightSimulatorSupport()
{
return CBuildConfig::isCompiledWithFs9Support() || CBuildConfig::isCompiledWithFsxSupport() || CBuildConfig::isCompiledWithP3DSupport();
}
bool CBuildConfig::isCompiledWithFlightSimulatorSupport()
{
return CBuildConfig::isCompiledWithFsxSupport() || CBuildConfig::isCompiledWithXPlaneSupport();
}
const QString &CBuildConfig::swiftGuiExecutableName()
{
static const QString s("swiftguistd");
return s;
}
const QString &CBuildConfig::swiftCoreExecutableName()
{
static const QString s("swiftcore");
return s;
}
const QString &CBuildConfig::swiftDataExecutableName()
{
static const QString s("swiftdata");
return s;
}
bool CBuildConfig::isRunningOnWindowsNtPlatform()
{
#ifdef Q_OS_WIN
// QSysInfo::WindowsVersion only available on Win platforms
return (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based);
#else
return false;
#endif
}
bool CBuildConfig::isRunningOnMacOSXPlatform()
{
#ifdef Q_OS_OSX
return true;
#else
return false;
#endif
}
bool CBuildConfig::isRunningOnLinuxPlatform()
{
#ifdef Q_OS_LINUX
return true;
#else
return false;
#endif
}
bool CBuildConfig::isRunningOnUnixPlatform()
{
return isRunningOnMacOSXPlatform() || isRunningOnLinuxPlatform();
}
bool CBuildConfig::isDebugBuild()
{
#ifdef QT_DEBUG
return true;
#else
return false;
#endif
}
bool CBuildConfig::isReleaseBuild()
{
#ifdef QT_NO_DEBUG
return true;
#else
return false;
#endif
}
const QStringList &CBuildConfig::swiftTeamDefaultServers()
{
static const QStringList s({ "https://vatsim-germany.org:50443/mapping/public/shared",
"http://ubuntu12/public/bootstrap/shared"
});
return s;
}
bool CBuildConfig::isLifetimeExpired()
{
if (getEol().isValid())
{
return QDateTime::currentDateTime() > getEol();
}
else
{
return true;
}
}
QString getApplicationDirImpl()
{
QFileInfo executable(QCoreApplication::applicationFilePath());
QDir p(executable.dir());
return p.absolutePath();
}
const QString &CBuildConfig::getApplicationDir()
{
static const QString s(getApplicationDirImpl());
return s;
}
bool isAppBundle()
{
QDir bundleDir(CBuildConfig::getApplicationDir());
bundleDir.cd("../..");
static const bool isBundled = QFileInfo(bundleDir.absolutePath()).isBundle();
return isBundled;
}
QString getSwiftResourceDirImpl()
{
QDir dir(CBuildConfig::getApplicationDir());
bool success = true;
static const bool appBundle = isAppBundle();
if (CBuildConfig::isRunningOnMacOSXPlatform() && appBundle)
{
success = dir.cd("../../../../data");
}
else { success = dir.cd("../data"); }
if (success)
{
Q_ASSERT_X(dir.exists(), Q_FUNC_INFO, "missing dir");
return dir.absolutePath();
}
Q_ASSERT_X(false, Q_FUNC_INFO, "missing dir");
return "";
}
const QString &CBuildConfig::getSwiftResourceDir()
{
static const QString s(getSwiftResourceDirImpl());
return s;
}
const QString getBootstrapResourceFileImpl()
{
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 &CBuildConfig::getBootstrapResourceFile()
{
static const QString s(getBootstrapResourceFileImpl());
return s;
}
QString getSwiftStaticDbFilesDirImpl()
{
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 &CBuildConfig::getSwiftStaticDbFilesDir()
{
static QString s(getSwiftStaticDbFilesDirImpl());
return s;
}
QString getSoundFilesDirImpl()
{
const QString d(CBuildConfig::getSwiftResourceDir());
if (d.isEmpty()) { return ""; }
QDir dir(CFileUtils::appendFilePaths(d, "sounds"));
Q_ASSERT_X(dir.exists(), Q_FUNC_INFO, "missing dir");
return dir.absolutePath();
}
const QString &CBuildConfig::getSoundFilesDir()
{
static QString s(getSoundFilesDirImpl());
return s;
}
QString getStylesheetsDirImpl()
{
const QString d(CBuildConfig::getSwiftResourceDir());
if (d.isEmpty()) { return ""; }
QDir dir(CFileUtils::appendFilePaths(d, "qss"));
Q_ASSERT_X(dir.exists(), Q_FUNC_INFO, "missing dir");
return dir.absolutePath();
}
const QString &CBuildConfig::getStylesheetsDir()
{
static QString s(getStylesheetsDirImpl());
return s;
}
QString getImagesDirImpl()
{
const QString d(CBuildConfig::getSwiftResourceDir());
QDir dir(CFileUtils::appendFilePaths(d, "images"));
Q_ASSERT_X(dir.exists(), Q_FUNC_INFO, "missing dir");
return dir.absolutePath();
}
const QString &CBuildConfig::getImagesDir()
{
static const QString s(getImagesDirImpl());
return s;
}
bool CBuildConfig::canRunInDeveloperEnvironment()
{
if (CBuildConfig::isBetaTest()) { return true; }
return !CBuildConfig::isShippedVersion();
}
QString getDocumentationDirectoryImpl()
{
QStringList pathes(QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation));
QString d = pathes.first();
d = CFileUtils::appendFilePaths(d, "/swift");
QDir dir(d);
if (dir.exists()) { return dir.absolutePath(); }
return pathes.first();
}
const QString &CBuildConfig::getDocumentationDirectory()
{
static const QString d(getDocumentationDirectoryImpl());
return d;
}
const QString &CBuildConfig::compiledWithInfo(bool shortVersion)
{
if (shortVersion)
{
static QString infoShort;
if (infoShort.isEmpty())
{
QStringList sl;
if (CBuildConfig::isCompiledWithBlackCore()) { sl << "BlackCore"; }
if (CBuildConfig::isCompiledWithBlackSound()) { sl << "BlackSound"; }
if (CBuildConfig::isCompiledWithBlackInput()) { sl << "BlackInput"; }
if (CBuildConfig::isCompiledWithGui()) { sl << "BlackGui"; }
if (CBuildConfig::isCompiledWithFs9Support()) { sl << "FS9"; }
if (CBuildConfig::isCompiledWithFsxSupport()) { sl << "FSX"; }
if (CBuildConfig::isCompiledWithXPlaneSupport()) { sl << "XPlane"; }
if (CBuildConfig::isCompiledWithP3DSupport()) { sl << "P3D"; }
infoShort = sl.join(", ");
if (infoShort.isEmpty()) { infoShort = "<none>"; }
}
return infoShort;
}
else
{
static QString infoLong;
if (infoLong.isEmpty())
{
infoLong = infoLong.append("BlackCore: ").append(BlackMisc::boolToYesNo(isCompiledWithBlackCore()));
infoLong = infoLong.append(" BlackInput: ").append(BlackMisc::boolToYesNo(isCompiledWithBlackInput()));
infoLong = infoLong.append(" BlackSound: ").append(BlackMisc::boolToYesNo(isCompiledWithBlackSound()));
infoLong = infoLong.append(" GUI: ").append(BlackMisc::boolToYesNo(isCompiledWithGui()));
infoLong = infoLong.append(" FS9: ").append(BlackMisc::boolToYesNo(isCompiledWithFs9Support()));
infoLong = infoLong.append(" FSX: ").append(BlackMisc::boolToYesNo(isCompiledWithFsxSupport()));
infoLong = infoLong.append(" P3D: ").append(BlackMisc::boolToYesNo(isCompiledWithP3DSupport()));
infoLong = infoLong.append(" XPlane: ").append(BlackMisc::boolToYesNo(isCompiledWithXPlaneSupport()));
}
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,136 +0,0 @@
/* 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,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include \"blackmisc/buildconfig.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
bool BlackMisc::CBuildConfig::isCompiledWithBlackCore()
{
#ifdef WITH_BLACKCORE
return true;
#else
return false;
#endif
}
bool BlackMisc::CBuildConfig::isCompiledWithBlackSound()
{
#ifdef WITH_BLACKSOUND
return true;
#else
return false;
#endif
}
bool BlackMisc::CBuildConfig::isCompiledWithBlackInput()
{
#ifdef WITH_BLACKINPUT
return true;
#else
return false;
#endif
}
bool BlackMisc::CBuildConfig::isCompiledWithFs9Support()
{
#ifdef WITH_FS9
return true;
#else
return false;
#endif
}
bool BlackMisc::CBuildConfig::isCompiledWithFsxSupport()
{
#ifdef WITH_FSX
return true;
#else
return false;
#endif
}
bool BlackMisc::CBuildConfig::isCompiledWithXPlaneSupport()
{
#ifdef WITH_XPLANE
return true;
#else
return false;
#endif
}
bool BlackMisc::CBuildConfig::isCompiledWithGui()
{
#ifdef WITH_BLACKGUI
return true;
#else
return false;
#endif
}
bool BlackMisc::CBuildConfig::isBetaTest()
{
#ifdef SWIFT_BETA
return true;
#else
return false;
#endif
}
bool BlackMisc::CBuildConfig::isShippedVersion()
{
#ifdef SWIFT_SHIPPED
return true;
#else
return false;
#endif
}
const QDateTime &BlackMisc::CBuildConfig::getEol()
{
static const QString eol(\"$$BLACK_EOL\");
static const QDateTime dt(eol.isEmpty() ? QDateTime() : QDateTime::fromString(eol, \"yyyyMMdd\"));
return dt;
}
int BlackMisc::CBuildConfig::vatsimClientId()
{
static const int id { $$VATSIM_CLIENT_ID };
return id;
}
const QString &BlackMisc::CBuildConfig::vatsimPrivateKey()
{
static const auto pk = QString { \"$$VATSIM_CLIENT_PRIVATE_KEY\" };
return pk;
}
const QString &BlackMisc::CVersion::version()
{
static const QString version(\"$$BLACK_VERSION\");
Q_ASSERT(!version.isEmpty());
return version;
}
int BlackMisc::CVersion::versionMajor() { return $$BLACK_VER_MAJ; }
int BlackMisc::CVersion::versionMinor() { return $$BLACK_VER_MIN; }
int BlackMisc::CVersion::versionPatch() { return $$BLACK_VER_PAT; }

View File

@@ -1,164 +0,0 @@
/* 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,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_BUILDCONFIG_H
#define BLACKMISC_BUILDCONFIG_H
#include "blackmisc/blackmiscexport.h"
#include <QList>
#include <QString>
class QDateTime;
class QStringList;
namespace BlackMisc
{
//! Build configuration
class BLACKMISC_EXPORT CBuildConfig
{
public:
//! with BlackCore?
static bool isCompiledWithBlackCore();
//! with BlackSound?
static bool isCompiledWithBlackSound();
//! with BlackInput?
static bool isCompiledWithBlackInput();
//! with FS9 support?
static bool isCompiledWithFs9Support();
//! with FSX support?
static bool isCompiledWithFsxSupport();
//! with P3D support
static bool isCompiledWithP3DSupport();
//! Compiled with any MS Flight Simulator support (P3D, FSX, FS9)
static bool isCompiledWithMsFlightSimulatorSupport();
//! with XPlane support?
static bool isCompiledWithXPlaneSupport();
//! with any simulator libraries
static bool isCompiledWithFlightSimulatorSupport();
//! with GUI?
static bool isCompiledWithGui();
//! Debug build?
static bool isDebugBuild();
//! Release build?
static bool isReleaseBuild();
//! Beta test?
static bool isBetaTest();
//! Can run in dev. environment
static bool canRunInDeveloperEnvironment();
//! Shipped version?
static bool isShippedVersion();
//! Running on Windows NT platform?
static bool isRunningOnWindowsNtPlatform();
//! Running on Mac OS X platform?
static bool isRunningOnMacOSXPlatform();
//! Running on Linux platform?
static bool isRunningOnLinuxPlatform();
//! Running on Unix (Linux or Mac OS X) platform
static bool isRunningOnUnixPlatform();
//! 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
static const QString &getSwiftResourceDir();
//! Bootstrap resource directory
static const QString &getBootstrapResourceFile();
//! Where static DB files are located
static const QString &getSwiftStaticDbFilesDir();
//! Where sound files are located
static const QString &getSoundFilesDir();
//! Where qss files are located
static const QString &getStylesheetsDir();
//! Where images are located
static const QString &getImagesDir();
//! Directory where data can be stored
static const QString &getDocumentationDirectory();
//! Info string about compilation
static const QString &compiledWithInfo(bool shortVersion = true);
//! Executable name for swift GUI, no(!) appendix
static const QString &swiftGuiExecutableName();
//! Executable name for swift core, no(!) appendix
static const QString &swiftCoreExecutableName();
//! Executable name for swift data, no(!) appendix
static const QString &swiftDataExecutableName();
//! swift team default servers for DB, bootstrap etc.
static const QStringList &swiftTeamDefaultServers();
//! End of lifetime
static const QDateTime &getEol();
//! Lifetime ended?
static bool isLifetimeExpired();
//! Vatsim client id
static int vatsimClientId();
//! Vatsim client key
static const QString &vatsimPrivateKey();
};
//! Version
class BLACKMISC_EXPORT CVersion
{
public:
//! Version info
static const QString &version();
//! Version major
static int versionMajor();
//! Version minor
static int versionMinor();
//! Version patch
static int versionPatch();
//! 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);
};
}
#endif // guard

View File

@@ -7,7 +7,7 @@
* contained in the LICENSE file.
*/
#include "blackmisc/buildconfig.h"
#include "blackconfig/buildconfig.h"
#include "blackmisc/fileutils.h"
#include "blackmisc/worker.h"
@@ -21,6 +21,8 @@
#include <QtGlobal>
#include <algorithm>
using namespace BlackConfig;
namespace BlackMisc
{
const QString &CFileUtils::jsonAppendix()

View File

@@ -9,7 +9,7 @@
//! \cond PRIVATE
#include "blackmisc/buildconfig.h"
#include "blackconfig/buildconfig.h"
#include "blackmisc/fileutils.h"
#include "blackmisc/icons.h"
@@ -21,6 +21,8 @@
#include <QSize>
#include <QtGlobal>
using namespace BlackConfig;
namespace BlackMisc
{

View File

@@ -8,7 +8,6 @@
*/
#include "blackmisc/processctrl.h"
#include "blackmisc/buildconfig.h"
#include "blackmisc/logmessage.h"
#include <array>

View File

@@ -7,7 +7,7 @@
* contained in the LICENSE file.
*/
#include "blackmisc/buildconfig.h"
#include "blackconfig/buildconfig.h"
#include "blackmisc/simulation/fscommon/fscommonutil.h"
#include <QDir>
@@ -17,6 +17,7 @@
#include <QStringList>
#include <QVariant>
using namespace BlackConfig;
using namespace BlackMisc;
namespace BlackMisc

View File

@@ -7,7 +7,7 @@
* contained in the LICENSE file.
*/
#include "blackmisc/buildconfig.h"
#include "blackconfig/buildconfig.h"
#include "blackmisc/simulation/fscommon/fscommonutil.h"
#include "blackmisc/simulation/fsx/fsxsimulatorsetup.h"
#include "blackmisc/simulation/fsx/simconnectutilities.h"
@@ -15,6 +15,7 @@
#include <QString>
using namespace BlackConfig;
using namespace BlackMisc;
using namespace BlackMisc::Simulation::FsCommon;
using namespace BlackMisc::Simulation;

View File

@@ -7,7 +7,7 @@
* contained in the LICENSE file.
*/
#include "blackmisc/buildconfig.h"
#include "blackconfig/buildconfig.h"
#include "blackmisc/comparefunctions.h"
#include "blackmisc/datastoreutility.h"
#include "blackmisc/simulation/fscommon/fscommonutil.h"
@@ -16,6 +16,7 @@
#include <QtGlobal>
#include <algorithm>
using namespace BlackConfig;
using namespace BlackMisc;
using namespace BlackMisc::Simulation::FsCommon;