diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2020-04-14 15:49:18 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2020-04-16 09:56:01 +0000 |
commit | 4d3eea6884c212893eea599d47edec2648e4c266 (patch) | |
tree | 52b7ceb012d672cc605d43c6c882dfaec4d263f1 /src/plugins | |
parent | 9c2393fa6931a302d8669dc35d802620c6d5f3a2 (diff) | |
download | qt-creator-4d3eea6884c212893eea599d47edec2648e4c266.tar.gz |
CMake: Pass on extra files to code model
Pass on extra files that are not compiled according to CMake
(== headers) to the code model, so that it has the information
which build system these files are associated with.
This helps a bit with the AutoTest plugin, which wants to scan
files (incl. headers) for tests and needs information on which
build system target will build that test.
This patch fixes e.g. Google Test detection for CMake projects --
but *only* if the header files are actually listed in
CMakeLists.txt. If that is not the case, then the CMake plugin
has no way of knowing which target will build tests.
Task-number: QTCREATORBUG-23843
Change-Id: I1117c63dd052ec29a3bce6cce24c3389eedb2df7
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/cmakeprojectmanager/fileapidataextractor.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp index 79891a8b5b..568b9510bd 100644 --- a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp +++ b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp @@ -312,11 +312,10 @@ RawProjectParts generateRawProjectParts(const PreprocessedData &input, const FilePath &sourceDirectory) { RawProjectParts rpps; + const QDir sourceDir(sourceDirectory.toString()); int counter = 0; for (const TargetDetails &t : input.targetDetails) { - QDir sourceDir(sourceDirectory.toString()); - bool needPostfix = t.compileGroups.size() > 1; int count = 1; for (const CompileInfo &ci : t.compileGroups) { @@ -359,14 +358,15 @@ RawProjectParts generateRawProjectParts(const PreprocessedData &input, cxxProjectFlags.commandLineFlags = cProjectFlags.commandLineFlags; rpp.setFlagsForCxx(cxxProjectFlags); - FilePath precompiled_header - = FilePath::fromString(findOrDefault(t.sources, [&ending](const SourceInfo &si) { - return si.path.endsWith(ending); - }).path); + FilePath precompiled_header = FilePath::fromString( + findOrDefault(t.sources, [&ending](const SourceInfo &si) { + return si.path.endsWith(ending); + }).path); rpp.setFiles(transform<QList>(ci.sources, [&t, &sourceDir](const int si) { return sourceDir.absoluteFilePath(t.sources[static_cast<size_t>(si)].path); })); + if (!precompiled_header.isEmpty()) { if (precompiled_header.toFileInfo().isRelative()) { const FilePath parentDir = FilePath::fromString(sourceDir.absolutePath()); @@ -381,6 +381,22 @@ RawProjectParts generateRawProjectParts(const PreprocessedData &input, rpps.append(rpp); ++count; } + + // Check sources for more files and associate them with the current target + const QStringList extraSources = Utils::transform<QList>( + Utils::filtered(t.sources, [](const SourceInfo &si) { return si.compileGroup == -1; }), + [&sourceDir](const SourceInfo &si) { return sourceDir.absoluteFilePath(si.path); }); + if (!extraSources.isEmpty()) { + RawProjectPart rpp; + rpp.setProjectFileLocation(t.sourceDir.pathAppended("CMakeLists.txt").toString()); + rpp.setBuildSystemTarget(t.name); + rpp.setDisplayName(t.id + "_extra"); + + rpp.setFiles(extraSources); + + // This is all the information we have :-/ + rpps.append(rpp); + } } return rpps; |