forked from qt-creator/qt-creator
CMakeProjectManager: Add compiler for Visual Studio / Xcode imports
Visual Studio / Xcode generators are not setting the CMAKE_C|XX_COMPILER variables, and when importing such a build the generated kit will have no compilers and won't be much of a use. Luckily CMAKE_LINKER has the path to link.exe / ld, which is the same path for the compiler cl.exe / clang. Change-Id: Id21bb0ec2d5aa6ab5a185e03992477c433ac4798 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -254,19 +254,50 @@ static FilePath qmakeFromCMakeCache(const CMakeConfig &config)
|
|||||||
static QVector<ToolChainDescription> extractToolChainsFromCache(const CMakeConfig &config)
|
static QVector<ToolChainDescription> extractToolChainsFromCache(const CMakeConfig &config)
|
||||||
{
|
{
|
||||||
QVector<ToolChainDescription> result;
|
QVector<ToolChainDescription> result;
|
||||||
|
bool haveCCxxCompiler = false;
|
||||||
for (const CMakeConfigItem &i : config) {
|
for (const CMakeConfigItem &i : config) {
|
||||||
if (!i.key.startsWith("CMAKE_") || !i.key.endsWith("_COMPILER"))
|
if (!i.key.startsWith("CMAKE_") || !i.key.endsWith("_COMPILER"))
|
||||||
continue;
|
continue;
|
||||||
const QByteArray language = i.key.mid(6, i.key.count() - 6 - 9); // skip "CMAKE_" and "_COMPILER"
|
const QByteArray language = i.key.mid(6, i.key.count() - 6 - 9); // skip "CMAKE_" and "_COMPILER"
|
||||||
Id languageId;
|
Id languageId;
|
||||||
if (language == "CXX")
|
if (language == "CXX") {
|
||||||
|
haveCCxxCompiler = true;
|
||||||
languageId = ProjectExplorer::Constants::CXX_LANGUAGE_ID;
|
languageId = ProjectExplorer::Constants::CXX_LANGUAGE_ID;
|
||||||
else if (language == "C")
|
}
|
||||||
|
else if (language == "C") {
|
||||||
|
haveCCxxCompiler = true;
|
||||||
languageId = ProjectExplorer::Constants::C_LANGUAGE_ID;
|
languageId = ProjectExplorer::Constants::C_LANGUAGE_ID;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
languageId = Id::fromName(language);
|
languageId = Id::fromName(language);
|
||||||
result.append({FilePath::fromUtf8(i.value), languageId});
|
result.append({FilePath::fromUtf8(i.value), languageId});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!haveCCxxCompiler) {
|
||||||
|
const QByteArray generator = CMakeConfigItem::valueOf(QByteArray("CMAKE_GENERATOR"), config);
|
||||||
|
QString cCompilerName;
|
||||||
|
QString cxxCompilerName;
|
||||||
|
if (generator.contains("Visual Studio")) {
|
||||||
|
cCompilerName = "cl.exe";
|
||||||
|
cxxCompilerName = "cl.exe";
|
||||||
|
} else if (generator.contains("Xcode")) {
|
||||||
|
cCompilerName = "clang";
|
||||||
|
cxxCompilerName = "clang++";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cCompilerName.isEmpty() && !cxxCompilerName.isEmpty()) {
|
||||||
|
const FilePath linker = FilePath::fromUtf8(
|
||||||
|
CMakeConfigItem::valueOf(QByteArray("CMAKE_LINKER"), config));
|
||||||
|
if (!linker.isEmpty()) {
|
||||||
|
const FilePath compilerPath = linker.parentDir();
|
||||||
|
result.append({compilerPath.pathAppended(cCompilerName),
|
||||||
|
ProjectExplorer::Constants::C_LANGUAGE_ID});
|
||||||
|
result.append({compilerPath.pathAppended(cxxCompilerName),
|
||||||
|
ProjectExplorer::Constants::CXX_LANGUAGE_ID});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,8 +396,12 @@ bool CMakeProjectImporter::matchKit(void *directoryData, const Kit *k) const
|
|||||||
if (!Utils::contains(allLanguages, [&tcd](const Id& language) {return language == tcd.language;}))
|
if (!Utils::contains(allLanguages, [&tcd](const Id& language) {return language == tcd.language;}))
|
||||||
continue;
|
continue;
|
||||||
ToolChain *tc = ToolChainKitAspect::toolChain(k, tcd.language);
|
ToolChain *tc = ToolChainKitAspect::toolChain(k, tcd.language);
|
||||||
if (!tc || tc->compilerCommand().canonicalPath() != tcd.compilerPath.canonicalPath())
|
if (!tc
|
||||||
|
|| !Utils::Environment::systemEnvironment()
|
||||||
|
.isSameExecutable(tc->compilerCommand().toString(),
|
||||||
|
tcd.compilerPath.toString())) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(cmInputLog) << k->displayName()
|
qCDebug(cmInputLog) << k->displayName()
|
||||||
|
|||||||
Reference in New Issue
Block a user