forked from qt-creator/qt-creator
CMakePM: Fix C/C++ code model preparation
Only set the compiler flags for the active language. Select source and header files accordingly to the active language. Fixes: QTCREATORBUG-29707 Change-Id: Ieeaa56f85ccc937f31253ac047538fa19ae4166f Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#include "projecttreehelper.h"
|
#include "projecttreehelper.h"
|
||||||
|
|
||||||
#include <cppeditor/cppeditorconstants.h>
|
#include <cppeditor/cppeditorconstants.h>
|
||||||
|
#include <cppeditor/projectinfo.h>
|
||||||
|
|
||||||
#include <projectexplorer/projecttree.h>
|
#include <projectexplorer/projecttree.h>
|
||||||
|
|
||||||
@@ -442,27 +443,41 @@ static RawProjectParts generateRawProjectParts(const QFuture<void> &cancelFuture
|
|||||||
return isUnityFile(buildDirectory, path);
|
return isUnityFile(buildDirectory, path);
|
||||||
});
|
});
|
||||||
|
|
||||||
QString headerMimeType;
|
const QString headerMimeType = [&]() -> QString {
|
||||||
QString sourceMimeType;
|
if (ci.language == "C") {
|
||||||
if (ci.language == "C") {
|
return CppEditor::Constants::C_HEADER_MIMETYPE;
|
||||||
headerMimeType = CppEditor::Constants::C_HEADER_MIMETYPE;
|
} else if (ci.language == "CXX") {
|
||||||
sourceMimeType = CppEditor::Constants::C_SOURCE_MIMETYPE;
|
return CppEditor::Constants::CPP_HEADER_MIMETYPE;
|
||||||
} else if (ci.language == "CXX") {
|
}
|
||||||
headerMimeType = CppEditor::Constants::CPP_HEADER_MIMETYPE;
|
return {};
|
||||||
sourceMimeType = CppEditor::Constants::CPP_SOURCE_MIMETYPE;
|
}();
|
||||||
}
|
|
||||||
|
auto haveFileKindForLanguage = [&](const auto &kind) {
|
||||||
|
if (kind == CppEditor::ProjectFile::AmbiguousHeader)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (ci.language == "C")
|
||||||
|
return CppEditor::ProjectFile::isC(kind);
|
||||||
|
else if (ci.language == "CXX")
|
||||||
|
return CppEditor::ProjectFile::isCxx(kind);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
if (!hasPchSource) {
|
if (!hasPchSource) {
|
||||||
for (const SourceInfo &si : t.sources) {
|
for (const SourceInfo &si : t.sources) {
|
||||||
if (si.isGenerated)
|
if (si.isGenerated)
|
||||||
continue;
|
continue;
|
||||||
const auto mimeTypes = Utils::mimeTypesForFileName(si.path);
|
|
||||||
for (const auto &mime : mimeTypes) {
|
const auto kind = CppEditor::ProjectFile::classify(si.path);
|
||||||
const bool headerType = mime.inherits(headerMimeType);
|
const bool headerType = CppEditor::ProjectFile::isHeader(kind)
|
||||||
const bool sourceUnityType = hasUnitySources ? mime.inherits(sourceMimeType)
|
&& haveFileKindForLanguage(kind);
|
||||||
: false;
|
const bool sourceUnityType = hasUnitySources
|
||||||
if (headerType || sourceUnityType)
|
? CppEditor::ProjectFile::isSource(kind)
|
||||||
sources.append(sourceDirectory.resolvePath(si.path));
|
&& haveFileKindForLanguage(kind)
|
||||||
}
|
: false;
|
||||||
|
if (headerType || sourceUnityType)
|
||||||
|
sources.append(sourceDirectory.resolvePath(si.path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FilePath::removeDuplicates(sources);
|
FilePath::removeDuplicates(sources);
|
||||||
@@ -477,9 +492,7 @@ static RawProjectParts generateRawProjectParts(const QFuture<void> &cancelFuture
|
|||||||
rpp.setFiles(Utils::transform(filtered, &FilePath::toFSPathString),
|
rpp.setFiles(Utils::transform(filtered, &FilePath::toFSPathString),
|
||||||
{},
|
{},
|
||||||
[headerMimeType](const QString &path) {
|
[headerMimeType](const QString &path) {
|
||||||
// Similar to ProjectFile::classify but classify headers with language
|
if (CppEditor::ProjectFile::isAmbiguousHeader(path))
|
||||||
// of compile group instead of ambiguous header
|
|
||||||
if (path.endsWith(".h"))
|
|
||||||
return headerMimeType;
|
return headerMimeType;
|
||||||
return Utils::mimeTypeForFile(path).name();
|
return Utils::mimeTypeForFile(path).name();
|
||||||
});
|
});
|
||||||
@@ -514,13 +527,12 @@ static RawProjectParts generateRawProjectParts(const QFuture<void> &cancelFuture
|
|||||||
rpp.setPreCompiledHeaders({qtc_precompiled_header.path()});
|
rpp.setPreCompiledHeaders({qtc_precompiled_header.path()});
|
||||||
}
|
}
|
||||||
|
|
||||||
RawProjectPartFlags cProjectFlags;
|
RawProjectPartFlags projectFlags;
|
||||||
cProjectFlags.commandLineFlags = fragments;
|
projectFlags.commandLineFlags = fragments;
|
||||||
rpp.setFlagsForC(cProjectFlags);
|
if (ci.language == "C")
|
||||||
|
rpp.setFlagsForC(projectFlags);
|
||||||
RawProjectPartFlags cxxProjectFlags;
|
else if (ci.language == "CXX")
|
||||||
cxxProjectFlags.commandLineFlags = cProjectFlags.commandLineFlags;
|
rpp.setFlagsForCxx(projectFlags);
|
||||||
rpp.setFlagsForCxx(cxxProjectFlags);
|
|
||||||
|
|
||||||
const bool isExecutable = t.type == "EXECUTABLE";
|
const bool isExecutable = t.type == "EXECUTABLE";
|
||||||
rpp.setBuildTargetType(isExecutable ? BuildTargetType::Executable
|
rpp.setBuildTargetType(isExecutable ? BuildTargetType::Executable
|
||||||
|
|||||||
Reference in New Issue
Block a user