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"
|
2020-04-17 15:30:05 +02:00
|
|
|
|
2017-04-03 14:31:32 +02:00
|
|
|
#include "cmakeprojectconstants.h"
|
2020-03-03 12:23:04 +01:00
|
|
|
#include "cmakeprojectplugin.h"
|
|
|
|
|
#include "cmakespecificsettings.h"
|
2015-02-24 21:57:00 +01:00
|
|
|
#include "cmaketool.h"
|
2020-03-03 12:23:04 +01:00
|
|
|
#include "cmaketoolmanager.h"
|
2015-02-24 21:57:00 +01:00
|
|
|
|
2021-04-12 10:58:54 +02:00
|
|
|
#include <app/app_version.h>
|
|
|
|
|
|
2021-04-23 11:59:23 +02:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
2021-02-02 16:10:45 +01:00
|
|
|
#include <ios/iosconstants.h>
|
2021-04-12 10:58:54 +02:00
|
|
|
|
2016-02-12 12:23:18 +01:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
2020-04-17 08:53:16 +02:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2021-02-02 16:10:45 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2020-04-17 08:53:16 +02:00
|
|
|
#include <projectexplorer/projectexplorersettings.h>
|
|
|
|
|
#include <projectexplorer/task.h>
|
|
|
|
|
#include <projectexplorer/toolchain.h>
|
Add workarounds for running under Rosetta on macOS
When Qt Creator is built as an Intel binary, and runs on
an Apple Silicon (ARM) Mac, it will be run via the Rosetta
translation layer. This means any process spawned by QtC,
including qmake, CMake, and lldb, will launch as x86_64
binaries as well.
For qmake and CMake, this affects their default choice of
build architecture, resulting in x86_64 builds of user
applications. We want to produce native arm64 apps, even
if Qt Creator itself isn't one, so we explicitly detect
the situation, and if Qt has an arm64 slice, we default
to arm64 builds.
The logic of adding CONFIG+=x86_64 to the qmake step has
been disabled, as the assumption that a single qmake run
and build will produce only a single architecture does no
longer hold. The corresponding logic in Qt was removed
in 2015 (qtbase f58e95f098c8d78a5f2db7729606126fe093cbdf).
In the case of lldb, running it as an x86_64 binary fails
to attach to the running application. We work around this
by using the 'arch' tool to explicitly launch it as an
arm64 binary. This works for debugging both arm64 and
x86_64 applications.
Change-Id: I65cc0f600223990f25c76cef18d927895e551260
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2021-06-22 00:11:58 +02:00
|
|
|
#include <projectexplorer/devicesupport/idevice.h>
|
2021-04-12 10:58:54 +02:00
|
|
|
|
2016-09-19 11:53:30 +02:00
|
|
|
#include <qtsupport/baseqtversion.h>
|
2016-02-12 12:23:18 +01:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2020-04-17 15:30:05 +02:00
|
|
|
|
2016-02-12 12:23:18 +01:00
|
|
|
#include <utils/algorithm.h>
|
2019-02-06 15:04:17 +01:00
|
|
|
#include <utils/elidinglabel.h>
|
2016-02-29 14:26:50 +01:00
|
|
|
#include <utils/environment.h>
|
2021-04-07 18:55:21 +02:00
|
|
|
#include <utils/layoutbuilder.h>
|
2020-04-17 15:30:05 +02:00
|
|
|
#include <utils/macroexpander.h>
|
2016-02-12 12:10:28 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2020-09-18 12:11:40 +02:00
|
|
|
#include <utils/variablechooser.h>
|
2015-02-24 21:57:00 +01:00
|
|
|
|
2019-02-06 15:04:17 +01:00
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QDialog>
|
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
|
#include <QGridLayout>
|
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
|
#include <QPointer>
|
|
|
|
|
#include <QPushButton>
|
2016-09-19 11:53:30 +02:00
|
|
|
|
2015-02-24 21:57:00 +01:00
|
|
|
using namespace ProjectExplorer;
|
2021-06-01 18:26:35 +02:00
|
|
|
using namespace Utils;
|
2015-02-24 21:57:00 +01:00
|
|
|
|
|
|
|
|
namespace CMakeProjectManager {
|
2016-02-04 18:09:31 +01:00
|
|
|
// --------------------------------------------------------------------
|
2019-02-06 12:50:51 +01:00
|
|
|
// CMakeKitAspect:
|
2016-02-04 18:09:31 +01:00
|
|
|
// --------------------------------------------------------------------
|
2015-02-24 21:57:00 +01:00
|
|
|
|
2021-02-02 16:10:45 +01:00
|
|
|
static bool isIos(const Kit *k)
|
|
|
|
|
{
|
2021-06-01 18:26:35 +02:00
|
|
|
const Id deviceType = DeviceTypeKitAspect::deviceTypeId(k);
|
2021-02-02 16:10:45 +01:00
|
|
|
return deviceType == Ios::Constants::IOS_DEVICE_TYPE
|
|
|
|
|
|| deviceType == Ios::Constants::IOS_SIMULATOR_TYPE;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
static Id defaultCMakeToolId()
|
2016-02-04 17:52:55 +01:00
|
|
|
{
|
|
|
|
|
CMakeTool *defaultTool = CMakeToolManager::defaultCMakeTool();
|
2021-06-01 18:26:35 +02:00
|
|
|
return defaultTool ? defaultTool->id() : Id();
|
2016-02-04 17:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
const char TOOL_ID[] = "CMakeProjectManager.CMakeKitInformation";
|
2016-02-04 18:09:31 +01:00
|
|
|
|
2020-11-18 17:04:54 +01:00
|
|
|
class CMakeKitAspectWidget final : public KitAspectWidget
|
2019-02-06 15:04:17 +01:00
|
|
|
{
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(CMakeProjectManager::Internal::CMakeKitAspect)
|
|
|
|
|
public:
|
|
|
|
|
CMakeKitAspectWidget(Kit *kit, const KitAspect *ki) : KitAspectWidget(kit, ki),
|
2021-04-07 18:55:21 +02:00
|
|
|
m_comboBox(createSubWidget<QComboBox>()),
|
2021-04-12 10:58:54 +02:00
|
|
|
m_manageButton(createManageButton(Constants::CMAKE_SETTINGS_PAGE_ID))
|
2019-02-06 15:04:17 +01:00
|
|
|
{
|
|
|
|
|
m_comboBox->setSizePolicy(QSizePolicy::Ignored, m_comboBox->sizePolicy().verticalPolicy());
|
|
|
|
|
m_comboBox->setEnabled(false);
|
2019-02-11 17:10:03 +01:00
|
|
|
m_comboBox->setToolTip(ki->description());
|
2019-02-06 15:04:17 +01:00
|
|
|
|
|
|
|
|
foreach (CMakeTool *tool, CMakeToolManager::cmakeTools())
|
|
|
|
|
cmakeToolAdded(tool->id());
|
|
|
|
|
|
|
|
|
|
updateComboBox();
|
|
|
|
|
refresh();
|
2019-05-27 23:28:48 +02:00
|
|
|
connect(m_comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
2019-02-06 15:04:17 +01:00
|
|
|
this, &CMakeKitAspectWidget::currentCMakeToolChanged);
|
|
|
|
|
|
|
|
|
|
CMakeToolManager *cmakeMgr = CMakeToolManager::instance();
|
|
|
|
|
connect(cmakeMgr, &CMakeToolManager::cmakeAdded,
|
|
|
|
|
this, &CMakeKitAspectWidget::cmakeToolAdded);
|
|
|
|
|
connect(cmakeMgr, &CMakeToolManager::cmakeRemoved,
|
|
|
|
|
this, &CMakeKitAspectWidget::cmakeToolRemoved);
|
|
|
|
|
connect(cmakeMgr, &CMakeToolManager::cmakeUpdated,
|
|
|
|
|
this, &CMakeKitAspectWidget::cmakeToolUpdated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~CMakeKitAspectWidget() override
|
|
|
|
|
{
|
|
|
|
|
delete m_comboBox;
|
|
|
|
|
delete m_manageButton;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// KitAspectWidget interface
|
|
|
|
|
void makeReadOnly() override { m_comboBox->setEnabled(false); }
|
2021-04-07 18:55:21 +02:00
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
void addToLayout(LayoutBuilder &builder) override
|
2021-04-07 18:55:21 +02:00
|
|
|
{
|
|
|
|
|
addMutableAction(m_comboBox);
|
|
|
|
|
builder.addItem(m_comboBox);
|
|
|
|
|
builder.addItem(m_manageButton);
|
|
|
|
|
}
|
2019-02-06 15:04:17 +01:00
|
|
|
|
|
|
|
|
void refresh() override
|
|
|
|
|
{
|
|
|
|
|
CMakeTool *tool = CMakeKitAspect::cmakeTool(m_kit);
|
|
|
|
|
m_comboBox->setCurrentIndex(tool ? indexOf(tool->id()) : -1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
int indexOf(Id id)
|
2019-02-06 15:04:17 +01:00
|
|
|
{
|
|
|
|
|
for (int i = 0; i < m_comboBox->count(); ++i) {
|
2021-06-01 18:26:35 +02:00
|
|
|
if (id == Id::fromSetting(m_comboBox->itemData(i)))
|
2019-02-06 15:04:17 +01:00
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateComboBox()
|
|
|
|
|
{
|
|
|
|
|
// remove unavailable cmake tool:
|
2021-06-01 18:26:35 +02:00
|
|
|
int pos = indexOf(Id());
|
2019-02-06 15:04:17 +01:00
|
|
|
if (pos >= 0)
|
|
|
|
|
m_comboBox->removeItem(pos);
|
|
|
|
|
|
|
|
|
|
if (m_comboBox->count() == 0) {
|
2021-06-01 18:26:35 +02:00
|
|
|
m_comboBox->addItem(tr("<No CMake Tool available>"), Id().toSetting());
|
2019-02-06 15:04:17 +01:00
|
|
|
m_comboBox->setEnabled(false);
|
|
|
|
|
} else {
|
|
|
|
|
m_comboBox->setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
void cmakeToolAdded(Id id)
|
2019-02-06 15:04:17 +01:00
|
|
|
{
|
|
|
|
|
const CMakeTool *tool = CMakeToolManager::findById(id);
|
|
|
|
|
QTC_ASSERT(tool, return);
|
|
|
|
|
|
|
|
|
|
m_comboBox->addItem(tool->displayName(), tool->id().toSetting());
|
|
|
|
|
updateComboBox();
|
|
|
|
|
refresh();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
void cmakeToolUpdated(Id id)
|
2019-02-06 15:04:17 +01:00
|
|
|
{
|
|
|
|
|
const int pos = indexOf(id);
|
|
|
|
|
QTC_ASSERT(pos >= 0, return);
|
|
|
|
|
|
|
|
|
|
const CMakeTool *tool = CMakeToolManager::findById(id);
|
|
|
|
|
QTC_ASSERT(tool, return);
|
|
|
|
|
|
|
|
|
|
m_comboBox->setItemText(pos, tool->displayName());
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
void cmakeToolRemoved(Id id)
|
2019-02-06 15:04:17 +01:00
|
|
|
{
|
|
|
|
|
const int pos = indexOf(id);
|
|
|
|
|
QTC_ASSERT(pos >= 0, return);
|
|
|
|
|
|
|
|
|
|
// do not handle the current index changed signal
|
|
|
|
|
m_removingItem = true;
|
|
|
|
|
m_comboBox->removeItem(pos);
|
|
|
|
|
m_removingItem = false;
|
|
|
|
|
|
|
|
|
|
// update the checkbox and set the current index
|
|
|
|
|
updateComboBox();
|
|
|
|
|
refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void currentCMakeToolChanged(int index)
|
|
|
|
|
{
|
|
|
|
|
if (m_removingItem)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
const Id id = Id::fromSetting(m_comboBox->itemData(index));
|
2019-02-06 15:04:17 +01:00
|
|
|
CMakeKitAspect::setCMakeTool(m_kit, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool m_removingItem = false;
|
|
|
|
|
QComboBox *m_comboBox;
|
2021-04-12 10:58:54 +02:00
|
|
|
QWidget *m_manageButton;
|
2019-02-06 15:04:17 +01:00
|
|
|
};
|
2016-01-22 17:17:36 +01:00
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
CMakeKitAspect::CMakeKitAspect()
|
2015-02-24 21:57:00 +01:00
|
|
|
{
|
2019-02-06 12:50:51 +01:00
|
|
|
setObjectName(QLatin1String("CMakeKitAspect"));
|
2016-02-04 18:09:31 +01:00
|
|
|
setId(TOOL_ID);
|
2019-02-06 16:16:07 +01:00
|
|
|
setDisplayName(tr("CMake Tool"));
|
|
|
|
|
setDescription(tr("The CMake Tool to use when building a project with CMake.<br>"
|
|
|
|
|
"This setting is ignored when using other build systems."));
|
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,
|
2021-06-01 18:26:35 +02:00
|
|
|
[this] { for (Kit *k : KitManager::kits()) fix(k); });
|
2015-02-24 21:57:00 +01:00
|
|
|
|
|
|
|
|
//make sure the default value is set if a new default CMake is set
|
|
|
|
|
connect(CMakeToolManager::instance(), &CMakeToolManager::defaultCMakeChanged,
|
2021-06-01 18:26:35 +02:00
|
|
|
[this] { for (Kit *k : KitManager::kits()) fix(k); });
|
2015-02-24 21:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
Id CMakeKitAspect::id()
|
2016-08-25 14:33:44 +02:00
|
|
|
{
|
|
|
|
|
return TOOL_ID;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
Id CMakeKitAspect::cmakeToolId(const Kit *k)
|
2015-02-24 21:57:00 +01:00
|
|
|
{
|
|
|
|
|
if (!k)
|
2018-05-24 16:57:31 +02:00
|
|
|
return {};
|
2021-06-01 18:26:35 +02:00
|
|
|
return Id::fromSetting(k->value(TOOL_ID));
|
2018-05-24 16:57:31 +02:00
|
|
|
}
|
2015-02-24 21:57:00 +01:00
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
CMakeTool *CMakeKitAspect::cmakeTool(const Kit *k)
|
2018-05-24 16:57:31 +02:00
|
|
|
{
|
|
|
|
|
return CMakeToolManager::findById(cmakeToolId(k));
|
2015-02-24 21:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
void CMakeKitAspect::setCMakeTool(Kit *k, const Id id)
|
2015-02-24 21:57:00 +01:00
|
|
|
{
|
2021-06-01 18:26:35 +02:00
|
|
|
const Id toSet = id.isValid() ? id : defaultCMakeToolId();
|
2016-02-04 18:09:31 +01:00
|
|
|
QTC_ASSERT(!id.isValid() || CMakeToolManager::findById(toSet), return);
|
|
|
|
|
if (k)
|
|
|
|
|
k->setValue(TOOL_ID, toSet.toSetting());
|
2015-02-24 21:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-27 16:09:44 +02:00
|
|
|
Tasks CMakeKitAspect::validate(const Kit *k) const
|
2015-02-24 21:57:00 +01:00
|
|
|
{
|
2019-05-27 16:09:44 +02:00
|
|
|
Tasks result;
|
2019-02-06 12:50:51 +01:00
|
|
|
CMakeTool *tool = CMakeKitAspect::cmakeTool(k);
|
2016-09-28 17:26:02 +02:00
|
|
|
if (tool) {
|
|
|
|
|
CMakeTool::Version version = tool->version();
|
2020-04-03 11:16:48 +02:00
|
|
|
if (version.major < 3 || (version.major == 3 && version.minor < 14)) {
|
2020-11-19 09:45:55 +01:00
|
|
|
result << BuildSystemTask(Task::Warning, msgUnsupportedVersion(version.fullVersion));
|
2016-09-28 17:26:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2015-02-24 21:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void CMakeKitAspect::setup(Kit *k)
|
2015-02-24 21:57:00 +01:00
|
|
|
{
|
2019-02-06 12:50:51 +01:00
|
|
|
CMakeTool *tool = CMakeKitAspect::cmakeTool(k);
|
2021-06-22 14:08:20 +02:00
|
|
|
if (tool)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Look for a suitable auto-detected one:
|
2021-07-13 13:05:36 +02:00
|
|
|
const QString kitSource = k->autoDetectionSource();
|
2021-06-22 14:08:20 +02:00
|
|
|
for (CMakeTool *tool : CMakeToolManager::cmakeTools()) {
|
2021-07-13 13:05:36 +02:00
|
|
|
const QString toolSource = tool->detectionSource();
|
|
|
|
|
if (!toolSource.isEmpty() && toolSource == kitSource) {
|
2021-06-22 14:08:20 +02:00
|
|
|
setCMakeTool(k, tool->id());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setCMakeTool(k, defaultCMakeToolId());
|
2015-02-24 21:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void CMakeKitAspect::fix(Kit *k)
|
2015-02-24 21:57:00 +01:00
|
|
|
{
|
2019-03-12 16:50:39 +01:00
|
|
|
setup(k);
|
2015-02-24 21:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
KitAspect::ItemList CMakeKitAspect::toUserOutput(const Kit *k) const
|
2015-02-24 21:57:00 +01:00
|
|
|
{
|
2016-02-04 18:09:31 +01:00
|
|
|
const CMakeTool *const tool = cmakeTool(k);
|
2019-05-28 08:28:51 +02:00
|
|
|
return {{tr("CMake"), tool ? tool->displayName() : tr("Unconfigured")}};
|
2015-02-24 21:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
KitAspectWidget *CMakeKitAspect::createConfigWidget(Kit *k) const
|
2015-02-24 21:57:00 +01:00
|
|
|
{
|
2018-02-12 12:49:22 +01:00
|
|
|
QTC_ASSERT(k, return nullptr);
|
2019-02-06 15:04:17 +01:00
|
|
|
return new CMakeKitAspectWidget(k, this);
|
2015-02-24 21:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
void CMakeKitAspect::addToMacroExpander(Kit *k, MacroExpander *expander) const
|
2015-11-23 12:45:47 +01:00
|
|
|
{
|
2018-02-12 12:49:22 +01:00
|
|
|
QTC_ASSERT(k, return);
|
2015-11-23 12:45:47 +01:00
|
|
|
expander->registerFileVariables("CMake:Executable", tr("Path to the cmake executable"),
|
2021-06-01 18:18:02 +02:00
|
|
|
[k] {
|
|
|
|
|
CMakeTool *tool = CMakeKitAspect::cmakeTool(k);
|
2021-06-01 18:26:35 +02:00
|
|
|
return tool ? tool->cmakeExecutable() : FilePath();
|
2021-06-01 18:18:02 +02:00
|
|
|
});
|
2017-04-03 14:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
QSet<Id> CMakeKitAspect::availableFeatures(const Kit *k) const
|
2017-04-03 14:31:32 +02:00
|
|
|
{
|
|
|
|
|
if (cmakeTool(k))
|
|
|
|
|
return { CMakeProjectManager::Constants::CMAKE_FEATURE_ID };
|
|
|
|
|
return {};
|
2015-11-23 12:45:47 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-19 09:45:55 +01:00
|
|
|
QString CMakeKitAspect::msgUnsupportedVersion(const QByteArray &versionString)
|
|
|
|
|
{
|
|
|
|
|
return tr("CMake version %1 is unsupported. Please update to "
|
|
|
|
|
"version 3.14 (with file-api) or later.")
|
|
|
|
|
.arg(QString::fromUtf8(versionString));
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-22 17:17:36 +01:00
|
|
|
// --------------------------------------------------------------------
|
2019-02-06 12:50:51 +01:00
|
|
|
// CMakeGeneratorKitAspect:
|
2016-01-22 17:17:36 +01:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
const char GENERATOR_ID[] = "CMake.GeneratorKitInformation";
|
2016-01-22 17:17:36 +01:00
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
const char GENERATOR_KEY[] = "Generator";
|
|
|
|
|
const char EXTRA_GENERATOR_KEY[] = "ExtraGenerator";
|
|
|
|
|
const char PLATFORM_KEY[] = "Platform";
|
|
|
|
|
const char TOOLSET_KEY[] = "Toolset";
|
2016-09-27 13:26:54 +02:00
|
|
|
|
2020-11-18 17:04:54 +01:00
|
|
|
class CMakeGeneratorKitAspectWidget final : public KitAspectWidget
|
2019-02-06 15:04:17 +01:00
|
|
|
{
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(CMakeProjectManager::Internal::CMakeGeneratorKitAspect)
|
2021-06-01 18:26:35 +02:00
|
|
|
|
2019-02-06 15:04:17 +01:00
|
|
|
public:
|
2021-06-01 18:26:35 +02:00
|
|
|
CMakeGeneratorKitAspectWidget(Kit *kit, const KitAspect *ki)
|
2019-02-06 15:04:17 +01:00
|
|
|
: KitAspectWidget(kit, ki),
|
2021-06-01 18:26:35 +02:00
|
|
|
m_label(createSubWidget<ElidingLabel>()),
|
2021-04-07 18:55:21 +02:00
|
|
|
m_changeButton(createSubWidget<QPushButton>())
|
2019-02-06 15:04:17 +01:00
|
|
|
{
|
2019-02-11 17:10:03 +01:00
|
|
|
m_label->setToolTip(ki->description());
|
2019-02-06 15:04:17 +01:00
|
|
|
m_changeButton->setText(tr("Change..."));
|
|
|
|
|
refresh();
|
|
|
|
|
connect(m_changeButton, &QPushButton::clicked,
|
|
|
|
|
this, &CMakeGeneratorKitAspectWidget::changeGenerator);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~CMakeGeneratorKitAspectWidget() override
|
|
|
|
|
{
|
|
|
|
|
delete m_label;
|
|
|
|
|
delete m_changeButton;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// KitAspectWidget interface
|
|
|
|
|
void makeReadOnly() override { m_changeButton->setEnabled(false); }
|
2021-04-07 18:55:21 +02:00
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
void addToLayout(LayoutBuilder &builder) override
|
2021-04-07 18:55:21 +02:00
|
|
|
{
|
|
|
|
|
addMutableAction(m_label);
|
|
|
|
|
builder.addItem(m_label);
|
|
|
|
|
builder.addItem(m_changeButton);
|
|
|
|
|
}
|
2019-02-06 15:04:17 +01:00
|
|
|
|
|
|
|
|
void refresh() override
|
|
|
|
|
{
|
|
|
|
|
if (m_ignoreChange)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CMakeTool *const tool = CMakeKitAspect::cmakeTool(m_kit);
|
|
|
|
|
if (tool != m_currentTool)
|
|
|
|
|
m_currentTool = tool;
|
|
|
|
|
|
|
|
|
|
m_changeButton->setEnabled(m_currentTool);
|
|
|
|
|
const QString generator = CMakeGeneratorKitAspect::generator(kit());
|
|
|
|
|
const QString extraGenerator = CMakeGeneratorKitAspect::extraGenerator(kit());
|
|
|
|
|
const QString platform = CMakeGeneratorKitAspect::platform(kit());
|
|
|
|
|
const QString toolset = CMakeGeneratorKitAspect::toolset(kit());
|
|
|
|
|
|
|
|
|
|
const QString message = tr("%1 - %2, Platform: %3, Toolset: %4")
|
|
|
|
|
.arg(extraGenerator.isEmpty() ? tr("<none>") : extraGenerator)
|
|
|
|
|
.arg(generator.isEmpty() ? tr("<none>") : generator)
|
|
|
|
|
.arg(platform.isEmpty() ? tr("<none>") : platform)
|
|
|
|
|
.arg(toolset.isEmpty() ? tr("<none>") : toolset);
|
|
|
|
|
m_label->setText(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void changeGenerator()
|
|
|
|
|
{
|
|
|
|
|
QPointer<QDialog> changeDialog = new QDialog(m_changeButton);
|
|
|
|
|
|
|
|
|
|
// Disable help button in titlebar on windows:
|
|
|
|
|
Qt::WindowFlags flags = changeDialog->windowFlags();
|
|
|
|
|
flags |= Qt::MSWindowsFixedSizeDialogHint;
|
|
|
|
|
changeDialog->setWindowFlags(flags);
|
|
|
|
|
|
|
|
|
|
changeDialog->setWindowTitle(tr("CMake Generator"));
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
auto layout = new QGridLayout(changeDialog);
|
2019-02-06 15:04:17 +01:00
|
|
|
layout->setSizeConstraint(QLayout::SetFixedSize);
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
auto cmakeLabel = new QLabel;
|
2019-02-06 15:04:17 +01:00
|
|
|
cmakeLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
auto generatorCombo = new QComboBox;
|
|
|
|
|
auto extraGeneratorCombo = new QComboBox;
|
|
|
|
|
auto platformEdit = new QLineEdit;
|
|
|
|
|
auto toolsetEdit = new QLineEdit;
|
2019-02-06 15:04:17 +01:00
|
|
|
|
|
|
|
|
int row = 0;
|
|
|
|
|
layout->addWidget(new QLabel(QLatin1String("Executable:")));
|
|
|
|
|
layout->addWidget(cmakeLabel, row, 1);
|
|
|
|
|
|
|
|
|
|
++row;
|
|
|
|
|
layout->addWidget(new QLabel(tr("Generator:")), row, 0);
|
|
|
|
|
layout->addWidget(generatorCombo, row, 1);
|
|
|
|
|
|
|
|
|
|
++row;
|
|
|
|
|
layout->addWidget(new QLabel(tr("Extra generator:")), row, 0);
|
|
|
|
|
layout->addWidget(extraGeneratorCombo, row, 1);
|
|
|
|
|
|
|
|
|
|
++row;
|
|
|
|
|
layout->addWidget(new QLabel(tr("Platform:")), row, 0);
|
|
|
|
|
layout->addWidget(platformEdit, row, 1);
|
|
|
|
|
|
|
|
|
|
++row;
|
|
|
|
|
layout->addWidget(new QLabel(tr("Toolset:")), row, 0);
|
|
|
|
|
layout->addWidget(toolsetEdit, row, 1);
|
|
|
|
|
|
|
|
|
|
++row;
|
2021-06-01 18:26:35 +02:00
|
|
|
auto bb = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
|
2019-02-06 15:04:17 +01:00
|
|
|
layout->addWidget(bb, row, 0, 1, 2);
|
|
|
|
|
|
|
|
|
|
connect(bb, &QDialogButtonBox::accepted, changeDialog.data(), &QDialog::accept);
|
|
|
|
|
connect(bb, &QDialogButtonBox::rejected, changeDialog.data(), &QDialog::reject);
|
|
|
|
|
|
|
|
|
|
cmakeLabel->setText(m_currentTool->cmakeExecutable().toUserOutput());
|
|
|
|
|
|
|
|
|
|
QList<CMakeTool::Generator> generatorList = m_currentTool->supportedGenerators();
|
|
|
|
|
Utils::sort(generatorList, &CMakeTool::Generator::name);
|
|
|
|
|
|
|
|
|
|
for (auto it = generatorList.constBegin(); it != generatorList.constEnd(); ++it)
|
|
|
|
|
generatorCombo->addItem(it->name);
|
|
|
|
|
|
|
|
|
|
auto updateDialog = [&generatorList, generatorCombo, extraGeneratorCombo,
|
|
|
|
|
platformEdit, toolsetEdit](const QString &name) {
|
2020-11-18 13:06:55 +01:00
|
|
|
const auto it = std::find_if(generatorList.constBegin(), generatorList.constEnd(),
|
2019-02-06 15:04:17 +01:00
|
|
|
[name](const CMakeTool::Generator &g) { return g.name == name; });
|
|
|
|
|
QTC_ASSERT(it != generatorList.constEnd(), return);
|
|
|
|
|
generatorCombo->setCurrentText(name);
|
|
|
|
|
|
|
|
|
|
extraGeneratorCombo->clear();
|
|
|
|
|
extraGeneratorCombo->addItem(tr("<none>"), QString());
|
2021-06-01 18:26:35 +02:00
|
|
|
for (const QString &eg : qAsConst(it->extraGenerators))
|
2019-02-06 15:04:17 +01:00
|
|
|
extraGeneratorCombo->addItem(eg, eg);
|
|
|
|
|
extraGeneratorCombo->setEnabled(extraGeneratorCombo->count() > 1);
|
|
|
|
|
|
|
|
|
|
platformEdit->setEnabled(it->supportsPlatform);
|
|
|
|
|
toolsetEdit->setEnabled(it->supportsToolset);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
updateDialog(CMakeGeneratorKitAspect::generator(kit()));
|
|
|
|
|
|
|
|
|
|
generatorCombo->setCurrentText(CMakeGeneratorKitAspect::generator(kit()));
|
|
|
|
|
extraGeneratorCombo->setCurrentText(CMakeGeneratorKitAspect::extraGenerator(kit()));
|
2021-01-14 16:38:55 +01:00
|
|
|
platformEdit->setText(platformEdit->isEnabled() ? CMakeGeneratorKitAspect::platform(kit()) : QString());
|
|
|
|
|
toolsetEdit->setText(toolsetEdit->isEnabled() ? CMakeGeneratorKitAspect::toolset(kit()) : QString());
|
2019-02-06 15:04:17 +01:00
|
|
|
|
|
|
|
|
connect(generatorCombo, &QComboBox::currentTextChanged, updateDialog);
|
|
|
|
|
|
|
|
|
|
if (changeDialog->exec() == QDialog::Accepted) {
|
|
|
|
|
if (!changeDialog)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CMakeGeneratorKitAspect::set(kit(), generatorCombo->currentText(),
|
|
|
|
|
extraGeneratorCombo->currentData().toString(),
|
|
|
|
|
platformEdit->isEnabled() ? platformEdit->text() : QString(),
|
|
|
|
|
toolsetEdit->isEnabled() ? toolsetEdit->text() : QString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool m_ignoreChange = false;
|
2021-06-01 18:26:35 +02:00
|
|
|
ElidingLabel *m_label;
|
2019-02-06 15:04:17 +01:00
|
|
|
QPushButton *m_changeButton;
|
|
|
|
|
CMakeTool *m_currentTool = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-27 13:26:54 +02:00
|
|
|
namespace {
|
|
|
|
|
|
2020-03-05 10:34:35 +01:00
|
|
|
class GeneratorInfo
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
GeneratorInfo() = default;
|
|
|
|
|
GeneratorInfo(const QString &generator_,
|
|
|
|
|
const QString &extraGenerator_ = QString(),
|
|
|
|
|
const QString &platform_ = QString(),
|
|
|
|
|
const QString &toolset_ = QString())
|
|
|
|
|
: generator(generator_)
|
|
|
|
|
, extraGenerator(extraGenerator_)
|
|
|
|
|
, platform(platform_)
|
|
|
|
|
, toolset(toolset_)
|
|
|
|
|
{}
|
|
|
|
|
|
2016-09-27 13:26:54 +02:00
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
CMakeGeneratorKitAspect::CMakeGeneratorKitAspect()
|
2016-01-22 17:17:36 +01:00
|
|
|
{
|
2019-02-06 12:50:51 +01:00
|
|
|
setObjectName(QLatin1String("CMakeGeneratorKitAspect"));
|
2016-01-22 17:17:36 +01:00
|
|
|
setId(GENERATOR_ID);
|
2019-02-06 16:16:07 +01:00
|
|
|
setDisplayName(tr("CMake generator"));
|
|
|
|
|
setDescription(tr("CMake generator defines how a project is built when using CMake.<br>"
|
|
|
|
|
"This setting is ignored when using other build systems."));
|
2016-01-22 17:17:36 +01:00
|
|
|
setPriority(19000);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
QString CMakeGeneratorKitAspect::generator(const Kit *k)
|
2016-01-22 17:17:36 +01:00
|
|
|
{
|
2016-09-27 13:26:54 +02:00
|
|
|
return generatorInfo(k).generator;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
QString CMakeGeneratorKitAspect::extraGenerator(const Kit *k)
|
2016-09-27 13:26:54 +02:00
|
|
|
{
|
|
|
|
|
return generatorInfo(k).extraGenerator;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
QString CMakeGeneratorKitAspect::platform(const Kit *k)
|
2016-09-27 13:26:54 +02:00
|
|
|
{
|
|
|
|
|
return generatorInfo(k).platform;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
QString CMakeGeneratorKitAspect::toolset(const Kit *k)
|
2016-09-27 13:26:54 +02:00
|
|
|
{
|
|
|
|
|
return generatorInfo(k).toolset;
|
2016-01-22 17:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void CMakeGeneratorKitAspect::setGenerator(Kit *k, const QString &generator)
|
2016-01-22 17:17:36 +01:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void CMakeGeneratorKitAspect::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);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void CMakeGeneratorKitAspect::setPlatform(Kit *k, const QString &platform)
|
2016-09-27 13:26:54 +02:00
|
|
|
{
|
|
|
|
|
GeneratorInfo info = generatorInfo(k);
|
|
|
|
|
info.platform = platform;
|
|
|
|
|
setGeneratorInfo(k, info);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void CMakeGeneratorKitAspect::setToolset(Kit *k, const QString &toolset)
|
2016-09-27 13:26:54 +02:00
|
|
|
{
|
|
|
|
|
GeneratorInfo info = generatorInfo(k);
|
|
|
|
|
info.toolset = toolset;
|
|
|
|
|
setGeneratorInfo(k, info);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void CMakeGeneratorKitAspect::set(Kit *k,
|
2020-03-05 10:34:35 +01:00
|
|
|
const QString &generator,
|
|
|
|
|
const QString &extraGenerator,
|
|
|
|
|
const QString &platform,
|
|
|
|
|
const QString &toolset)
|
2016-09-28 12:24:06 +02:00
|
|
|
{
|
2020-03-05 10:34:35 +01:00
|
|
|
GeneratorInfo info(generator, extraGenerator, platform, toolset);
|
2016-09-28 12:24:06 +02:00
|
|
|
setGeneratorInfo(k, info);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
QStringList CMakeGeneratorKitAspect::generatorArguments(const Kit *k)
|
2016-09-27 13:26:54 +02:00
|
|
|
{
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-01-14 16:38:55 +01:00
|
|
|
bool CMakeGeneratorKitAspect::isMultiConfigGenerator(const Kit *k)
|
|
|
|
|
{
|
|
|
|
|
const QString generator = CMakeGeneratorKitAspect::generator(k);
|
|
|
|
|
return generator.indexOf("Visual Studio") != -1 ||
|
|
|
|
|
generator == "Xcode" ||
|
|
|
|
|
generator == "Ninja Multi-Config";
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
QVariant CMakeGeneratorKitAspect::defaultValue(const Kit *k) const
|
2016-01-22 17:17:36 +01:00
|
|
|
{
|
2018-02-12 12:49:22 +01:00
|
|
|
QTC_ASSERT(k, return QVariant());
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
CMakeTool *tool = CMakeKitAspect::cmakeTool(k);
|
2016-01-22 17:17:36 +01:00
|
|
|
if (!tool)
|
2016-09-27 13:26:54 +02:00
|
|
|
return QVariant();
|
2016-09-28 12:24:06 +02:00
|
|
|
|
2021-02-02 16:10:45 +01:00
|
|
|
if (isIos(k))
|
|
|
|
|
return GeneratorInfo("Xcode").toVariant();
|
|
|
|
|
|
2020-03-05 10:34:35 +01:00
|
|
|
const QList<CMakeTool::Generator> known = tool->supportedGenerators();
|
|
|
|
|
auto it = std::find_if(known.constBegin(), known.constEnd(), [](const CMakeTool::Generator &g) {
|
|
|
|
|
return g.matches("Ninja");
|
2016-09-28 12:24:06 +02:00
|
|
|
});
|
2016-02-29 14:26:50 +01:00
|
|
|
if (it != known.constEnd()) {
|
2020-03-03 12:23:04 +01:00
|
|
|
const bool hasNinja = [k]() {
|
|
|
|
|
Internal::CMakeSpecificSettings *settings
|
|
|
|
|
= Internal::CMakeProjectPlugin::projectTypeSpecificSettings();
|
|
|
|
|
|
2021-03-26 16:54:40 +01:00
|
|
|
if (settings->ninjaPath.filePath().isEmpty()) {
|
2021-06-01 18:26:35 +02:00
|
|
|
Environment env = k->buildEnvironment();
|
2020-03-03 12:23:04 +01:00
|
|
|
return !env.searchInPath("ninja").isEmpty();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}();
|
|
|
|
|
|
|
|
|
|
if (hasNinja)
|
2020-03-05 10:34:35 +01:00
|
|
|
return GeneratorInfo("Ninja").toVariant();
|
2016-02-29 14:26:50 +01:00
|
|
|
}
|
2016-09-28 12:24:06 +02:00
|
|
|
|
2021-09-22 13:11:37 +02:00
|
|
|
if (tool->filePath().osType() == OsTypeWindows) {
|
2016-03-02 10:18:06 +01:00
|
|
|
// *sigh* Windows with its zoo of incompatible stuff again...
|
2020-02-18 18:25:26 +01:00
|
|
|
ToolChain *tc = ToolChainKitAspect::cxxToolChain(k);
|
2016-03-02 10:18:06 +01:00
|
|
|
if (tc && tc->typeId() == ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID) {
|
2020-03-05 10:34:35 +01:00
|
|
|
it = std::find_if(known.constBegin(),
|
|
|
|
|
known.constEnd(),
|
|
|
|
|
[](const CMakeTool::Generator &g) {
|
|
|
|
|
return g.matches("MinGW Makefiles");
|
|
|
|
|
});
|
2016-03-02 10:18:06 +01:00
|
|
|
} else {
|
2020-03-05 10:34:35 +01:00
|
|
|
it = std::find_if(known.constBegin(),
|
|
|
|
|
known.constEnd(),
|
|
|
|
|
[](const CMakeTool::Generator &g) {
|
|
|
|
|
return g.matches("NMake Makefiles")
|
|
|
|
|
|| g.matches("NMake Makefiles JOM");
|
|
|
|
|
});
|
2020-04-17 08:53:16 +02:00
|
|
|
if (ProjectExplorerPlugin::projectExplorerSettings().useJom) {
|
|
|
|
|
it = std::find_if(known.constBegin(),
|
|
|
|
|
known.constEnd(),
|
2020-04-24 12:39:54 +02:00
|
|
|
[](const CMakeTool::Generator &g) {
|
|
|
|
|
return g.matches("NMake Makefiles JOM");
|
2020-04-17 08:53:16 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (it == known.constEnd()) {
|
|
|
|
|
it = std::find_if(known.constBegin(),
|
|
|
|
|
known.constEnd(),
|
2020-04-24 12:39:54 +02:00
|
|
|
[](const CMakeTool::Generator &g) {
|
|
|
|
|
return g.matches("NMake Makefiles");
|
2020-04-17 08:53:16 +02:00
|
|
|
});
|
|
|
|
|
}
|
2016-03-02 10:18:06 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Unix-oid OSes:
|
2020-03-05 10:34:35 +01:00
|
|
|
it = std::find_if(known.constBegin(), known.constEnd(), [](const CMakeTool::Generator &g) {
|
|
|
|
|
return g.matches("Unix Makefiles");
|
2016-09-28 12:24:06 +02:00
|
|
|
});
|
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();
|
|
|
|
|
|
2020-03-05 10:34:35 +01:00
|
|
|
return GeneratorInfo(it->name).toVariant();
|
2016-01-22 17:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-27 16:09:44 +02:00
|
|
|
Tasks CMakeGeneratorKitAspect::validate(const Kit *k) const
|
2016-01-22 17:17:36 +01:00
|
|
|
{
|
2019-02-06 12:50:51 +01:00
|
|
|
CMakeTool *tool = CMakeKitAspect::cmakeTool(k);
|
2020-01-15 08:56:11 +01:00
|
|
|
if (!tool)
|
|
|
|
|
return {};
|
2016-01-22 17:17:36 +01:00
|
|
|
|
2019-05-27 16:09:44 +02:00
|
|
|
Tasks result;
|
2020-01-15 08:56:11 +01:00
|
|
|
const auto addWarning = [&result](const QString &desc) {
|
|
|
|
|
result << BuildSystemTask(Task::Warning, desc);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!tool->isValid()) {
|
|
|
|
|
addWarning(tr("CMake Tool is unconfigured, CMake generator will be ignored."));
|
|
|
|
|
} else {
|
|
|
|
|
const GeneratorInfo info = generatorInfo(k);
|
|
|
|
|
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()) {
|
|
|
|
|
addWarning(tr("CMake Tool does not support the configured generator."));
|
2016-01-22 17:17:36 +01:00
|
|
|
} else {
|
2020-01-15 08:56:11 +01:00
|
|
|
if (!it->supportsPlatform && !info.platform.isEmpty())
|
|
|
|
|
addWarning(tr("Platform is not supported by the selected CMake generator."));
|
|
|
|
|
if (!it->supportsToolset && !info.toolset.isEmpty())
|
|
|
|
|
addWarning(tr("Toolset is not supported by the selected CMake generator."));
|
|
|
|
|
}
|
2020-04-03 11:16:48 +02:00
|
|
|
if (!tool->hasFileApi()) {
|
|
|
|
|
addWarning(tr("The selected CMake binary does not support file-api. "
|
2020-01-15 08:56:11 +01:00
|
|
|
"%1 will not be able to parse CMake projects.")
|
2020-04-16 18:21:16 +02:00
|
|
|
.arg(Core::Constants::IDE_DISPLAY_NAME));
|
2016-01-22 17:17:36 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-01-15 08:56:11 +01:00
|
|
|
|
2016-01-22 17:17:36 +01:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void CMakeGeneratorKitAspect::setup(Kit *k)
|
2016-01-22 17:17:36 +01:00
|
|
|
{
|
2019-05-06 14:55:34 +02:00
|
|
|
if (!k || k->hasValue(id()))
|
|
|
|
|
return;
|
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
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void CMakeGeneratorKitAspect::fix(Kit *k)
|
2016-01-22 17:17:36 +01:00
|
|
|
{
|
2019-02-06 12:50:51 +01:00
|
|
|
const CMakeTool *tool = CMakeKitAspect::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 {
|
2021-02-02 16:10:45 +01:00
|
|
|
const GeneratorInfo dv(isIos(k) ? QString("Xcode") : info.generator,
|
2020-03-05 10:34:35 +01:00
|
|
|
info.extraGenerator,
|
|
|
|
|
it->supportsPlatform ? info.platform : QString(),
|
|
|
|
|
it->supportsToolset ? info.toolset : QString());
|
2016-09-28 12:24:06 +02:00
|
|
|
setGeneratorInfo(k, dv);
|
2016-09-27 13:26:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void CMakeGeneratorKitAspect::upgrade(Kit *k)
|
2016-09-27 13:26:54 +02:00
|
|
|
{
|
2018-02-12 12:49:22 +01:00
|
|
|
QTC_ASSERT(k, return);
|
|
|
|
|
|
2016-09-27 13:26:54 +02:00
|
|
|
const QVariant value = k->value(GENERATOR_ID);
|
|
|
|
|
if (value.type() != QVariant::Map) {
|
2016-12-02 15:15:04 +01:00
|
|
|
GeneratorInfo info;
|
2016-09-27 13:26:54 +02:00
|
|
|
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;
|
|
|
|
|
}
|
2016-10-11 12:10:51 +02:00
|
|
|
setGeneratorInfo(k, info);
|
2016-09-27 13:26:54 +02:00
|
|
|
}
|
2016-01-22 17:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
KitAspect::ItemList CMakeGeneratorKitAspect::toUserOutput(const Kit *k) const
|
2016-01-22 17:17:36 +01:00
|
|
|
{
|
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 {
|
2016-11-01 14:56:14 +01:00
|
|
|
message = tr("Generator: %1<br>Extra generator: %2").arg(info.generator).arg(info.extraGenerator);
|
2016-09-27 13:26:54 +02:00
|
|
|
if (!info.platform.isEmpty())
|
2017-09-13 15:56:47 +02:00
|
|
|
message += "<br/>" + tr("Platform: %1").arg(info.platform);
|
2016-09-27 13:26:54 +02:00
|
|
|
if (!info.toolset.isEmpty())
|
2017-09-13 15:56:47 +02:00
|
|
|
message += "<br/>" + tr("Toolset: %1").arg(info.toolset);
|
2016-09-27 13:26:54 +02:00
|
|
|
}
|
2019-05-28 08:28:51 +02:00
|
|
|
return {{tr("CMake Generator"), message}};
|
2016-01-22 17:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
KitAspectWidget *CMakeGeneratorKitAspect::createConfigWidget(Kit *k) const
|
2016-01-22 17:17:36 +01:00
|
|
|
{
|
2019-02-06 15:04:17 +01:00
|
|
|
return new CMakeGeneratorKitAspectWidget(k, this);
|
2016-01-22 17:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
void CMakeGeneratorKitAspect::addToBuildEnvironment(const Kit *k, Environment &env) const
|
2020-04-17 09:06:28 +02:00
|
|
|
{
|
|
|
|
|
GeneratorInfo info = generatorInfo(k);
|
|
|
|
|
if (info.generator == "NMake Makefiles JOM") {
|
|
|
|
|
if (env.searchInPath("jom.exe").exists())
|
|
|
|
|
return;
|
2021-11-09 18:20:14 +01:00
|
|
|
env.appendOrSetPath(Core::ICore::libexecPath());
|
|
|
|
|
env.appendOrSetPath(Core::ICore::libexecPath("jom"));
|
2020-04-17 09:06:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-12 12:23:18 +01:00
|
|
|
// --------------------------------------------------------------------
|
2019-02-06 12:50:51 +01:00
|
|
|
// CMakeConfigurationKitAspect:
|
2016-02-12 12:23:18 +01:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
const char CONFIGURATION_ID[] = "CMake.ConfigurationKitInformation";
|
2016-02-12 12:23:18 +01:00
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
const char CMAKE_C_TOOLCHAIN_KEY[] = "CMAKE_C_COMPILER";
|
|
|
|
|
const char CMAKE_CXX_TOOLCHAIN_KEY[] = "CMAKE_CXX_COMPILER";
|
|
|
|
|
const char CMAKE_QMAKE_KEY[] = "QT_QMAKE_EXECUTABLE";
|
|
|
|
|
const char CMAKE_PREFIX_PATH_KEY[] = "CMAKE_PREFIX_PATH";
|
2016-02-12 12:23:18 +01:00
|
|
|
|
2020-11-18 17:04:54 +01:00
|
|
|
class CMakeConfigurationKitAspectWidget final : public KitAspectWidget
|
2019-02-06 15:04:17 +01:00
|
|
|
{
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(CMakeProjectManager::Internal::CMakeConfigurationKitAspect)
|
2021-06-01 18:26:35 +02:00
|
|
|
|
2019-02-06 15:04:17 +01:00
|
|
|
public:
|
|
|
|
|
CMakeConfigurationKitAspectWidget(Kit *kit, const KitAspect *ki)
|
|
|
|
|
: KitAspectWidget(kit, ki),
|
2021-06-01 18:26:35 +02:00
|
|
|
m_summaryLabel(createSubWidget<ElidingLabel>()),
|
2021-04-07 18:55:21 +02:00
|
|
|
m_manageButton(createSubWidget<QPushButton>())
|
2019-02-06 15:04:17 +01:00
|
|
|
{
|
|
|
|
|
refresh();
|
|
|
|
|
m_manageButton->setText(tr("Change..."));
|
|
|
|
|
connect(m_manageButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &CMakeConfigurationKitAspectWidget::editConfigurationChanges);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// KitAspectWidget interface
|
2021-06-01 18:26:35 +02:00
|
|
|
void addToLayout(LayoutBuilder &builder) override
|
2021-04-07 18:55:21 +02:00
|
|
|
{
|
|
|
|
|
addMutableAction(m_summaryLabel);
|
|
|
|
|
builder.addItem(m_summaryLabel);
|
|
|
|
|
builder.addItem(m_manageButton);
|
|
|
|
|
}
|
2019-02-06 15:04:17 +01:00
|
|
|
|
|
|
|
|
void makeReadOnly() override
|
|
|
|
|
{
|
|
|
|
|
m_manageButton->setEnabled(false);
|
|
|
|
|
if (m_dialog)
|
|
|
|
|
m_dialog->reject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void refresh() override
|
|
|
|
|
{
|
|
|
|
|
const QStringList current = CMakeConfigurationKitAspect::toStringList(kit());
|
|
|
|
|
|
|
|
|
|
m_summaryLabel->setText(current.join("; "));
|
|
|
|
|
if (m_editor)
|
|
|
|
|
m_editor->setPlainText(current.join('\n'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void editConfigurationChanges()
|
|
|
|
|
{
|
|
|
|
|
if (m_dialog) {
|
|
|
|
|
m_dialog->activateWindow();
|
|
|
|
|
m_dialog->raise();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTC_ASSERT(!m_editor, return);
|
|
|
|
|
|
|
|
|
|
m_dialog = new QDialog(m_summaryLabel->window());
|
|
|
|
|
m_dialog->setWindowTitle(tr("Edit CMake Configuration"));
|
|
|
|
|
auto layout = new QVBoxLayout(m_dialog);
|
|
|
|
|
m_editor = new QPlainTextEdit;
|
|
|
|
|
m_editor->setToolTip(tr("Enter one variable per line with the variable name "
|
|
|
|
|
"separated from the variable value by \"=\".<br>"
|
|
|
|
|
"You may provide a type hint by adding \":TYPE\" before the \"=\"."));
|
|
|
|
|
m_editor->setMinimumSize(800, 200);
|
|
|
|
|
|
2021-06-01 18:26:35 +02:00
|
|
|
auto chooser = new VariableChooser(m_dialog);
|
2019-02-06 15:04:17 +01:00
|
|
|
chooser->addSupportedWidget(m_editor);
|
|
|
|
|
chooser->addMacroExpanderProvider([this]() { return kit()->macroExpander(); });
|
|
|
|
|
|
|
|
|
|
auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Apply
|
|
|
|
|
|QDialogButtonBox::Reset|QDialogButtonBox::Cancel);
|
|
|
|
|
|
|
|
|
|
layout->addWidget(m_editor);
|
|
|
|
|
layout->addWidget(buttons);
|
|
|
|
|
|
|
|
|
|
connect(buttons, &QDialogButtonBox::accepted, m_dialog, &QDialog::accept);
|
|
|
|
|
connect(buttons, &QDialogButtonBox::rejected, m_dialog, &QDialog::reject);
|
|
|
|
|
connect(buttons, &QDialogButtonBox::clicked, m_dialog, [buttons, this](QAbstractButton *button) {
|
|
|
|
|
if (button != buttons->button(QDialogButtonBox::Reset))
|
|
|
|
|
return;
|
|
|
|
|
CMakeConfigurationKitAspect::setConfiguration(kit(),
|
|
|
|
|
CMakeConfigurationKitAspect::defaultConfiguration(kit()));
|
|
|
|
|
});
|
|
|
|
|
connect(m_dialog, &QDialog::accepted, this, &CMakeConfigurationKitAspectWidget::acceptChangesDialog);
|
|
|
|
|
connect(m_dialog, &QDialog::rejected, this, &CMakeConfigurationKitAspectWidget::closeChangesDialog);
|
|
|
|
|
connect(buttons->button(QDialogButtonBox::Apply), &QAbstractButton::clicked,
|
|
|
|
|
this, &CMakeConfigurationKitAspectWidget::applyChanges);
|
|
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
|
m_dialog->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void applyChanges()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_editor, return);
|
|
|
|
|
CMakeConfigurationKitAspect::fromStringList(kit(), m_editor->toPlainText().split(QLatin1Char('\n')));
|
|
|
|
|
}
|
|
|
|
|
void closeChangesDialog()
|
|
|
|
|
{
|
|
|
|
|
m_dialog->deleteLater();
|
|
|
|
|
m_dialog = nullptr;
|
|
|
|
|
m_editor = nullptr;
|
|
|
|
|
}
|
|
|
|
|
void acceptChangesDialog()
|
|
|
|
|
{
|
|
|
|
|
applyChanges();
|
|
|
|
|
closeChangesDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLabel *m_summaryLabel;
|
|
|
|
|
QPushButton *m_manageButton;
|
|
|
|
|
QDialog *m_dialog = nullptr;
|
|
|
|
|
QPlainTextEdit *m_editor = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
CMakeConfigurationKitAspect::CMakeConfigurationKitAspect()
|
2016-02-12 12:23:18 +01:00
|
|
|
{
|
2019-02-06 12:50:51 +01:00
|
|
|
setObjectName(QLatin1String("CMakeConfigurationKitAspect"));
|
2016-02-12 12:23:18 +01:00
|
|
|
setId(CONFIGURATION_ID);
|
2019-02-06 16:16:07 +01:00
|
|
|
setDisplayName(tr("CMake Configuration"));
|
|
|
|
|
setDescription(tr("Default configuration passed to CMake when setting up a project."));
|
2016-02-12 12:23:18 +01:00
|
|
|
setPriority(18000);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
CMakeConfig CMakeConfigurationKitAspect::configuration(const Kit *k)
|
2016-02-12 12:23:18 +01:00
|
|
|
{
|
|
|
|
|
if (!k)
|
|
|
|
|
return CMakeConfig();
|
|
|
|
|
const QStringList tmp = k->value(CONFIGURATION_ID).toStringList();
|
2018-05-28 11:05:37 +02:00
|
|
|
return Utils::transform(tmp, &CMakeConfigItem::fromString);
|
2016-02-12 12:23:18 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void CMakeConfigurationKitAspect::setConfiguration(Kit *k, const CMakeConfig &config)
|
2016-02-12 12:23:18 +01:00
|
|
|
{
|
|
|
|
|
if (!k)
|
|
|
|
|
return;
|
2021-07-06 10:29:29 +02:00
|
|
|
const QStringList tmp = Utils::transform(config.toList(),
|
|
|
|
|
[](const CMakeConfigItem &i) { return i.toString(); });
|
2016-02-12 12:23:18 +01:00
|
|
|
k->setValue(CONFIGURATION_ID, tmp);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
QStringList CMakeConfigurationKitAspect::toStringList(const Kit *k)
|
2016-02-12 12:23:18 +01:00
|
|
|
{
|
2021-07-06 10:29:29 +02:00
|
|
|
QStringList current = Utils::transform(CMakeConfigurationKitAspect::configuration(k).toList(),
|
|
|
|
|
[](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
|
|
|
return current;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void CMakeConfigurationKitAspect::fromStringList(Kit *k, const QStringList &in)
|
2016-02-12 12:23:18 +01:00
|
|
|
{
|
|
|
|
|
CMakeConfig result;
|
2021-06-01 18:26:35 +02:00
|
|
|
for (const QString &s : in) {
|
2016-02-12 12:23:18 +01:00
|
|
|
const CMakeConfigItem item = CMakeConfigItem::fromString(s);
|
|
|
|
|
if (!item.key.isEmpty())
|
|
|
|
|
result << item;
|
|
|
|
|
}
|
|
|
|
|
setConfiguration(k, result);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 14:49:05 +02:00
|
|
|
QStringList CMakeConfigurationKitAspect::toArgumentsList(const Kit *k)
|
|
|
|
|
{
|
2021-07-06 10:29:29 +02:00
|
|
|
return Utils::transform(CMakeConfigurationKitAspect::configuration(k).toList(),
|
2020-04-02 14:49:05 +02:00
|
|
|
[](const CMakeConfigItem &i) { return i.toArgument(nullptr); });
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
CMakeConfig CMakeConfigurationKitAspect::defaultConfiguration(const Kit *k)
|
2016-02-12 12:23:18 +01:00
|
|
|
{
|
2019-07-23 10:58:00 +02: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:
|
2016-11-08 11:56:53 +01:00
|
|
|
config << CMakeConfigItem(CMAKE_PREFIX_PATH_KEY, "%{Qt:QT_INSTALL_PREFIX}");
|
2016-09-19 11:53:30 +02:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
QVariant CMakeConfigurationKitAspect::defaultValue(const Kit *k) const
|
2016-04-06 15:29:39 +02:00
|
|
|
{
|
|
|
|
|
// FIXME: Convert preload scripts
|
|
|
|
|
CMakeConfig config = defaultConfiguration(k);
|
2021-07-06 10:29:29 +02:00
|
|
|
const QStringList tmp = Utils::transform(config.toList(),
|
|
|
|
|
[](const CMakeConfigItem &i) { return i.toString(); });
|
2016-02-12 12:23:18 +01:00
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 16:09:44 +02:00
|
|
|
Tasks CMakeConfigurationKitAspect::validate(const Kit *k) const
|
2016-02-12 12:23:18 +01:00
|
|
|
{
|
2019-05-27 16:09:44 +02:00
|
|
|
QTC_ASSERT(k, return Tasks());
|
2018-02-12 12:49:22 +01:00
|
|
|
|
2022-01-21 16:06:36 +01:00
|
|
|
const QtSupport::QtVersion *const version = QtSupport::QtKitAspect::qtVersion(k);
|
2020-02-18 18:25:26 +01:00
|
|
|
const ToolChain *const tcC = ToolChainKitAspect::cToolChain(k);
|
|
|
|
|
const ToolChain *const tcCxx = ToolChainKitAspect::cxxToolChain(k);
|
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);
|
2021-08-05 10:25:04 +02:00
|
|
|
FilePath qmakePath; // This is relative to the cmake used for building.
|
|
|
|
|
QStringList qtInstallDirs; // This is relativ to the cmake used for building.
|
2021-06-01 18:26:35 +02:00
|
|
|
FilePath tcCPath;
|
|
|
|
|
FilePath tcCxxPath;
|
|
|
|
|
for (const CMakeConfigItem &i : config) {
|
2018-10-22 16:34:31 +02:00
|
|
|
// Do not use expand(QByteArray) as we cannot be sure the input is latin1
|
2021-06-01 18:26:35 +02:00
|
|
|
const FilePath expandedValue
|
|
|
|
|
= FilePath::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)
|
2021-08-05 10:25:04 +02:00
|
|
|
qtInstallDirs = CMakeConfigItem::cmakeSplitValue(expandedValue.path());
|
2016-02-12 12:23:18 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-27 16:09:44 +02:00
|
|
|
Tasks result;
|
2020-01-15 08:56:11 +01:00
|
|
|
const auto addWarning = [&result](const QString &desc) {
|
|
|
|
|
result << BuildSystemTask(Task::Warning, desc);
|
|
|
|
|
};
|
|
|
|
|
|
2016-02-12 12:23:18 +01:00
|
|
|
// Validate Qt:
|
|
|
|
|
if (qmakePath.isEmpty()) {
|
2016-09-19 11:53:30 +02:00
|
|
|
if (version && version->isValid() && isQt4) {
|
2020-01-15 08:56:11 +01:00
|
|
|
addWarning(tr("CMake configuration has no path to qmake binary set, "
|
|
|
|
|
"even though the kit has a valid Qt version."));
|
2016-02-12 12:23:18 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!version || !version->isValid()) {
|
2020-01-15 08:56:11 +01:00
|
|
|
addWarning(tr("CMake configuration has a path to a qmake binary set, "
|
|
|
|
|
"even though the kit has no valid Qt version."));
|
2021-07-13 09:41:26 +02:00
|
|
|
} else if (qmakePath != version->qmakeFilePath() && isQt4) {
|
2020-01-15 08:56:11 +01:00
|
|
|
addWarning(tr("CMake configuration has a path to a qmake binary set "
|
|
|
|
|
"that does not match the qmake binary path "
|
|
|
|
|
"configured in the Qt version."));
|
2016-02-12 12:23:18 +01:00
|
|
|
}
|
2016-09-19 11:53:30 +02:00
|
|
|
}
|
2021-08-05 10:25:04 +02:00
|
|
|
if (version && !qtInstallDirs.contains(version->prefix().path()) && !isQt4) {
|
2016-09-30 11:35:12 +02:00
|
|
|
if (version->isValid()) {
|
2020-01-15 08:56:11 +01:00
|
|
|
addWarning(tr("CMake configuration has no CMAKE_PREFIX_PATH set "
|
|
|
|
|
"that points to the kit Qt version."));
|
2016-09-19 11:53:30 +02:00
|
|
|
}
|
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()) {
|
2020-01-15 08:56:11 +01:00
|
|
|
addWarning(tr("CMake configuration has no path to a C compiler set, "
|
|
|
|
|
"even though the kit has a valid tool chain."));
|
2016-07-18 02:08:25 -07:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!tcC || !tcC->isValid()) {
|
2020-01-15 08:56:11 +01:00
|
|
|
addWarning(tr("CMake configuration has a path to a C compiler set, "
|
|
|
|
|
"even though the kit has no valid tool chain."));
|
2016-07-18 02:08:25 -07:00
|
|
|
} else if (tcCPath != tcC->compilerCommand()) {
|
2020-01-15 08:56:11 +01:00
|
|
|
addWarning(tr("CMake configuration has a path to a C compiler set "
|
|
|
|
|
"that does not match the compiler path "
|
|
|
|
|
"configured in the tool chain of the kit."));
|
2016-07-18 02:08:25 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tcCxxPath.isEmpty()) {
|
|
|
|
|
if (tcCxx && tcCxx->isValid()) {
|
2020-01-15 08:56:11 +01:00
|
|
|
addWarning(tr("CMake configuration has no path to a C++ compiler set, "
|
|
|
|
|
"even though the kit has a valid tool chain."));
|
2016-02-12 12:23:18 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
2016-07-18 02:08:25 -07:00
|
|
|
if (!tcCxx || !tcCxx->isValid()) {
|
2020-01-15 08:56:11 +01:00
|
|
|
addWarning(tr("CMake configuration has a path to a C++ compiler set, "
|
|
|
|
|
"even though the kit has no valid tool chain."));
|
2016-07-18 02:08:25 -07:00
|
|
|
} else if (tcCxxPath != tcCxx->compilerCommand()) {
|
2020-01-15 08:56:11 +01:00
|
|
|
addWarning(tr("CMake configuration has a path to a C++ compiler set "
|
|
|
|
|
"that does not match the compiler path "
|
|
|
|
|
"configured in the tool chain of the kit."));
|
2016-02-12 12:23:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void CMakeConfigurationKitAspect::setup(Kit *k)
|
2016-02-12 12:23:18 +01:00
|
|
|
{
|
2016-12-21 11:50:43 +01:00
|
|
|
if (k && !k->hasValue(CONFIGURATION_ID))
|
2016-02-12 12:23:18 +01:00
|
|
|
k->setValue(CONFIGURATION_ID, defaultValue(k));
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
void CMakeConfigurationKitAspect::fix(Kit *k)
|
2016-02-12 12:23:18 +01:00
|
|
|
{
|
2019-07-23 10:58:00 +02:00
|
|
|
Q_UNUSED(k)
|
2016-02-12 12:23:18 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
KitAspect::ItemList CMakeConfigurationKitAspect::toUserOutput(const Kit *k) const
|
2016-02-12 12:23:18 +01:00
|
|
|
{
|
2019-05-28 08:28:51 +02:00
|
|
|
return {{tr("CMake Configuration"), toStringList(k).join("<br>")}};
|
2016-02-12 12:23:18 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
KitAspectWidget *CMakeConfigurationKitAspect::createConfigWidget(Kit *k) const
|
2016-02-12 12:23:18 +01:00
|
|
|
{
|
|
|
|
|
if (!k)
|
2018-02-12 12:49:22 +01:00
|
|
|
return nullptr;
|
2019-02-06 15:04:17 +01:00
|
|
|
return new CMakeConfigurationKitAspectWidget(k, this);
|
2016-02-12 12:23:18 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-24 21:57:00 +01:00
|
|
|
} // namespace CMakeProjectManager
|