2015-02-24 21:57:00 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Canonical Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-02-24 21:57:00 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-02-24 21:57:00 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2015-02-24 21:57:00 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
2016-01-15 14:57:40 +01:00
|
|
|
|
2015-02-24 21:57:00 +01:00
|
|
|
#include "cmakekitinformation.h"
|
|
|
|
|
#include "cmakekitconfigwidget.h"
|
|
|
|
|
#include "cmaketoolmanager.h"
|
|
|
|
|
#include "cmaketool.h"
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/task.h>
|
2016-02-12 12:23:18 +01:00
|
|
|
#include <projectexplorer/toolchain.h>
|
2015-02-24 21:57:00 +01:00
|
|
|
#include <projectexplorer/kit.h>
|
2016-02-12 12:23:18 +01:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
2016-09-19 11:53:30 +02:00
|
|
|
#include <qtsupport/baseqtversion.h>
|
2016-02-12 12:23:18 +01:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2015-02-24 21:57:00 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
|
2016-02-12 12:23:18 +01:00
|
|
|
#include <utils/algorithm.h>
|
2016-02-29 14:26:50 +01:00
|
|
|
#include <utils/environment.h>
|
2016-02-12 12:10:28 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2015-02-24 21:57:00 +01:00
|
|
|
|
2016-09-19 11:53:30 +02:00
|
|
|
#include <QVariant>
|
|
|
|
|
|
2015-02-24 21:57:00 +01:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
|
|
|
|
namespace CMakeProjectManager {
|
2016-02-04 18:09:31 +01:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// CMakeKitInformation:
|
|
|
|
|
// --------------------------------------------------------------------
|
2015-02-24 21:57:00 +01:00
|
|
|
|
2016-02-04 17:52:55 +01:00
|
|
|
static Core::Id defaultCMakeToolId()
|
|
|
|
|
{
|
|
|
|
|
CMakeTool *defaultTool = CMakeToolManager::defaultCMakeTool();
|
2016-02-04 18:09:31 +01:00
|
|
|
return defaultTool ? defaultTool->id() : Core::Id();
|
2016-02-04 17:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-04 18:09:31 +01:00
|
|
|
static const char TOOL_ID[] = "CMakeProjectManager.CMakeKitInformation";
|
|
|
|
|
|
2016-01-22 17:17:36 +01:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// CMakeKitInformation:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2015-02-24 21:57:00 +01:00
|
|
|
CMakeKitInformation::CMakeKitInformation()
|
|
|
|
|
{
|
|
|
|
|
setObjectName(QLatin1String("CMakeKitInformation"));
|
2016-02-04 18:09:31 +01:00
|
|
|
setId(TOOL_ID);
|
2015-08-02 20:21:21 +03:00
|
|
|
setPriority(20000);
|
2015-02-24 21:57:00 +01:00
|
|
|
|
|
|
|
|
//make sure the default value is set if a selected CMake is removed
|
|
|
|
|
connect(CMakeToolManager::instance(), &CMakeToolManager::cmakeRemoved,
|
|
|
|
|
[this]() { foreach (Kit *k, KitManager::kits()) fix(k); });
|
|
|
|
|
|
|
|
|
|
//make sure the default value is set if a new default CMake is set
|
|
|
|
|
connect(CMakeToolManager::instance(), &CMakeToolManager::defaultCMakeChanged,
|
|
|
|
|
[this]() { foreach (Kit *k, KitManager::kits()) fix(k); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMakeTool *CMakeKitInformation::cmakeTool(const Kit *k)
|
|
|
|
|
{
|
|
|
|
|
if (!k)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2016-02-04 18:09:31 +01:00
|
|
|
const QVariant id = k->value(TOOL_ID);
|
2015-02-24 21:57:00 +01:00
|
|
|
return CMakeToolManager::findById(Core::Id::fromSetting(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeKitInformation::setCMakeTool(Kit *k, const Core::Id id)
|
|
|
|
|
{
|
2016-02-04 18:09:31 +01:00
|
|
|
const Core::Id toSet = id.isValid() ? id : defaultCMakeToolId();
|
|
|
|
|
QTC_ASSERT(!id.isValid() || CMakeToolManager::findById(toSet), return);
|
|
|
|
|
if (k)
|
|
|
|
|
k->setValue(TOOL_ID, toSet.toSetting());
|
2015-02-24 21:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-04 17:52:55 +01:00
|
|
|
QVariant CMakeKitInformation::defaultValue(const Kit *k) const
|
2015-02-24 21:57:00 +01:00
|
|
|
{
|
2016-02-04 18:09:31 +01:00
|
|
|
const Core::Id id = k ? defaultCMakeToolId() : Core::Id();
|
2016-02-04 17:52:55 +01:00
|
|
|
return id.toSetting();
|
2015-02-24 21:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Task> CMakeKitInformation::validate(const Kit *k) const
|
|
|
|
|
{
|
2016-09-28 17:26:02 +02:00
|
|
|
QList<Task> result;
|
|
|
|
|
CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
|
|
|
|
|
if (tool) {
|
|
|
|
|
CMakeTool::Version version = tool->version();
|
|
|
|
|
if (version.major < 3) {
|
|
|
|
|
result << Task(Task::Warning, tr("CMake version %1 is unsupported. Please update to "
|
|
|
|
|
"version 3.0 or later.").arg(QString::fromUtf8(version.fullVersion)),
|
|
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2015-02-24 21:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeKitInformation::setup(Kit *k)
|
|
|
|
|
{
|
|
|
|
|
CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
|
2016-02-04 18:09:31 +01:00
|
|
|
if (!tool)
|
|
|
|
|
setCMakeTool(k, defaultCMakeToolId());
|
2015-02-24 21:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeKitInformation::fix(Kit *k)
|
|
|
|
|
{
|
2016-02-04 18:09:31 +01:00
|
|
|
if (!CMakeKitInformation::cmakeTool(k))
|
2015-02-24 21:57:00 +01:00
|
|
|
setup(k);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KitInformation::ItemList CMakeKitInformation::toUserOutput(const Kit *k) const
|
|
|
|
|
{
|
2016-02-04 18:09:31 +01:00
|
|
|
const CMakeTool *const tool = cmakeTool(k);
|
2015-02-24 21:57:00 +01:00
|
|
|
return ItemList() << qMakePair(tr("CMake"), tool == 0 ? tr("Unconfigured") : tool->displayName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KitConfigWidget *CMakeKitInformation::createConfigWidget(Kit *k) const
|
|
|
|
|
{
|
|
|
|
|
return new Internal::CMakeKitConfigWidget(k, this);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-23 12:45:47 +01:00
|
|
|
void CMakeKitInformation::addToMacroExpander(Kit *k, Utils::MacroExpander *expander) const
|
|
|
|
|
{
|
|
|
|
|
expander->registerFileVariables("CMake:Executable", tr("Path to the cmake executable"),
|
2016-03-21 06:38:43 +01:00
|
|
|
[this, k]() -> QString {
|
2015-11-23 12:45:47 +01:00
|
|
|
CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
|
|
|
|
|
return tool ? tool->cmakeExecutable().toString() : QString();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-22 17:17:36 +01:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// CMakeGeneratorKitInformation:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
static const char GENERATOR_ID[] = "CMake.GeneratorKitInformation";
|
|
|
|
|
|
2016-09-27 13:26:54 +02:00
|
|
|
static const char GENERATOR_KEY[] = "Generator";
|
|
|
|
|
static const char EXTRA_GENERATOR_KEY[] = "ExtraGenerator";
|
|
|
|
|
static const char PLATFORM_KEY[] = "Platform";
|
|
|
|
|
static const char TOOLSET_KEY[] = "Toolset";
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
struct GeneratorInfo {
|
|
|
|
|
QVariant toVariant() const {
|
|
|
|
|
QVariantMap result;
|
|
|
|
|
result.insert(GENERATOR_KEY, generator);
|
|
|
|
|
result.insert(EXTRA_GENERATOR_KEY, extraGenerator);
|
|
|
|
|
result.insert(PLATFORM_KEY, platform);
|
|
|
|
|
result.insert(TOOLSET_KEY, toolset);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
void fromVariant(const QVariant &v) {
|
|
|
|
|
const QVariantMap value = v.toMap();
|
|
|
|
|
|
|
|
|
|
generator = value.value(GENERATOR_KEY).toString();
|
|
|
|
|
extraGenerator = value.value(EXTRA_GENERATOR_KEY).toString();
|
|
|
|
|
platform = value.value(PLATFORM_KEY).toString();
|
|
|
|
|
toolset = value.value(TOOLSET_KEY).toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString generator;
|
|
|
|
|
QString extraGenerator;
|
|
|
|
|
QString platform;
|
|
|
|
|
QString toolset;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
static GeneratorInfo generatorInfo(const Kit *k)
|
|
|
|
|
{
|
|
|
|
|
GeneratorInfo info;
|
|
|
|
|
if (!k)
|
|
|
|
|
return info;
|
|
|
|
|
|
|
|
|
|
info.fromVariant(k->value(GENERATOR_ID));
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void setGeneratorInfo(Kit *k, const GeneratorInfo &info)
|
|
|
|
|
{
|
|
|
|
|
if (!k)
|
|
|
|
|
return;
|
|
|
|
|
k->setValue(GENERATOR_ID, info.toVariant());
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-22 17:17:36 +01:00
|
|
|
CMakeGeneratorKitInformation::CMakeGeneratorKitInformation()
|
|
|
|
|
{
|
|
|
|
|
setObjectName(QLatin1String("CMakeGeneratorKitInformation"));
|
|
|
|
|
setId(GENERATOR_ID);
|
|
|
|
|
setPriority(19000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CMakeGeneratorKitInformation::generator(const Kit *k)
|
|
|
|
|
{
|
2016-09-27 13:26:54 +02:00
|
|
|
return generatorInfo(k).generator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CMakeGeneratorKitInformation::extraGenerator(const Kit *k)
|
|
|
|
|
{
|
|
|
|
|
return generatorInfo(k).extraGenerator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CMakeGeneratorKitInformation::platform(const Kit *k)
|
|
|
|
|
{
|
|
|
|
|
return generatorInfo(k).platform;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CMakeGeneratorKitInformation::toolset(const Kit *k)
|
|
|
|
|
{
|
|
|
|
|
return generatorInfo(k).toolset;
|
2016-01-22 17:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeGeneratorKitInformation::setGenerator(Kit *k, const QString &generator)
|
|
|
|
|
{
|
2016-09-27 13:26:54 +02:00
|
|
|
GeneratorInfo info = generatorInfo(k);
|
|
|
|
|
info.generator = generator;
|
|
|
|
|
setGeneratorInfo(k, info);
|
2016-01-22 17:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
2016-09-27 13:26:54 +02:00
|
|
|
void CMakeGeneratorKitInformation::setExtraGenerator(Kit *k, const QString &extraGenerator)
|
2016-01-22 17:17:36 +01:00
|
|
|
{
|
2016-09-27 13:26:54 +02:00
|
|
|
GeneratorInfo info = generatorInfo(k);
|
|
|
|
|
info.extraGenerator = extraGenerator;
|
|
|
|
|
setGeneratorInfo(k, info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeGeneratorKitInformation::setPlatform(Kit *k, const QString &platform)
|
|
|
|
|
{
|
|
|
|
|
GeneratorInfo info = generatorInfo(k);
|
|
|
|
|
info.platform = platform;
|
|
|
|
|
setGeneratorInfo(k, info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeGeneratorKitInformation::setToolset(Kit *k, const QString &toolset)
|
|
|
|
|
{
|
|
|
|
|
GeneratorInfo info = generatorInfo(k);
|
|
|
|
|
info.toolset = toolset;
|
|
|
|
|
setGeneratorInfo(k, info);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-28 12:24:06 +02:00
|
|
|
void CMakeGeneratorKitInformation::set(Kit *k,
|
|
|
|
|
const QString &generator, const QString &extraGenerator,
|
|
|
|
|
const QString &platform, const QString &toolset)
|
|
|
|
|
{
|
|
|
|
|
GeneratorInfo info = { generator, extraGenerator, platform, toolset };
|
|
|
|
|
setGeneratorInfo(k, info);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-27 13:26:54 +02:00
|
|
|
QStringList CMakeGeneratorKitInformation::generatorArguments(const Kit *k)
|
|
|
|
|
{
|
|
|
|
|
QStringList result;
|
|
|
|
|
GeneratorInfo info = generatorInfo(k);
|
|
|
|
|
if (info.generator.isEmpty())
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
if (info.extraGenerator.isEmpty()) {
|
|
|
|
|
result.append("-G" + info.generator);
|
|
|
|
|
} else {
|
2016-09-30 14:31:28 +02:00
|
|
|
result.append("-G" + info.extraGenerator + " - " + info.generator);
|
2016-09-27 13:26:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!info.platform.isEmpty())
|
|
|
|
|
result.append("-A" + info.platform);
|
|
|
|
|
|
|
|
|
|
if (!info.toolset.isEmpty())
|
|
|
|
|
result.append("-T" + info.toolset);
|
|
|
|
|
|
|
|
|
|
return result;
|
2016-01-22 17:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant CMakeGeneratorKitInformation::defaultValue(const Kit *k) const
|
|
|
|
|
{
|
|
|
|
|
CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
|
|
|
|
|
if (!tool)
|
2016-09-27 13:26:54 +02:00
|
|
|
return QVariant();
|
2016-09-28 12:24:06 +02:00
|
|
|
|
2016-09-27 13:26:54 +02:00
|
|
|
const QString extraGenerator = "CodeBlocks";
|
|
|
|
|
|
2016-09-28 12:24:06 +02:00
|
|
|
QList<CMakeTool::Generator> known = tool->supportedGenerators();
|
2016-01-22 17:17:36 +01:00
|
|
|
auto it = std::find_if(known.constBegin(), known.constEnd(),
|
2016-09-28 12:24:06 +02:00
|
|
|
[extraGenerator](const CMakeTool::Generator &g) {
|
|
|
|
|
return g.matches("Ninja", extraGenerator);
|
|
|
|
|
});
|
2016-02-29 14:26:50 +01:00
|
|
|
if (it != known.constEnd()) {
|
|
|
|
|
Utils::Environment env = Utils::Environment::systemEnvironment();
|
|
|
|
|
k->addToEnvironment(env);
|
|
|
|
|
const Utils::FileName ninjaExec = env.searchInPath(QLatin1String("ninja"));
|
2016-09-28 12:24:06 +02:00
|
|
|
if (!ninjaExec.isEmpty())
|
2016-09-30 11:24:11 +02:00
|
|
|
return GeneratorInfo({ QString("Ninja"), extraGenerator, QString(), QString() }).toVariant();
|
2016-02-29 14:26:50 +01:00
|
|
|
}
|
2016-09-28 12:24:06 +02:00
|
|
|
|
2016-03-02 10:18:06 +01:00
|
|
|
if (Utils::HostOsInfo::isWindowsHost()) {
|
|
|
|
|
// *sigh* Windows with its zoo of incompatible stuff again...
|
2016-07-12 16:27:45 +02:00
|
|
|
ToolChain *tc = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx);
|
2016-03-02 10:18:06 +01:00
|
|
|
if (tc && tc->typeId() == ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID) {
|
2016-09-28 12:24:06 +02:00
|
|
|
it = std::find_if(known.constBegin(), known.constEnd(),
|
|
|
|
|
[extraGenerator](const CMakeTool::Generator &g) {
|
|
|
|
|
return g.matches("MinGW Makefiles", extraGenerator);
|
|
|
|
|
});
|
2016-03-02 10:18:06 +01:00
|
|
|
} else {
|
2016-09-28 12:24:06 +02:00
|
|
|
it = std::find_if(known.constBegin(), known.constEnd(),
|
|
|
|
|
[extraGenerator](const CMakeTool::Generator &g) {
|
|
|
|
|
return g.matches("NMake Makefiles", extraGenerator);
|
|
|
|
|
});
|
2016-03-02 10:18:06 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Unix-oid OSes:
|
2016-09-28 12:24:06 +02:00
|
|
|
it = std::find_if(known.constBegin(), known.constEnd(),
|
|
|
|
|
[extraGenerator](const CMakeTool::Generator &g) {
|
|
|
|
|
return g.matches("Unix Makefiles", extraGenerator);
|
|
|
|
|
});
|
2016-03-02 10:18:06 +01:00
|
|
|
}
|
2016-01-22 17:17:36 +01:00
|
|
|
if (it == known.constEnd())
|
|
|
|
|
it = known.constBegin(); // Fallback to the first generator...
|
2016-09-27 13:26:54 +02:00
|
|
|
if (it == known.constEnd())
|
|
|
|
|
return QVariant();
|
|
|
|
|
|
2016-09-28 12:24:06 +02:00
|
|
|
return GeneratorInfo({ it->name, extraGenerator, QString(), QString() }).toVariant();
|
2016-01-22 17:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Task> CMakeGeneratorKitInformation::validate(const Kit *k) const
|
|
|
|
|
{
|
|
|
|
|
CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
|
2016-09-27 13:26:54 +02:00
|
|
|
GeneratorInfo info = generatorInfo(k);
|
2016-01-22 17:17:36 +01:00
|
|
|
|
|
|
|
|
QList<Task> result;
|
2016-04-19 11:57:09 +02:00
|
|
|
if (tool) {
|
2016-01-22 17:17:36 +01:00
|
|
|
if (!tool->isValid()) {
|
|
|
|
|
result << Task(Task::Warning, tr("CMake Tool is unconfigured, CMake generator will be ignored."),
|
|
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
} else {
|
2016-09-28 12:24:06 +02:00
|
|
|
QList<CMakeTool::Generator> known = tool->supportedGenerators();
|
|
|
|
|
auto it = std::find_if(known.constBegin(), known.constEnd(), [info](const CMakeTool::Generator &g) {
|
|
|
|
|
return g.matches(info.generator, info.extraGenerator);
|
|
|
|
|
});
|
|
|
|
|
if (it == known.constEnd()) {
|
2016-06-03 08:39:47 +02:00
|
|
|
result << Task(Task::Warning, tr("CMake Tool does not support the configured generator."),
|
2016-01-22 17:17:36 +01:00
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
2016-09-28 12:24:06 +02:00
|
|
|
} else {
|
|
|
|
|
if (!it->supportsPlatform && !info.platform.isEmpty()) {
|
|
|
|
|
result << Task(Task::Warning, tr("Platform is not supported by the selected CMake generator."),
|
|
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
}
|
|
|
|
|
if (!it->supportsToolset && !info.toolset.isEmpty()) {
|
|
|
|
|
result << Task(Task::Warning, tr("Toolset is not supported by the selected CMake generator."),
|
|
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
}
|
2016-01-22 17:17:36 +01:00
|
|
|
}
|
2016-09-27 13:26:54 +02:00
|
|
|
if (info.extraGenerator != "CodeBlocks") {
|
2016-04-21 17:24:53 +02:00
|
|
|
result << Task(Task::Warning, tr("CMake generator does not generate a CodeBlocks file. "
|
2016-01-22 17:17:36 +01:00
|
|
|
"Qt Creator will not be able to parse the CMake project."),
|
|
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeGeneratorKitInformation::setup(Kit *k)
|
|
|
|
|
{
|
2016-09-27 13:26:54 +02:00
|
|
|
GeneratorInfo info;
|
|
|
|
|
info.fromVariant(defaultValue(k));
|
|
|
|
|
setGeneratorInfo(k, info);
|
2016-01-22 17:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeGeneratorKitInformation::fix(Kit *k)
|
|
|
|
|
{
|
|
|
|
|
const CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
|
2016-09-27 13:26:54 +02:00
|
|
|
const GeneratorInfo info = generatorInfo(k);
|
2016-01-22 17:17:36 +01:00
|
|
|
|
|
|
|
|
if (!tool)
|
|
|
|
|
return;
|
2016-09-28 12:24:06 +02:00
|
|
|
QList<CMakeTool::Generator> known = tool->supportedGenerators();
|
|
|
|
|
auto it = std::find_if(known.constBegin(), known.constEnd(),
|
|
|
|
|
[info](const CMakeTool::Generator &g) {
|
|
|
|
|
return g.matches(info.generator, info.extraGenerator);
|
|
|
|
|
});
|
|
|
|
|
if (it == known.constEnd()) {
|
2016-09-27 13:26:54 +02:00
|
|
|
GeneratorInfo dv;
|
|
|
|
|
dv.fromVariant(defaultValue(k));
|
|
|
|
|
setGeneratorInfo(k, dv);
|
2016-09-28 12:24:06 +02:00
|
|
|
} else {
|
|
|
|
|
const GeneratorInfo dv = { info.generator, info.extraGenerator,
|
|
|
|
|
it->supportsPlatform ? info.platform : QString(),
|
|
|
|
|
it->supportsToolset ? info.toolset : QString() };
|
|
|
|
|
setGeneratorInfo(k, dv);
|
2016-09-27 13:26:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeGeneratorKitInformation::upgrade(Kit *k)
|
|
|
|
|
{
|
|
|
|
|
const QVariant value = k->value(GENERATOR_ID);
|
|
|
|
|
GeneratorInfo info;
|
|
|
|
|
if (value.type() != QVariant::Map) {
|
|
|
|
|
const QString fullName = value.toString();
|
|
|
|
|
const int pos = fullName.indexOf(" - ");
|
|
|
|
|
if (pos >= 0) {
|
|
|
|
|
info.generator = fullName.mid(pos + 3);
|
|
|
|
|
info.extraGenerator = fullName.mid(0, pos);
|
|
|
|
|
} else {
|
|
|
|
|
info.generator = fullName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setGeneratorInfo(k, info);
|
2016-01-22 17:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KitInformation::ItemList CMakeGeneratorKitInformation::toUserOutput(const Kit *k) const
|
|
|
|
|
{
|
2016-09-27 13:26:54 +02:00
|
|
|
const GeneratorInfo info = generatorInfo(k);
|
|
|
|
|
QString message;
|
|
|
|
|
if (info.generator.isEmpty()) {
|
|
|
|
|
message = tr("<Use Default Generator>");
|
|
|
|
|
} else {
|
|
|
|
|
message = tr("Generator: %1<br>Extra Generator: %2").arg(info.generator).arg(info.extraGenerator);
|
|
|
|
|
if (!info.platform.isEmpty())
|
|
|
|
|
message += tr("<br>Platform: %1").arg(info.platform);
|
|
|
|
|
if (!info.toolset.isEmpty())
|
|
|
|
|
message += tr("<br>Toolset: %1").arg(info.toolset);
|
|
|
|
|
}
|
|
|
|
|
return ItemList() << qMakePair(tr("CMake Generator"), message);
|
2016-01-22 17:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KitConfigWidget *CMakeGeneratorKitInformation::createConfigWidget(Kit *k) const
|
|
|
|
|
{
|
|
|
|
|
return new Internal::CMakeGeneratorKitConfigWidget(k, this);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-12 12:23:18 +01:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// CMakeConfigurationKitInformation:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
static const char CONFIGURATION_ID[] = "CMake.ConfigurationKitInformation";
|
|
|
|
|
|
2016-07-18 02:08:25 -07:00
|
|
|
static const char CMAKE_C_TOOLCHAIN_KEY[] = "CMAKE_C_COMPILER";
|
|
|
|
|
static const char CMAKE_CXX_TOOLCHAIN_KEY[] = "CMAKE_CXX_COMPILER";
|
2016-09-19 11:53:30 +02:00
|
|
|
static const char CMAKE_QMAKE_KEY[] = "QT_QMAKE_EXECUTABLE";
|
|
|
|
|
static const char CMAKE_PREFIX_PATH_KEY[] = "CMAKE_PREFIX_PATH";
|
2016-02-12 12:23:18 +01:00
|
|
|
|
|
|
|
|
CMakeConfigurationKitInformation::CMakeConfigurationKitInformation()
|
|
|
|
|
{
|
|
|
|
|
setObjectName(QLatin1String("CMakeConfigurationKitInformation"));
|
|
|
|
|
setId(CONFIGURATION_ID);
|
|
|
|
|
setPriority(18000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMakeConfig CMakeConfigurationKitInformation::configuration(const Kit *k)
|
|
|
|
|
{
|
|
|
|
|
if (!k)
|
|
|
|
|
return CMakeConfig();
|
|
|
|
|
const QStringList tmp = k->value(CONFIGURATION_ID).toStringList();
|
|
|
|
|
return Utils::transform(tmp, [](const QString &s) { return CMakeConfigItem::fromString(s); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeConfigurationKitInformation::setConfiguration(Kit *k, const CMakeConfig &config)
|
|
|
|
|
{
|
|
|
|
|
if (!k)
|
|
|
|
|
return;
|
|
|
|
|
const QStringList tmp = Utils::transform(config, [](const CMakeConfigItem &i) { return i.toString(); });
|
|
|
|
|
k->setValue(CONFIGURATION_ID, tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList CMakeConfigurationKitInformation::toStringList(const Kit *k)
|
|
|
|
|
{
|
|
|
|
|
QStringList current
|
|
|
|
|
= Utils::transform(CMakeConfigurationKitInformation::configuration(k),
|
|
|
|
|
[](const CMakeConfigItem &i) { return i.toString(); });
|
2016-04-08 14:08:13 +02:00
|
|
|
current = Utils::filtered(current, [](const QString &s) { return !s.isEmpty(); });
|
2016-02-12 12:23:18 +01:00
|
|
|
Utils::sort(current);
|
|
|
|
|
return current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeConfigurationKitInformation::fromStringList(Kit *k, const QStringList &in)
|
|
|
|
|
{
|
|
|
|
|
CMakeConfig result;
|
|
|
|
|
foreach (const QString &s, in) {
|
|
|
|
|
const CMakeConfigItem item = CMakeConfigItem::fromString(s);
|
|
|
|
|
if (!item.key.isEmpty())
|
|
|
|
|
result << item;
|
|
|
|
|
}
|
|
|
|
|
setConfiguration(k, result);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-06 15:29:39 +02:00
|
|
|
CMakeConfig CMakeConfigurationKitInformation::defaultConfiguration(const Kit *k)
|
2016-02-12 12:23:18 +01:00
|
|
|
{
|
2016-03-16 13:39:41 +01:00
|
|
|
Q_UNUSED(k);
|
2016-02-12 12:23:18 +01:00
|
|
|
CMakeConfig config;
|
2016-09-19 11:53:30 +02:00
|
|
|
// Qt4:
|
2016-03-16 13:39:41 +01:00
|
|
|
config << CMakeConfigItem(CMAKE_QMAKE_KEY, "%{Qt:qmakeExecutable}");
|
2016-09-19 11:53:30 +02:00
|
|
|
// Qt5:
|
|
|
|
|
config << CMakeConfigItem(CMAKE_PREFIX_PATH_KEY, "%{Qt:QT_INSTALL_LIBS}");
|
|
|
|
|
|
2016-07-18 02:08:25 -07:00
|
|
|
config << CMakeConfigItem(CMAKE_C_TOOLCHAIN_KEY, "%{Compiler:Executable:C}");
|
|
|
|
|
config << CMakeConfigItem(CMAKE_CXX_TOOLCHAIN_KEY, "%{Compiler:Executable:Cxx}");
|
2016-02-12 12:23:18 +01:00
|
|
|
|
2016-04-06 15:29:39 +02:00
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant CMakeConfigurationKitInformation::defaultValue(const Kit *k) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(k);
|
|
|
|
|
|
|
|
|
|
// FIXME: Convert preload scripts
|
|
|
|
|
CMakeConfig config = defaultConfiguration(k);
|
2016-02-12 12:23:18 +01:00
|
|
|
const QStringList tmp
|
|
|
|
|
= Utils::transform(config, [](const CMakeConfigItem &i) { return i.toString(); });
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Task> CMakeConfigurationKitInformation::validate(const Kit *k) const
|
|
|
|
|
{
|
|
|
|
|
const QtSupport::BaseQtVersion *const version = QtSupport::QtKitInformation::qtVersion(k);
|
2016-07-18 02:08:25 -07:00
|
|
|
const ToolChain *const tcC = ToolChainKitInformation::toolChain(k, ToolChain::Language::C);
|
|
|
|
|
const ToolChain *const tcCxx = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx);
|
2016-02-12 12:23:18 +01:00
|
|
|
const CMakeConfig config = configuration(k);
|
|
|
|
|
|
2016-09-19 11:53:30 +02:00
|
|
|
const bool isQt4 = version && version->qtVersion() < QtSupport::QtVersionNumber(5, 0, 0);
|
2016-07-18 02:08:25 -07:00
|
|
|
Utils::FileName qmakePath;
|
2016-09-19 11:53:30 +02:00
|
|
|
QStringList qtLibDirs;
|
2016-07-18 02:08:25 -07:00
|
|
|
Utils::FileName tcCPath;
|
|
|
|
|
Utils::FileName tcCxxPath;
|
2016-02-12 12:23:18 +01:00
|
|
|
foreach (const CMakeConfigItem &i, config) {
|
2016-03-16 13:39:41 +01:00
|
|
|
// Do not use expand(QByteArray) as we can not be sure the input is latin1
|
2016-07-18 02:08:25 -07:00
|
|
|
const Utils::FileName expandedValue
|
|
|
|
|
= Utils::FileName::fromString(k->macroExpander()->expand(QString::fromUtf8(i.value)));
|
2016-02-12 12:23:18 +01:00
|
|
|
if (i.key == CMAKE_QMAKE_KEY)
|
2016-03-16 13:39:41 +01:00
|
|
|
qmakePath = expandedValue;
|
2016-07-18 02:08:25 -07:00
|
|
|
else if (i.key == CMAKE_C_TOOLCHAIN_KEY)
|
|
|
|
|
tcCPath = expandedValue;
|
|
|
|
|
else if (i.key == CMAKE_CXX_TOOLCHAIN_KEY)
|
|
|
|
|
tcCxxPath = expandedValue;
|
2016-09-19 11:53:30 +02:00
|
|
|
else if (i.key == CMAKE_PREFIX_PATH_KEY)
|
|
|
|
|
qtLibDirs = CMakeConfigItem::cmakeSplitValue(expandedValue.toString());
|
2016-02-12 12:23:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Task> result;
|
|
|
|
|
// Validate Qt:
|
|
|
|
|
if (qmakePath.isEmpty()) {
|
2016-09-19 11:53:30 +02:00
|
|
|
if (version && version->isValid() && isQt4) {
|
2016-02-12 12:23:18 +01:00
|
|
|
result << Task(Task::Warning, tr("CMake configuration has no path to qmake binary set, "
|
|
|
|
|
"even though the kit has a valid Qt version."),
|
|
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!version || !version->isValid()) {
|
|
|
|
|
result << Task(Task::Warning, tr("CMake configuration has a path to a qmake binary set, "
|
|
|
|
|
"even though the kit has no valid Qt version."),
|
|
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
2016-09-19 11:53:30 +02:00
|
|
|
} else if (qmakePath != version->qmakeCommand() && isQt4) {
|
2016-07-25 15:27:18 +02:00
|
|
|
result << Task(Task::Warning, tr("CMake configuration has a path to a qmake binary set "
|
|
|
|
|
"that does not match the qmake binary path "
|
2016-02-12 12:23:18 +01:00
|
|
|
"configured in the Qt version."),
|
|
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
}
|
2016-09-19 11:53:30 +02:00
|
|
|
}
|
2016-09-30 11:35:12 +02:00
|
|
|
if (version && !qtLibDirs.contains(version->qmakeProperty("QT_INSTALL_LIBS")) && !isQt4) {
|
|
|
|
|
if (version->isValid()) {
|
2016-09-19 11:53:30 +02:00
|
|
|
result << Task(Task::Warning, tr("CMake configuration has no CMAKE_PREFIX_PATH set "
|
|
|
|
|
"that points to the kit Qt version."),
|
|
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
}
|
2016-02-12 12:23:18 +01:00
|
|
|
}
|
|
|
|
|
|
2016-07-18 02:08:25 -07:00
|
|
|
// Validate Toolchains:
|
|
|
|
|
if (tcCPath.isEmpty()) {
|
|
|
|
|
if (tcC && tcC->isValid()) {
|
|
|
|
|
result << Task(Task::Warning, tr("CMake configuration has no path to a C compiler set, "
|
|
|
|
|
"even though the kit has a valid tool chain."),
|
|
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!tcC || !tcC->isValid()) {
|
|
|
|
|
result << Task(Task::Warning, tr("CMake configuration has a path to a C compiler set, "
|
|
|
|
|
"even though the kit has no valid tool chain."),
|
|
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
} else if (tcCPath != tcC->compilerCommand()) {
|
2016-07-25 15:27:18 +02:00
|
|
|
result << Task(Task::Warning, tr("CMake configuration has a path to a C compiler set "
|
|
|
|
|
"that does not match the compiler path "
|
2016-07-18 02:08:25 -07:00
|
|
|
"configured in the tool chain of the kit."),
|
|
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tcCxxPath.isEmpty()) {
|
|
|
|
|
if (tcCxx && tcCxx->isValid()) {
|
2016-02-12 12:23:18 +01:00
|
|
|
result << Task(Task::Warning, tr("CMake configuration has no path to a C++ compiler set, "
|
|
|
|
|
"even though the kit has a valid tool chain."),
|
|
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2016-07-18 02:08:25 -07:00
|
|
|
if (!tcCxx || !tcCxx->isValid()) {
|
2016-02-12 12:23:18 +01:00
|
|
|
result << Task(Task::Warning, tr("CMake configuration has a path to a C++ compiler set, "
|
|
|
|
|
"even though the kit has no valid tool chain."),
|
|
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
2016-07-18 02:08:25 -07:00
|
|
|
} else if (tcCxxPath != tcCxx->compilerCommand()) {
|
2016-07-25 15:27:18 +02:00
|
|
|
result << Task(Task::Warning, tr("CMake configuration has a path to a C++ compiler set "
|
|
|
|
|
"that does not match the compiler path "
|
2016-02-12 12:23:18 +01:00
|
|
|
"configured in the tool chain of the kit."),
|
|
|
|
|
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeConfigurationKitInformation::setup(Kit *k)
|
|
|
|
|
{
|
|
|
|
|
if (k)
|
|
|
|
|
k->setValue(CONFIGURATION_ID, defaultValue(k));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeConfigurationKitInformation::fix(Kit *k)
|
|
|
|
|
{
|
2016-03-16 13:39:41 +01:00
|
|
|
Q_UNUSED(k);
|
2016-02-12 12:23:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KitInformation::ItemList CMakeConfigurationKitInformation::toUserOutput(const Kit *k) const
|
|
|
|
|
{
|
|
|
|
|
const QStringList current = toStringList(k);
|
|
|
|
|
return ItemList() << qMakePair(tr("CMake Configuration"), current.join(QLatin1String("<br>")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KitConfigWidget *CMakeConfigurationKitInformation::createConfigWidget(Kit *k) const
|
|
|
|
|
{
|
|
|
|
|
if (!k)
|
|
|
|
|
return 0;
|
|
|
|
|
return new Internal::CMakeConfigurationKitConfigWidget(k, this);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-24 21:57:00 +01:00
|
|
|
} // namespace CMakeProjectManager
|