forked from qt-creator/qt-creator
CMakeProjectManager: Add package manager auto-setup
Adds CMAKE_PROJECT_INCLUDE_BEFORE as initial CMake parameters with a path to a auto-setup.cmake script that will run conan install if a conanfile.txt is found in the prject. A project can have a local QtCreatorPackageManager.cmake file that will be loaded if exists. The auto setup can be controlled via the following CMake variables: * QT_CREATOR_SKIP_PACKAGE_MANAGER_SETUP * QT_CREATOR_SKIP_CONAN_SETUP * QT_CREATOR_SKIP_VCPKG_SETUP conan.cmake is taken from https://github.com/conan-io/cmake-conan which takes care of the conan specific compiler cruft. License is MIT. Fixes: QTCREATORBUG-25362 Change-Id: I70a6e1abc5600851d048f1590ca24204ce52a503 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -31,6 +31,8 @@
|
||||
#include "cmakeconfigitem.h"
|
||||
#include "cmakekitinformation.h"
|
||||
#include "cmakeprojectconstants.h"
|
||||
#include "cmakeprojectplugin.h"
|
||||
#include "cmakespecificsettings.h"
|
||||
#include "configmodel.h"
|
||||
#include "configmodelitemdelegate.h"
|
||||
|
||||
@@ -674,6 +676,14 @@ static QStringList defaultInitialCMakeArguments(const Kit *k, const QString buil
|
||||
initialArgs.append(QString::fromLatin1("-DCMAKE_BUILD_TYPE:String=%1").arg(buildType));
|
||||
}
|
||||
|
||||
Internal::CMakeSpecificSettings *settings
|
||||
= Internal::CMakeProjectPlugin::projectTypeSpecificSettings();
|
||||
|
||||
// Package manager
|
||||
if (settings->packageManagerAutoSetup())
|
||||
initialArgs.append(QString::fromLatin1("-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%1")
|
||||
.arg("%{IDE:ResourcePath}/package-manager/auto-setup.cmake"));
|
||||
|
||||
// Cross-compilation settings:
|
||||
if (!isIos(k)) { // iOS handles this differently
|
||||
const QString sysRoot = SysRootKitAspect::sysRoot(k).toString();
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace {
|
||||
static const char SETTINGS_KEY[] = "CMakeSpecificSettings";
|
||||
static const char AFTER_ADD_FILE_ACTION_KEY[] = "ProjectPopupSetting";
|
||||
static const char NINJA_PATH[] = "NinjaPath";
|
||||
static const char PACKAGE_MANAGER_AUTO_SETUP[] = "PackageManagerAutoSetup";
|
||||
}
|
||||
|
||||
void CMakeSpecificSettings::fromSettings(QSettings *settings)
|
||||
@@ -43,12 +44,15 @@ void CMakeSpecificSettings::fromSettings(QSettings *settings)
|
||||
|
||||
m_ninjaPath = Utils::FilePath::fromUserInput(
|
||||
settings->value(rootKey + NINJA_PATH, QString()).toString());
|
||||
|
||||
m_packageManagerAutoSetup = settings->value(rootKey + PACKAGE_MANAGER_AUTO_SETUP, true).toBool();
|
||||
}
|
||||
|
||||
void CMakeSpecificSettings::toSettings(QSettings *settings) const
|
||||
{
|
||||
settings->beginGroup(QString(SETTINGS_KEY));
|
||||
settings->setValue(QString(AFTER_ADD_FILE_ACTION_KEY), static_cast<int>(m_afterAddFileToProjectSetting));
|
||||
settings->setValue(QString(PACKAGE_MANAGER_AUTO_SETUP), m_packageManagerAutoSetup);
|
||||
settings->endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,9 +50,13 @@ public:
|
||||
|
||||
Utils::FilePath ninjaPath() const { return m_ninjaPath; }
|
||||
|
||||
void setPackageManagerAutoSetup(bool checked) { m_packageManagerAutoSetup = checked; }
|
||||
bool packageManagerAutoSetup() const { return m_packageManagerAutoSetup; }
|
||||
|
||||
private:
|
||||
AfterAddFileAction m_afterAddFileToProjectSetting;
|
||||
Utils::FilePath m_ninjaPath;
|
||||
bool m_packageManagerAutoSetup = true;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -70,6 +70,8 @@ CMakeSpecificSettingWidget::CMakeSpecificSettingWidget(CMakeSpecificSettings *se
|
||||
m_ui.neverCopyRadio->setChecked(true);
|
||||
break;
|
||||
}
|
||||
|
||||
m_ui.packageManagerAutoSetup->setChecked(settings->packageManagerAutoSetup());
|
||||
}
|
||||
|
||||
void CMakeSpecificSettingWidget::apply()
|
||||
@@ -77,6 +79,7 @@ void CMakeSpecificSettingWidget::apply()
|
||||
int popupSetting = m_ui.newFileAddedCopyToCpliSettingGroup->checkedId();
|
||||
m_settings->setAfterAddFileSetting(popupSetting == -1 ? AfterAddFileAction::ASK_USER
|
||||
: static_cast<AfterAddFileAction>(popupSetting));
|
||||
m_settings->setPackageManagerAutoSetup(m_ui.packageManagerAutoSetup->isChecked());
|
||||
m_settings->toSettings(Core::ICore::settings());
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,16 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="packageManagerAutoSetup">
|
||||
<property name="toolTip">
|
||||
<string>Add the CMAKE_PROJECT_INCLUDE_BEFORE variable pointing to a CMake script that will install dependencies from the conanfile.txt, conanfile.py, or vcpkg.json file from the project source directory.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Package manager auto setup</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
||||
Reference in New Issue
Block a user