2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2012-04-24 15:49:09 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-04-24 15:49:09 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-04-24 15:49:09 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
2012-04-24 15:49:09 +02: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.
|
2012-04-24 15:49:09 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
#include "qmakekitinformation.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2018-02-08 15:39:34 +01:00
|
|
|
#include "qmakeprojectmanagerconstants.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
|
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2013-03-25 17:13:18 +01:00
|
|
|
#include <projectexplorer/toolchain.h>
|
2012-12-17 16:26:14 +01:00
|
|
|
#include <projectexplorer/toolchainmanager.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2017-01-11 16:12:32 +01:00
|
|
|
#include <utils/algorithm.h>
|
2018-02-12 12:49:22 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2017-01-11 16:12:32 +01:00
|
|
|
|
2019-02-06 15:04:17 +01:00
|
|
|
#include <QLineEdit>
|
|
|
|
|
|
2013-08-29 13:14:19 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
2013-10-16 11:02:37 +02:00
|
|
|
namespace QmakeProjectManager {
|
2019-02-06 15:04:17 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class QmakeKitAspectWidget : public KitAspectWidget
|
|
|
|
|
{
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(QmakeProjectManager::Internal::QmakeKitAspect)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
QmakeKitAspectWidget(Kit *k, const KitAspect *ki)
|
|
|
|
|
: KitAspectWidget(k, ki), m_lineEdit(new QLineEdit)
|
|
|
|
|
{
|
|
|
|
|
refresh(); // set up everything according to kit
|
|
|
|
|
m_lineEdit->setToolTip(toolTip());
|
|
|
|
|
connect(m_lineEdit, &QLineEdit::textEdited, this, &QmakeKitAspectWidget::mkspecWasChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~QmakeKitAspectWidget() override { delete m_lineEdit; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QWidget *mainWidget() const override { return m_lineEdit; }
|
|
|
|
|
QString displayName() const override { return tr("Qt mkspec"); }
|
|
|
|
|
void makeReadOnly() override { m_lineEdit->setEnabled(false); }
|
|
|
|
|
|
|
|
|
|
QString toolTip() const override
|
|
|
|
|
{
|
|
|
|
|
return tr("The mkspec to use when building the project with qmake.<br>"
|
|
|
|
|
"This setting is ignored when using other build systems.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void refresh() override
|
|
|
|
|
{
|
|
|
|
|
if (!m_ignoreChange)
|
|
|
|
|
m_lineEdit->setText(QmakeKitAspect::mkspec(m_kit).toUserOutput());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mkspecWasChanged(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
m_ignoreChange = true;
|
|
|
|
|
QmakeKitAspect::setMkspec(m_kit, Utils::FileName::fromString(text));
|
|
|
|
|
m_ignoreChange = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLineEdit *m_lineEdit = nullptr;
|
|
|
|
|
bool m_ignoreChange = false;
|
|
|
|
|
};
|
|
|
|
|
|
2013-08-29 13:14:19 +02:00
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
QmakeKitAspect::QmakeKitAspect()
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2019-02-06 12:50:51 +01:00
|
|
|
setObjectName(QLatin1String("QmakeKitAspect"));
|
|
|
|
|
setId(QmakeKitAspect::id());
|
2013-08-28 18:57:25 +02:00
|
|
|
setPriority(24000);
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
QVariant QmakeKitAspect::defaultValue(const Kit *k) const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2012-09-03 18:31:44 +02:00
|
|
|
Q_UNUSED(k);
|
2012-06-20 15:43:01 +02:00
|
|
|
return QString();
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
QList<Task> QmakeKitAspect::validate(const Kit *k) const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2013-08-29 13:14:19 +02:00
|
|
|
QList<Task> result;
|
2019-02-06 12:50:51 +01:00
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitAspect::qtVersion(k);
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
FileName mkspec = QmakeKitAspect::mkspec(k);
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!version && !mkspec.isEmpty())
|
2013-08-29 13:14:19 +02:00
|
|
|
result << Task(Task::Warning, tr("No Qt version set, so mkspec is ignored."),
|
2018-02-08 15:39:34 +01:00
|
|
|
FileName(), -1, ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
|
2012-04-24 15:49:09 +02:00
|
|
|
if (version && !version->hasMkspec(mkspec))
|
2013-08-29 13:14:19 +02:00
|
|
|
result << Task(Task::Error, tr("Mkspec not found for Qt version."),
|
2018-02-08 15:39:34 +01:00
|
|
|
FileName(), -1, ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
|
2012-04-24 15:49:09 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void QmakeKitAspect::setup(Kit *k)
|
2012-12-17 16:26:14 +01:00
|
|
|
{
|
2019-02-06 12:50:51 +01:00
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitAspect::qtVersion(k);
|
2012-12-17 16:26:14 +01:00
|
|
|
if (!version)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-05-11 17:35:05 +03:00
|
|
|
// HACK: Ignore Boot2Qt kits!
|
|
|
|
|
if (version->type() == "Boot2Qt.QtVersionType" || version->type() == "Qdb.EmbeddedLinuxQt")
|
2016-12-14 11:32:24 +01:00
|
|
|
return;
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
FileName spec = QmakeKitAspect::mkspec(k);
|
2012-12-17 16:26:14 +01:00
|
|
|
if (spec.isEmpty())
|
|
|
|
|
spec = version->mkspec();
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
ToolChain *tc = ToolChainKitAspect::toolChain(k, ProjectExplorer::Constants::CXX_LANGUAGE_ID);
|
2012-12-17 16:26:14 +01:00
|
|
|
|
2013-08-15 13:17:18 +02:00
|
|
|
if (!tc || (!tc->suggestedMkspecList().empty() && !tc->suggestedMkspecList().contains(spec))) {
|
2017-09-07 17:05:47 +02:00
|
|
|
const QList<ToolChain *> possibleTcs = ToolChainManager::toolChains(
|
|
|
|
|
[version](const ToolChain *t) {
|
2017-01-11 16:12:32 +01:00
|
|
|
return t->isValid()
|
2018-02-08 15:39:34 +01:00
|
|
|
&& t->language() == Core::Id(ProjectExplorer::Constants::CXX_LANGUAGE_ID)
|
2017-01-11 16:12:32 +01:00
|
|
|
&& version->qtAbis().contains(t->targetAbi());
|
|
|
|
|
});
|
2017-03-09 13:30:53 +01:00
|
|
|
if (!possibleTcs.isEmpty()) {
|
2018-02-21 16:20:05 +01:00
|
|
|
const QList<ToolChain *> goodTcs = Utils::filtered(possibleTcs,
|
|
|
|
|
[&spec](const ToolChain *t) {
|
|
|
|
|
return t->suggestedMkspecList().contains(spec);
|
|
|
|
|
});
|
|
|
|
|
// Hack to prefer a tool chain from PATH (e.g. autodetected) over other matches.
|
|
|
|
|
// This improves the situation a bit if a cross-compilation tool chain has the
|
|
|
|
|
// same ABI as the host.
|
|
|
|
|
const Environment systemEnvironment = Environment::systemEnvironment();
|
|
|
|
|
ToolChain *bestTc = Utils::findOrDefault(goodTcs,
|
|
|
|
|
[&systemEnvironment](const ToolChain *t) {
|
2018-03-01 18:35:29 +01:00
|
|
|
return systemEnvironment.path().contains(t->compilerCommand().parentDir());
|
2018-02-21 16:20:05 +01:00
|
|
|
});
|
|
|
|
|
if (!bestTc) {
|
|
|
|
|
bestTc = goodTcs.isEmpty() ? possibleTcs.last() : goodTcs.last();
|
|
|
|
|
}
|
|
|
|
|
if (bestTc)
|
2019-02-06 12:50:51 +01:00
|
|
|
ToolChainKitAspect::setAllToolChainsToMatch(k, bestTc);
|
2017-03-09 13:30:53 +01:00
|
|
|
}
|
2012-12-17 16:26:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
KitAspectWidget *QmakeKitAspect::createConfigWidget(Kit *k) const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2019-02-06 12:50:51 +01:00
|
|
|
return new Internal::QmakeKitAspectWidget(k, this);
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
KitAspect::ItemList QmakeKitAspect::toUserOutput(const Kit *k) const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2012-09-03 18:31:44 +02:00
|
|
|
return ItemList() << qMakePair(tr("mkspec"), mkspec(k).toUserOutput());
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void QmakeKitAspect::addToMacroExpander(Kit *kit, MacroExpander *expander) const
|
2016-06-27 15:53:47 +02:00
|
|
|
{
|
|
|
|
|
expander->registerVariable("Qmake:mkspec", tr("Mkspec configured for qmake by the Kit."),
|
2017-09-07 17:05:47 +02:00
|
|
|
[kit]() -> QString {
|
2019-02-06 12:50:51 +01:00
|
|
|
return QmakeKitAspect::mkspec(kit).toUserOutput();
|
2016-06-27 15:53:47 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
Core::Id QmakeKitAspect::id()
|
2013-09-09 17:10:41 +02:00
|
|
|
{
|
2018-02-08 15:39:34 +01:00
|
|
|
return Constants::KIT_INFORMATION_ID;
|
2013-09-09 17:10:41 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
FileName QmakeKitAspect::mkspec(const Kit *k)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2012-09-03 18:31:44 +02:00
|
|
|
if (!k)
|
2013-08-29 13:14:19 +02:00
|
|
|
return FileName();
|
2019-02-06 12:50:51 +01:00
|
|
|
return FileName::fromString(k->value(QmakeKitAspect::id()).toString());
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
FileName QmakeKitAspect::effectiveMkspec(const Kit *k)
|
2012-06-20 15:43:01 +02:00
|
|
|
{
|
2012-09-03 18:31:44 +02:00
|
|
|
if (!k)
|
2013-08-29 13:14:19 +02:00
|
|
|
return FileName();
|
|
|
|
|
FileName spec = mkspec(k);
|
2012-06-20 15:43:01 +02:00
|
|
|
if (spec.isEmpty())
|
2012-09-03 18:31:44 +02:00
|
|
|
return defaultMkspec(k);
|
2012-06-20 15:43:01 +02:00
|
|
|
return spec;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void QmakeKitAspect::setMkspec(Kit *k, const FileName &fn)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2018-02-12 12:49:22 +01:00
|
|
|
QTC_ASSERT(k, return);
|
2019-02-06 12:50:51 +01:00
|
|
|
k->setValue(QmakeKitAspect::id(), fn == defaultMkspec(k) ? QString() : fn.toString());
|
2012-06-20 15:43:01 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
FileName QmakeKitAspect::defaultMkspec(const Kit *k)
|
2012-06-20 15:43:01 +02:00
|
|
|
{
|
2019-02-06 12:50:51 +01:00
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitAspect::qtVersion(k);
|
2012-06-20 15:43:01 +02:00
|
|
|
if (!version) // No version, so no qmake
|
2013-08-29 13:14:19 +02:00
|
|
|
return FileName();
|
2012-06-20 15:43:01 +02:00
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
return version->mkspecFor(ToolChainKitAspect::toolChain(k,
|
2018-02-08 15:39:34 +01:00
|
|
|
ProjectExplorer::Constants::CXX_LANGUAGE_ID));
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 15:04:17 +01:00
|
|
|
} // namespace Internal
|
2013-10-16 11:02:37 +02:00
|
|
|
} // namespace QmakeProjectManager
|