File indexing completed on 2024-05-05 04:39:26
0001 /* 0002 SPDX-FileCopyrightText: 2013-2017 Aleix Pol <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef CMAKEPROJECTDATA_H 0008 #define CMAKEPROJECTDATA_H 0009 0010 #include <QSharedPointer> 0011 #include <QStringList> 0012 #include <QHash> 0013 #include <QDebug> 0014 #include <QDateTime> 0015 #include <QSet> 0016 0017 #include <util/path.h> 0018 0019 #include <cmakecommonexport.h> 0020 0021 class CMakeServer; 0022 0023 /** 0024 * Represents any file in a cmake project that has been added 0025 * to the project. 0026 * 0027 * Contains the required information to compile it properly 0028 */ 0029 struct KDEVCMAKECOMMON_EXPORT CMakeFile 0030 { 0031 KDevelop::Path::List includes; 0032 KDevelop::Path::List frameworkDirectories; 0033 QString compileFlags; 0034 QString language; 0035 QHash<QString, QString> defines; 0036 0037 void addDefine(const QString& define); 0038 0039 bool isEmpty() const 0040 { 0041 return includes.isEmpty() && frameworkDirectories.isEmpty() 0042 && compileFlags.isEmpty() && defines.isEmpty(); 0043 } 0044 }; 0045 Q_DECLARE_TYPEINFO(CMakeFile, Q_MOVABLE_TYPE); 0046 0047 inline QDebug operator<<(QDebug debug, const CMakeFile& file) 0048 { 0049 const QDebugStateSaver saver(debug); 0050 debug.nospace() << "CMakeFile(-I " << file.includes << ", -F " << file.frameworkDirectories << ", -D " 0051 << file.defines << ", " << file.language << ")"; 0052 return debug; 0053 } 0054 0055 struct KDEVCMAKECOMMON_EXPORT CMakeFilesCompilationData 0056 { 0057 QHash<KDevelop::Path, CMakeFile> files; 0058 bool isValid = false; 0059 /// lookup table to quickly find a file path for a given folder path 0060 /// this greatly speeds up fallback searching for information on untracked files 0061 /// based on their folder path 0062 QHash<KDevelop::Path, KDevelop::Path> fileForFolder; 0063 mutable QSet<KDevelop::Path> missingFiles; ///< a cache of files, for which there is no compilation data 0064 0065 /// Clears @a missingFiles and recomputes @a fileForFolder. Should be called whenever @a files is modified. 0066 void rebuildFileForFolderMapping(); 0067 }; 0068 0069 struct KDEVCMAKECOMMON_EXPORT CMakeTarget 0070 { 0071 Q_GADGET 0072 public: 0073 enum Type { Library, Executable, Custom }; 0074 Q_ENUM(Type) 0075 0076 static Type typeToEnum(const QString& target); 0077 0078 Type type; 0079 QString name; 0080 KDevelop::Path::List artifacts; 0081 KDevelop::Path::List sources; 0082 // see https://cmake.org/cmake/help/latest/prop_tgt/FOLDER.html 0083 QString folder; 0084 }; 0085 Q_DECLARE_TYPEINFO(CMakeTarget, Q_MOVABLE_TYPE); 0086 0087 inline QDebug operator<<(QDebug debug, const CMakeTarget& target) 0088 { 0089 const QDebugStateSaver saver(debug); 0090 debug.nospace() << target.type << ':' << target.name; 0091 return debug; 0092 } 0093 0094 inline bool operator==(const CMakeTarget& lhs, const CMakeTarget& rhs) 0095 { 0096 return lhs.type == rhs.type 0097 && lhs.name == rhs.name 0098 && lhs.artifacts == rhs.artifacts; 0099 } 0100 0101 struct KDEVCMAKECOMMON_EXPORT CMakeTest 0102 { 0103 QString name; 0104 QString executable; 0105 QStringList arguments; 0106 QHash<QString, QString> properties; 0107 }; 0108 Q_DECLARE_TYPEINFO(CMakeTest, Q_MOVABLE_TYPE); 0109 0110 struct PrintLastModified 0111 { 0112 /// If not null, a prefix including this string is printed before formatted @a lastModified. 0113 const char* const whatWasModified; 0114 const QDateTime& lastModified; 0115 }; 0116 QDebug KDEVCMAKECOMMON_EXPORT operator<<(QDebug debug, PrintLastModified p); 0117 0118 struct KDEVCMAKECOMMON_EXPORT CMakeProjectData 0119 { 0120 CMakeFilesCompilationData compilationData; 0121 QHash<KDevelop::Path, QVector<CMakeTarget>> targets; 0122 QVector<CMakeTest> testSuites; 0123 /// Source CMake files (e.g. CMakeLists.txt, *.cmake), modifying which triggers reloading the project. 0124 QSet<KDevelop::Path> cmakeFiles; 0125 bool isOutdated = false; 0126 }; 0127 0128 #endif