1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/*
SPDX-FileCopyrightText: 2013-2017 Aleix Pol <aleixpol@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef CMAKEPROJECTDATA_H
#define CMAKEPROJECTDATA_H
#include <QSharedPointer>
#include <QStringList>
#include <QHash>
#include <QDebug>
#include <QDateTime>
#include <QSet>
#include <util/path.h>
#include <cmakecommonexport.h>
class CMakeServer;
/**
* Represents any file in a cmake project that has been added
* to the project.
*
* Contains the required information to compile it properly
*/
struct KDEVCMAKECOMMON_EXPORT CMakeFile
{
KDevelop::Path::List includes;
KDevelop::Path::List frameworkDirectories;
QString compileFlags;
QString language;
QHash<QString, QString> defines;
void addDefine(const QString& define);
bool isEmpty() const
{
return includes.isEmpty() && frameworkDirectories.isEmpty()
&& compileFlags.isEmpty() && defines.isEmpty();
}
};
Q_DECLARE_TYPEINFO(CMakeFile, Q_MOVABLE_TYPE);
inline QDebug operator<<(QDebug debug, const CMakeFile& file)
{
const QDebugStateSaver saver(debug);
debug.nospace() << "CMakeFile(-I " << file.includes << ", -F " << file.frameworkDirectories << ", -D "
<< file.defines << ", " << file.language << ")";
return debug;
}
struct KDEVCMAKECOMMON_EXPORT CMakeFilesCompilationData
{
QHash<KDevelop::Path, CMakeFile> files;
bool isValid = false;
/// lookup table to quickly find a file path for a given folder path
/// this greatly speeds up fallback searching for information on untracked files
/// based on their folder path
QHash<KDevelop::Path, KDevelop::Path> fileForFolder;
mutable QSet<KDevelop::Path> missingFiles; ///< a cache of files, for which there is no compilation data
/// Clears @a missingFiles and recomputes @a fileForFolder. Should be called whenever @a files is modified.
void rebuildFileForFolderMapping();
};
struct KDEVCMAKECOMMON_EXPORT CMakeTarget
{
Q_GADGET
public:
enum Type { Library, Executable, Custom };
Q_ENUM(Type)
static Type typeToEnum(const QString& target);
Type type;
QString name;
KDevelop::Path::List artifacts;
KDevelop::Path::List sources;
// see https://cmake.org/cmake/help/latest/prop_tgt/FOLDER.html
QString folder;
};
Q_DECLARE_TYPEINFO(CMakeTarget, Q_MOVABLE_TYPE);
inline QDebug operator<<(QDebug debug, const CMakeTarget& target)
{
const QDebugStateSaver saver(debug);
debug.nospace() << target.type << ':' << target.name;
return debug;
}
inline bool operator==(const CMakeTarget& lhs, const CMakeTarget& rhs)
{
return lhs.type == rhs.type
&& lhs.name == rhs.name
&& lhs.artifacts == rhs.artifacts;
}
struct KDEVCMAKECOMMON_EXPORT CMakeTest
{
QString name;
QString executable;
QStringList arguments;
QHash<QString, QString> properties;
};
Q_DECLARE_TYPEINFO(CMakeTest, Q_MOVABLE_TYPE);
struct PrintLastModified
{
/// If not null, a prefix including this string is printed before formatted @a lastModified.
const char* const whatWasModified;
const QDateTime& lastModified;
};
QDebug KDEVCMAKECOMMON_EXPORT operator<<(QDebug debug, PrintLastModified p);
struct KDEVCMAKECOMMON_EXPORT CMakeProjectData
{
CMakeFilesCompilationData compilationData;
QHash<KDevelop::Path, QVector<CMakeTarget>> targets;
QVector<CMakeTest> testSuites;
/// Source CMake files (e.g. CMakeLists.txt, *.cmake), modifying which triggers reloading the project.
QSet<KDevelop::Path> cmakeFiles;
bool isOutdated = false;
};
#endif
|