-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcmakebuildconfiguration.cpp
2250 lines (1894 loc) · 89.3 KB
/
cmakebuildconfiguration.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "cmakebuildconfiguration.h"
#include "cmakebuildstep.h"
#include "cmakebuildsystem.h"
#include "cmakeconfigitem.h"
#include "cmakekitaspect.h"
#include "cmakeproject.h"
#include "cmakeprojectconstants.h"
#include "cmakeprojectmanagertr.h"
#include "cmakespecificsettings.h"
#include "configmodel.h"
#include "configmodelitemdelegate.h"
#include "fileapiparser.h"
#include "presetsmacros.h"
#include "presetsparser.h"
#include <android/androidconstants.h>
#include <docker/dockerconstants.h>
#include <ios/iosconstants.h>
#include <qnx/qnxconstants.h>
#include <webassembly/webassemblyconstants.h>
#include <coreplugin/fileutils.h>
#include <coreplugin/find/itemviewfind.h>
#include <coreplugin/icore.h>
#include <projectexplorer/buildaspects.h>
#include <projectexplorer/buildinfo.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/environmentaspectwidget.h>
#include <projectexplorer/environmentwidget.h>
#include <projectexplorer/kitaspects.h>
#include <projectexplorer/namedwidget.h>
#include <projectexplorer/processparameters.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectexplorertr.h>
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/target.h>
#include <projectexplorer/taskhub.h>
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtbuildaspects.h>
#include <qtsupport/qtkitaspect.h>
#include <utils/algorithm.h>
#include <utils/categorysortfiltermodel.h>
#include <utils/checkablemessagebox.h>
#include <utils/commandline.h>
#include <utils/detailswidget.h>
#include <utils/infolabel.h>
#include <utils/itemviews.h>
#include <utils/layoutbuilder.h>
#include <utils/mimeconstants.h>
#include <utils/progressindicator.h>
#include <utils/qtcassert.h>
#include <utils/stringutils.h>
#include <utils/variablechooser.h>
#include <QCheckBox>
#include <QDialog>
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QHeaderView>
#include <QLoggingCategory>
#include <QMenu>
#include <QMessageBox>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QTimer>
using namespace ProjectExplorer;
using namespace Utils;
using namespace CMakeProjectManager::Internal;
namespace CMakeProjectManager {
static Q_LOGGING_CATEGORY(cmakeBuildConfigurationLog, "qtc.cmake.bc", QtWarningMsg);
const char DEVELOPMENT_TEAM_FLAG[] = "Ios:DevelopmentTeam:Flag";
const char PROVISIONING_PROFILE_FLAG[] = "Ios:ProvisioningProfile:Flag";
const char CMAKE_OSX_ARCHITECTURES_FLAG[] = "CMAKE_OSX_ARCHITECTURES:DefaultFlag";
const char QT_QML_DEBUG_FLAG[] = "Qt:QML_DEBUG_FLAG";
const char QT_QML_DEBUG_PARAM[] = "-DQT_QML_DEBUG";
const char CMAKE_QT6_TOOLCHAIN_FILE_ARG[]
= "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake";
const char CMAKE_BUILD_TYPE[] = "CMake.Build.Type";
const char CLEAR_SYSTEM_ENVIRONMENT_KEY[] = "CMake.Configure.ClearSystemEnvironment";
const char USER_ENVIRONMENT_CHANGES_KEY[] = "CMake.Configure.UserEnvironmentChanges";
const char BASE_ENVIRONMENT_KEY[] = "CMake.Configure.BaseEnvironment";
namespace Internal {
class CMakeBuildSettingsWidget : public NamedWidget
{
public:
explicit CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc);
void setError(const QString &message);
void setWarning(const QString &message);
private:
void updateButtonState();
void updateAdvancedCheckBox();
void updateFromKit();
void updateConfigurationStateIndex(int index);
CMakeConfig getQmlDebugCxxFlags();
CMakeConfig getSigningFlagsChanges();
void updateSelection();
void updateConfigurationStateSelection();
bool isInitialConfiguration() const;
void setVariableUnsetFlag(bool unsetFlag);
QAction *createForceAction(int type, const QModelIndex &idx);
bool eventFilter(QObject *target, QEvent *event) override;
void batchEditConfiguration();
void reconfigureWithInitialParameters();
void updateInitialCMakeArguments();
void kitCMakeConfiguration();
void updateConfigureDetailsWidgetsSummary(
const QStringList &configurationArguments = QStringList());
CMakeBuildConfiguration *m_buildConfig;
QTreeView *m_configView;
ConfigModel *m_configModel;
CategorySortFilterModel *m_configFilterModel;
CategorySortFilterModel *m_configTextFilterModel;
ProgressIndicator *m_progressIndicator;
QPushButton *m_addButton;
QPushButton *m_editButton;
QPushButton *m_setButton;
QPushButton *m_unsetButton;
QPushButton *m_resetButton;
QCheckBox *m_showAdvancedCheckBox;
QTabBar *m_configurationStates;
QPushButton *m_reconfigureButton;
QTimer m_showProgressTimer;
FancyLineEdit *m_filterEdit;
InfoLabel *m_warningMessageLabel;
DetailsWidget *m_configureDetailsWidget;
QPushButton *m_batchEditButton = nullptr;
QPushButton *m_kitConfiguration = nullptr;
};
static QModelIndex mapToSource(const QAbstractItemView *view, const QModelIndex &idx)
{
if (!idx.isValid())
return idx;
QAbstractItemModel *model = view->model();
QModelIndex result = idx;
while (auto proxy = qobject_cast<const QSortFilterProxyModel *>(model)) {
result = proxy->mapToSource(result);
model = proxy->sourceModel();
}
return result;
}
CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc) :
NamedWidget(Tr::tr("CMake")),
m_buildConfig(bc),
m_configModel(new ConfigModel(this)),
m_configFilterModel(new CategorySortFilterModel(this)),
m_configTextFilterModel(new CategorySortFilterModel(this))
{
m_configureDetailsWidget = new DetailsWidget;
updateConfigureDetailsWidgetsSummary();
auto details = new QWidget(m_configureDetailsWidget);
m_configureDetailsWidget->setWidget(details);
auto buildDirAspect = bc->buildDirectoryAspect();
buildDirAspect->setAutoApplyOnEditingFinished(true);
connect(buildDirAspect, &BaseAspect::changed, this, [this] {
m_configModel->flush(); // clear out config cache...;
});
connect(&m_buildConfig->buildTypeAspect, &BaseAspect::changed, this, [this] {
if (!m_buildConfig->cmakeBuildSystem()->isMultiConfig()) {
CMakeConfig config;
config << CMakeConfigItem("CMAKE_BUILD_TYPE",
m_buildConfig->buildTypeAspect().toUtf8());
m_configModel->setBatchEditConfiguration(config);
}
});
auto qmlDebugAspect = bc->aspect<QtSupport::QmlDebuggingAspect>();
connect(qmlDebugAspect, &QtSupport::QmlDebuggingAspect::changed, this, [this] {
updateButtonState();
});
m_warningMessageLabel = new InfoLabel({}, InfoLabel::Warning);
m_warningMessageLabel->setVisible(false);
m_configurationStates = new QTabBar(this);
m_configurationStates->addTab(Tr::tr("Initial Configuration"));
m_configurationStates->addTab(Tr::tr("Current Configuration"));
connect(m_configurationStates, &QTabBar::currentChanged, this, [this](int index) {
updateConfigurationStateIndex(index);
});
m_kitConfiguration = new QPushButton(Tr::tr("Kit Configuration"));
m_kitConfiguration->setToolTip(Tr::tr("Edit the current kit's CMake configuration."));
m_kitConfiguration->setFixedWidth(m_kitConfiguration->sizeHint().width());
connect(m_kitConfiguration, &QPushButton::clicked,
this, &CMakeBuildSettingsWidget::kitCMakeConfiguration,
Qt::QueuedConnection);
m_filterEdit = new FancyLineEdit;
m_filterEdit->setPlaceholderText(Tr::tr("Filter"));
m_filterEdit->setFiltering(true);
auto tree = new TreeView;
connect(tree, &TreeView::activated,
tree, [tree](const QModelIndex &idx) { tree->edit(idx); });
m_configView = tree;
m_configView->viewport()->installEventFilter(this);
m_configFilterModel->setSourceModel(m_configModel);
m_configFilterModel->setFilterKeyColumn(0);
m_configFilterModel->setFilterRole(ConfigModel::ItemIsAdvancedRole);
m_configFilterModel->setFilterFixedString("0");
m_configTextFilterModel->setSourceModel(m_configFilterModel);
m_configTextFilterModel->setSortRole(Qt::DisplayRole);
m_configTextFilterModel->setFilterKeyColumn(-1);
m_configTextFilterModel->setNewItemRole(ConfigModel::ItemIsUserNew);
connect(m_configTextFilterModel, &QAbstractItemModel::layoutChanged, this, [this] {
QModelIndex selectedIdx = m_configView->currentIndex();
if (selectedIdx.isValid())
m_configView->scrollTo(selectedIdx);
});
m_configView->setModel(m_configTextFilterModel);
m_configView->setMinimumHeight(300);
m_configView->setSortingEnabled(true);
m_configView->sortByColumn(0, Qt::AscendingOrder);
m_configView->header()->setSectionResizeMode(QHeaderView::Stretch);
m_configView->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_configView->setSelectionBehavior(QAbstractItemView::SelectItems);
m_configView->setAlternatingRowColors(true);
m_configView->setFrameShape(QFrame::NoFrame);
m_configView->setItemDelegate(new ConfigModelItemDelegate(bc->project()->projectDirectory(),
m_configView));
m_configView->setRootIsDecorated(false);
QFrame *findWrapper = Core::ItemViewFind::createSearchableWrapper(m_configView, Core::ItemViewFind::LightColored);
findWrapper->setFrameStyle(QFrame::StyledPanel);
m_progressIndicator = new ProgressIndicator(ProgressIndicatorSize::Large, findWrapper);
m_progressIndicator->attachToWidget(findWrapper);
m_progressIndicator->raise();
m_progressIndicator->hide();
m_showProgressTimer.setSingleShot(true);
m_showProgressTimer.setInterval(50); // don't show progress for < 50ms tasks
connect(&m_showProgressTimer, &QTimer::timeout, this, [this] { m_progressIndicator->show(); });
m_addButton = new QPushButton(Tr::tr("&Add"));
m_addButton->setToolTip(Tr::tr("Add a new configuration value."));
auto addButtonMenu = new QMenu(this);
addButtonMenu->addAction(Tr::tr("&Boolean"))->setData(
QVariant::fromValue(static_cast<int>(ConfigModel::DataItem::BOOLEAN)));
addButtonMenu->addAction(Tr::tr("&String"))->setData(
QVariant::fromValue(static_cast<int>(ConfigModel::DataItem::STRING)));
addButtonMenu->addAction(Tr::tr("&Directory"))->setData(
QVariant::fromValue(static_cast<int>(ConfigModel::DataItem::DIRECTORY)));
addButtonMenu->addAction(Tr::tr("&File"))->setData(
QVariant::fromValue(static_cast<int>(ConfigModel::DataItem::FILE)));
m_addButton->setMenu(addButtonMenu);
m_editButton = new QPushButton(Tr::tr("&Edit"));
m_editButton->setToolTip(Tr::tr("Edit the current CMake configuration value."));
m_setButton = new QPushButton(Tr::tr("&Set"));
m_setButton->setToolTip(Tr::tr("Set a value in the CMake configuration."));
m_unsetButton = new QPushButton(Tr::tr("&Unset"));
m_unsetButton->setToolTip(Tr::tr("Unset a value in the CMake configuration."));
m_resetButton = new QPushButton(Tr::tr("&Reset"));
m_resetButton->setToolTip(Tr::tr("Reset all unapplied changes."));
m_resetButton->setEnabled(false);
m_batchEditButton = new QPushButton(Tr::tr("Batch Edit..."));
m_batchEditButton->setToolTip(Tr::tr("Set or reset multiple values in the CMake configuration."));
m_showAdvancedCheckBox = new QCheckBox(Tr::tr("Advanced"));
m_showAdvancedCheckBox->setChecked(settings().showAdvancedOptionsByDefault());
connect(m_configView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, [this](const QItemSelection &, const QItemSelection &) {
updateSelection();
});
m_reconfigureButton = new QPushButton(Tr::tr("Run CMake"));
m_reconfigureButton->setEnabled(false);
using namespace Layouting;
Grid cmakeConfiguration {
m_filterEdit, br,
findWrapper,
Column {
m_addButton,
m_editButton,
m_setButton,
m_unsetButton,
m_resetButton,
m_batchEditButton,
Space(10),
m_showAdvancedCheckBox,
st
}
};
auto configureEnvironmentAspectWidget = bc->configureEnv.createConfigWidget();
configureEnvironmentAspectWidget->setContentsMargins(0, 0, 0, 0);
configureEnvironmentAspectWidget->layout()->setContentsMargins(0, 0, 0, 0);
Column {
Form {
buildDirAspect, br,
bc->buildTypeAspect, br,
qmlDebugAspect
},
m_warningMessageLabel,
m_kitConfiguration,
Column {
m_configurationStates,
Group {
Column {
cmakeConfiguration,
Row {
bc->initialCMakeArguments, br,
bc->additionalCMakeOptions
},
m_reconfigureButton,
}
},
configureEnvironmentAspectWidget
},
noMargin
}.attachTo(details);
Column {
m_configureDetailsWidget,
noMargin
}.attachTo(this);
updateAdvancedCheckBox();
CMakeBuildSystem *bs = m_buildConfig->cmakeBuildSystem();
setError(bs->error());
setWarning(bs->warning());
connect(bs, &BuildSystem::parsingStarted, this, [this] {
updateButtonState();
m_configView->setEnabled(false);
m_showProgressTimer.start();
});
m_configModel->setMacroExpander(bc->macroExpander());
if (bs->isParsing())
m_showProgressTimer.start();
else {
m_configModel->setConfiguration(bs->configurationFromCMake());
m_configModel->setInitialParametersConfiguration(
m_buildConfig->initialCMakeArguments.cmakeConfiguration());
}
connect(bs, &BuildSystem::parsingFinished, this, [this, bs] {
const CMakeConfig config = bs->configurationFromCMake();
const TriState qmlDebugSetting = m_buildConfig->qmlDebugging();
bool qmlDebugConfig = CMakeBuildConfiguration::hasQmlDebugging(config);
if ((qmlDebugSetting == TriState::Enabled && !qmlDebugConfig)
|| (qmlDebugSetting == TriState::Disabled && qmlDebugConfig)) {
m_buildConfig->qmlDebugging.setValue(TriState::Default);
}
m_configModel->setConfiguration(config);
m_configModel->setInitialParametersConfiguration(
m_buildConfig->initialCMakeArguments.cmakeConfiguration());
m_buildConfig->filterConfigArgumentsFromAdditionalCMakeArguments();
updateFromKit();
m_configView->setEnabled(true);
updateButtonState();
m_showProgressTimer.stop();
m_progressIndicator->hide();
updateConfigurationStateSelection();
});
connect(bs, &CMakeBuildSystem::configurationCleared, this, [this] {
updateConfigurationStateSelection();
});
connect(bs, &CMakeBuildSystem::errorOccurred, this, [this] {
m_showProgressTimer.stop();
m_progressIndicator->hide();
updateConfigurationStateSelection();
});
connect(m_configModel, &QAbstractItemModel::dataChanged,
this, &CMakeBuildSettingsWidget::updateButtonState);
connect(m_configModel, &QAbstractItemModel::modelReset,
this, &CMakeBuildSettingsWidget::updateButtonState);
connect(m_buildConfig, &CMakeBuildConfiguration::signingFlagsChanged,
this, &CMakeBuildSettingsWidget::updateButtonState);
connect(m_showAdvancedCheckBox, &QCheckBox::stateChanged,
this, &CMakeBuildSettingsWidget::updateAdvancedCheckBox);
connect(m_filterEdit,
&QLineEdit::textChanged,
m_configTextFilterModel,
[this](const QString &txt) {
m_configTextFilterModel->setFilterRegularExpression(
QRegularExpression(QRegularExpression::escape(txt),
QRegularExpression::CaseInsensitiveOption));
});
connect(m_resetButton, &QPushButton::clicked, this, [this] {
m_configModel->resetAllChanges(isInitialConfiguration());
});
connect(m_reconfigureButton, &QPushButton::clicked, this, [this, bs] {
if (!bs->isParsing()) {
if (isInitialConfiguration()) {
reconfigureWithInitialParameters();
} else {
bs->runCMakeWithExtraArguments();
}
} else {
bs->stopCMakeRun();
m_reconfigureButton->setEnabled(false);
}
});
connect(m_setButton, &QPushButton::clicked, this, [this] { setVariableUnsetFlag(false); });
connect(m_unsetButton, &QPushButton::clicked, this, [this] {
setVariableUnsetFlag(true);
});
connect(m_editButton, &QPushButton::clicked, this, [this] {
QModelIndex idx = m_configView->currentIndex();
if (idx.column() != 1)
idx = idx.sibling(idx.row(), 1);
m_configView->setCurrentIndex(idx);
m_configView->edit(idx);
});
connect(addButtonMenu, &QMenu::triggered, this, [this](QAction *action) {
ConfigModel::DataItem::Type type =
static_cast<ConfigModel::DataItem::Type>(action->data().value<int>());
QString value = Tr::tr("<UNSET>");
if (type == ConfigModel::DataItem::BOOLEAN)
value = QString::fromLatin1("OFF");
m_configModel->appendConfiguration(Tr::tr("<UNSET>"), value, type, isInitialConfiguration());
const TreeItem *item = m_configModel->findNonRootItem([&value, type](TreeItem *item) {
ConfigModel::DataItem dataItem = ConfigModel::dataItemFromIndex(item->index());
return dataItem.key == Tr::tr("<UNSET>") && dataItem.type == type && dataItem.value == value;
});
QModelIndex idx = m_configModel->indexForItem(item);
idx = m_configTextFilterModel->mapFromSource(m_configFilterModel->mapFromSource(idx));
m_configView->setFocus();
m_configView->scrollTo(idx);
m_configView->setCurrentIndex(idx);
m_configView->edit(idx);
});
connect(m_batchEditButton, &QAbstractButton::clicked,
this, &CMakeBuildSettingsWidget::batchEditConfiguration);
connect(bs, &CMakeBuildSystem::errorOccurred,
this, &CMakeBuildSettingsWidget::setError);
connect(bs, &CMakeBuildSystem::warningOccurred,
this, &CMakeBuildSettingsWidget::setWarning);
connect(bs, &CMakeBuildSystem::configurationChanged,
m_configModel, &ConfigModel::setBatchEditConfiguration);
updateFromKit();
connect(m_buildConfig->target(), &Target::kitChanged,
this, &CMakeBuildSettingsWidget::updateFromKit);
connect(bc, &CMakeBuildConfiguration::enabledChanged, this, [this, bc] {
if (bc->isEnabled())
setError(QString());
});
connect(this, &QObject::destroyed, this, [this] {
updateInitialCMakeArguments();
});
connect(m_buildConfig->target()->project(), &Project::aboutToSaveSettings, this, [this] {
updateInitialCMakeArguments();
});
connect(&bc->initialCMakeArguments,
&Utils::BaseAspect::labelLinkActivated,
this,
[this](const QString &) {
const CMakeTool *tool = CMakeKitAspect::cmakeTool(m_buildConfig->kit());
CMakeTool::openCMakeHelpUrl(tool, "%1/manual/cmake.1.html#options");
});
connect(&bc->additionalCMakeOptions,
&Utils::BaseAspect::labelLinkActivated, this, [this](const QString &) {
const CMakeTool *tool = CMakeKitAspect::cmakeTool(m_buildConfig->kit());
CMakeTool::openCMakeHelpUrl(tool, "%1/manual/cmake.1.html#options");
});
if (HostOsInfo::isMacHost())
m_configurationStates->setDrawBase(false);
m_configurationStates->setExpanding(false);
m_reconfigureButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
updateSelection();
updateConfigurationStateSelection();
}
void CMakeBuildSettingsWidget::batchEditConfiguration()
{
auto dialog = new QDialog(this);
dialog->setWindowTitle(Tr::tr("Edit CMake Configuration"));
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setModal(true);
auto layout = new QVBoxLayout(dialog);
auto editor = new QPlainTextEdit(dialog);
auto label = new QLabel(dialog);
label->setText(Tr::tr("Enter one CMake <a href=\"variable\">variable</a> per line.<br/>"
"To set or change a variable, use -D<variable>:<type>=<value>.<br/>"
"<type> can have one of the following values: FILEPATH, PATH, BOOL, INTERNAL, or STRING.<br/>"
"To unset a variable, use -U<variable>.<br/>"));
connect(label, &QLabel::linkActivated, this, [this](const QString &) {
const CMakeTool *tool = CMakeKitAspect::cmakeTool(m_buildConfig->target()->kit());
CMakeTool::openCMakeHelpUrl(tool, "%1/manual/cmake-variables.7.html");
});
editor->setMinimumSize(800, 200);
auto chooser = new Utils::VariableChooser(dialog);
chooser->addSupportedWidget(editor);
chooser->addMacroExpanderProvider([this] { return m_buildConfig->macroExpander(); });
auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
layout->addWidget(editor);
layout->addWidget(label);
layout->addWidget(buttons);
connect(buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject);
connect(dialog, &QDialog::accepted, this, [=]{
const auto expander = m_buildConfig->macroExpander();
const QStringList lines = editor->toPlainText().split('\n', Qt::SkipEmptyParts);
const QStringList expandedLines = Utils::transform(lines,
[expander](const QString &s) {
return expander->expand(s);
});
const bool isInitial = isInitialConfiguration();
QStringList unknownOptions;
CMakeConfig config = CMakeConfig::fromArguments(isInitial ? lines : expandedLines,
unknownOptions);
for (auto &ci : config)
ci.isInitial = isInitial;
m_configModel->setBatchEditConfiguration(config);
});
editor->setPlainText(
m_buildConfig->cmakeBuildSystem()->configurationChangesArguments(isInitialConfiguration())
.join('\n'));
dialog->show();
}
void CMakeBuildSettingsWidget::reconfigureWithInitialParameters()
{
QMessageBox::StandardButton reply = CheckableMessageBox::question(
Core::ICore::dialogParent(),
Tr::tr("Re-configure with Initial Parameters"),
Tr::tr("Clear CMake configuration and configure with initial parameters?"),
settings().askBeforeReConfigureInitialParams.askAgainCheckableDecider(),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes);
settings().writeSettings();
if (reply != QMessageBox::Yes)
return;
m_buildConfig->cmakeBuildSystem()->clearCMakeCache();
updateInitialCMakeArguments();
if (ProjectExplorerPlugin::saveModifiedFiles())
m_buildConfig->cmakeBuildSystem()->runCMake();
}
void CMakeBuildSettingsWidget::updateInitialCMakeArguments()
{
CMakeConfig initialList = m_buildConfig->initialCMakeArguments.cmakeConfiguration();
for (const CMakeConfigItem &ci : m_buildConfig->cmakeBuildSystem()->configurationChanges()) {
if (!ci.isInitial)
continue;
auto it = std::find_if(initialList.begin(),
initialList.end(),
[ci](const CMakeConfigItem &item) {
return item.key == ci.key;
});
if (it != initialList.end()) {
*it = ci;
if (ci.isUnset)
initialList.erase(it);
} else if (!ci.key.isEmpty()) {
initialList.push_back(ci);
}
}
m_buildConfig->initialCMakeArguments.setCMakeConfiguration(initialList);
// value() will contain only the unknown arguments (the non -D/-U arguments)
// As the user would expect to have e.g. "--preset" from "Initial Configuration"
// to "Current Configuration" as additional parameters
m_buildConfig->setAdditionalCMakeArguments(ProcessArgs::splitArgs(
m_buildConfig->initialCMakeArguments(), HostOsInfo::hostOs()));
}
void CMakeBuildSettingsWidget::kitCMakeConfiguration()
{
m_buildConfig->kit()->blockNotification();
auto dialog = new QDialog(this);
dialog->setWindowTitle(Tr::tr("Kit CMake Configuration"));
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setModal(true);
dialog->setSizeGripEnabled(true);
connect(dialog, &QDialog::finished, this, [this] {
m_buildConfig->kit()->unblockNotification();
});
Layouting::Grid grid;
KitAspect *widget = CMakeKitAspect::createKitAspect(m_buildConfig->kit());
widget->setParent(dialog);
widget->addToLayout(grid);
widget = CMakeGeneratorKitAspect::createKitAspect(m_buildConfig->kit());
widget->setParent(dialog);
widget->addToLayout(grid);
widget = CMakeConfigurationKitAspect::createKitAspect(m_buildConfig->kit());
widget->setParent(dialog);
widget->addToLayout(grid);
grid.attachTo(dialog);
auto layout = qobject_cast<QGridLayout *>(dialog->layout());
layout->setColumnStretch(1, 1);
auto buttons = new QDialogButtonBox(QDialogButtonBox::Close);
connect(buttons, &QDialogButtonBox::clicked, dialog, &QDialog::close);
layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Maximum, QSizePolicy::MinimumExpanding),
4, 0);
layout->addWidget(buttons, 5, 0, 1, -1);
dialog->setMinimumWidth(400);
dialog->resize(800, 1);
dialog->show();
}
void CMakeBuildSettingsWidget::updateConfigureDetailsWidgetsSummary(
const QStringList &configurationArguments)
{
ProjectExplorer::ProcessParameters params;
CommandLine cmd;
const CMakeTool *tool = CMakeKitAspect::cmakeTool(m_buildConfig->kit());
cmd.setExecutable(tool ? tool->cmakeExecutable() : "cmake");
const FilePath buildDirectory = m_buildConfig->buildDirectory();
cmd.addArgs({"-S", m_buildConfig->project()->projectDirectory().path()});
cmd.addArgs({"-B", buildDirectory.path()});
cmd.addArgs(configurationArguments);
params.setCommandLine(cmd);
m_configureDetailsWidget->setSummaryText(params.summary(Tr::tr("Configure")));
m_configureDetailsWidget->setState(DetailsWidget::Expanded);
}
void CMakeBuildSettingsWidget::setError(const QString &message)
{
m_buildConfig->buildDirectoryAspect()->setProblem(message);
}
void CMakeBuildSettingsWidget::setWarning(const QString &message)
{
bool showWarning = !message.isEmpty();
m_warningMessageLabel->setVisible(showWarning);
m_warningMessageLabel->setText(message);
}
void CMakeBuildSettingsWidget::updateButtonState()
{
const bool isParsing = m_buildConfig->cmakeBuildSystem()->isParsing();
// Update extra data in buildconfiguration
const QList<ConfigModel::DataItem> changes = m_configModel->configurationForCMake();
const CMakeConfig configChanges
= getQmlDebugCxxFlags() + getSigningFlagsChanges()
+ Utils::transform(changes, [](const ConfigModel::DataItem &i) {
CMakeConfigItem ni;
ni.key = i.key.toUtf8();
ni.value = i.value.toUtf8();
ni.documentation = i.description.toUtf8();
ni.isAdvanced = i.isAdvanced;
ni.isInitial = i.isInitial;
ni.isUnset = i.isUnset;
ni.inCMakeCache = i.inCMakeCache;
ni.values = i.values;
switch (i.type) {
case ConfigModel::DataItem::BOOLEAN:
ni.type = CMakeConfigItem::BOOL;
break;
case ConfigModel::DataItem::FILE:
ni.type = CMakeConfigItem::FILEPATH;
break;
case ConfigModel::DataItem::DIRECTORY:
ni.type = CMakeConfigItem::PATH;
break;
case ConfigModel::DataItem::STRING:
ni.type = CMakeConfigItem::STRING;
break;
case ConfigModel::DataItem::UNKNOWN:
default:
ni.type = CMakeConfigItem::UNINITIALIZED;
break;
}
return ni;
});
const bool isInitial = isInitialConfiguration();
m_resetButton->setEnabled(m_configModel->hasChanges(isInitial) && !isParsing);
m_buildConfig->initialCMakeArguments.setVisible(isInitialConfiguration());
m_buildConfig->additionalCMakeOptions.setVisible(!isInitialConfiguration());
m_buildConfig->initialCMakeArguments.setEnabled(!isParsing);
m_buildConfig->additionalCMakeOptions.setEnabled(!isParsing);
// Update label and text boldness of the reconfigure button
QFont reconfigureButtonFont = m_reconfigureButton->font();
if (isParsing) {
m_reconfigureButton->setText(Tr::tr("Stop CMake"));
reconfigureButtonFont.setBold(false);
} else {
m_reconfigureButton->setEnabled(true);
if (isInitial) {
m_reconfigureButton->setText(Tr::tr("Re-configure with Initial Parameters"));
} else {
m_reconfigureButton->setText(Tr::tr("Run CMake"));
}
reconfigureButtonFont.setBold(isInitial ? m_configModel->hasChanges(isInitial)
: !configChanges.isEmpty());
}
m_reconfigureButton->setFont(reconfigureButtonFont);
m_buildConfig->cmakeBuildSystem()->setConfigurationChanges(configChanges);
// Update the tooltip with the changes
const QStringList configurationArguments =
m_buildConfig->cmakeBuildSystem()->configurationChangesArguments(isInitialConfiguration());
m_reconfigureButton->setToolTip(configurationArguments.join('\n'));
updateConfigureDetailsWidgetsSummary(configurationArguments);
}
void CMakeBuildSettingsWidget::updateAdvancedCheckBox()
{
if (m_showAdvancedCheckBox->isChecked()) {
m_configFilterModel->setFilterRole(ConfigModel::ItemIsAdvancedRole);
m_configFilterModel->setFilterRegularExpression("[01]");
} else {
m_configFilterModel->setFilterRole(ConfigModel::ItemIsAdvancedRole);
m_configFilterModel->setFilterFixedString("0");
}
updateButtonState();
}
void CMakeBuildSettingsWidget::updateFromKit()
{
const Kit *k = m_buildConfig->kit();
CMakeConfig config = CMakeConfigurationKitAspect::configuration(k);
config.append(CMakeGeneratorKitAspect::generatorCMakeConfig(k));
// First the key value parameters
ConfigModel::KitConfiguration configHash;
for (const CMakeConfigItem &i : config)
configHash.insert(QString::fromUtf8(i.key), i);
m_configModel->setConfigurationFromKit(configHash);
// Then the additional parameters
const QStringList additionalKitCMake = ProcessArgs::splitArgs(
CMakeConfigurationKitAspect::additionalConfiguration(k), HostOsInfo::hostOs());
const QStringList additionalInitialCMake =
ProcessArgs::splitArgs(m_buildConfig->initialCMakeArguments(), HostOsInfo::hostOs());
QStringList mergedArgumentList;
std::set_union(additionalInitialCMake.begin(),
additionalInitialCMake.end(),
additionalKitCMake.begin(),
additionalKitCMake.end(),
std::back_inserter(mergedArgumentList));
m_buildConfig->initialCMakeArguments.setValue(ProcessArgs::joinArgs(mergedArgumentList));
}
void CMakeBuildSettingsWidget::updateConfigurationStateIndex(int index)
{
if (index == 0) {
m_configFilterModel->setFilterRole(ConfigModel::ItemIsInitialRole);
m_configFilterModel->setFilterFixedString("1");
} else {
updateAdvancedCheckBox();
}
m_showAdvancedCheckBox->setEnabled(index != 0);
updateButtonState();
}
CMakeConfig CMakeBuildSettingsWidget::getQmlDebugCxxFlags()
{
const TriState qmlDebuggingState = m_buildConfig->qmlDebugging();
if (qmlDebuggingState == TriState::Default) // don't touch anything
return {};
const bool enable = m_buildConfig->qmlDebugging() == TriState::Enabled;
const CMakeConfig configList = m_buildConfig->cmakeBuildSystem()->configurationFromCMake();
const QByteArrayList cxxFlagsPrev{"CMAKE_CXX_FLAGS",
"CMAKE_CXX_FLAGS_DEBUG",
"CMAKE_CXX_FLAGS_RELWITHDEBINFO",
"CMAKE_CXX_FLAGS_INIT"};
const QByteArrayList cxxFlags{"CMAKE_CXX_FLAGS_INIT", "CMAKE_CXX_FLAGS"};
const QByteArray qmlDebug(QT_QML_DEBUG_PARAM);
CMakeConfig changedConfig;
if (enable) {
const FilePath cmakeCache = m_buildConfig->buildDirectory().pathAppended("CMakeCache.txt");
// Only modify the CMAKE_CXX_FLAGS variable if the project was previously configured
// otherwise CMAKE_CXX_FLAGS_INIT will take care of setting the qmlDebug define
if (cmakeCache.exists()) {
for (const CMakeConfigItem &item : configList) {
if (!cxxFlags.contains(item.key))
continue;
CMakeConfigItem it(item);
if (!it.value.contains(qmlDebug)) {
it.value = it.value.append(' ').append(qmlDebug).trimmed();
changedConfig.append(it);
}
}
}
} else {
// Remove -DQT_QML_DEBUG from all configurations, potentially set by previous Qt Creator versions
for (const CMakeConfigItem &item : configList) {
if (!cxxFlagsPrev.contains(item.key))
continue;
CMakeConfigItem it(item);
int index = it.value.indexOf(qmlDebug);
if (index != -1) {
it.value.remove(index, qmlDebug.length());
it.value = it.value.trimmed();
changedConfig.append(it);
}
}
}
return changedConfig;
}
CMakeConfig CMakeBuildSettingsWidget::getSigningFlagsChanges()
{
const CMakeConfig flags = m_buildConfig->signingFlags();
if (flags.isEmpty())
return {};
const CMakeConfig configList = m_buildConfig->cmakeBuildSystem()->configurationFromCMake();
if (configList.isEmpty()) {
// we don't have any configuration --> initial configuration takes care of this itself
return {};
}
CMakeConfig changedConfig;
for (const CMakeConfigItem &signingFlag : flags) {
const CMakeConfigItem existingFlag = Utils::findOrDefault(configList,
Utils::equal(&CMakeConfigItem::key,
signingFlag.key));
const bool notInConfig = existingFlag.key.isEmpty();
if (notInConfig != signingFlag.isUnset || existingFlag.value != signingFlag.value)
changedConfig.append(signingFlag);
}
return changedConfig;
}
void CMakeBuildSettingsWidget::updateSelection()
{
const QModelIndexList selectedIndexes = m_configView->selectionModel()->selectedIndexes();
unsigned int setableCount = 0;
unsigned int unsetableCount = 0;
unsigned int editableCount = 0;
for (const QModelIndex &index : selectedIndexes) {
if (index.isValid() && index.flags().testFlag(Qt::ItemIsSelectable)) {
const ConfigModel::DataItem di = ConfigModel::dataItemFromIndex(index);
if (di.isUnset)
setableCount++;
else
unsetableCount++;
}
if (index.isValid() && index.flags().testFlag(Qt::ItemIsEditable))
editableCount++;
}
m_setButton->setEnabled(setableCount > 0);
m_unsetButton->setEnabled(unsetableCount > 0);
m_editButton->setEnabled(editableCount == 1);
}
void CMakeBuildSettingsWidget::updateConfigurationStateSelection()
{
const bool hasReplyFile
= FileApiParser::scanForCMakeReplyFile(m_buildConfig->buildDirectory()).exists();
const int switchToIndex = hasReplyFile ? 1 : 0;
if (m_configurationStates->currentIndex() != switchToIndex)
m_configurationStates->setCurrentIndex(switchToIndex);
else
emit m_configurationStates->currentChanged(switchToIndex);
}
bool CMakeBuildSettingsWidget::isInitialConfiguration() const
{
return m_configurationStates->currentIndex() == 0;
}
void CMakeBuildSettingsWidget::setVariableUnsetFlag(bool unsetFlag)
{
const QModelIndexList selectedIndexes = m_configView->selectionModel()->selectedIndexes();
bool unsetFlagToggled = false;
for (const QModelIndex &index : selectedIndexes) {
if (index.isValid()) {
const ConfigModel::DataItem di = ConfigModel::dataItemFromIndex(index);
if (di.isUnset != unsetFlag) {
m_configModel->toggleUnsetFlag(mapToSource(m_configView, index));
unsetFlagToggled = true;
}
}
}
if (unsetFlagToggled)
updateSelection();
}
QAction *CMakeBuildSettingsWidget::createForceAction(int type, const QModelIndex &idx)
{
auto t = static_cast<ConfigModel::DataItem::Type>(type);
QString typeString;
switch (type) {
case ConfigModel::DataItem::BOOLEAN:
typeString = Tr::tr("bool", "display string for cmake type BOOLEAN");
break;
case ConfigModel::DataItem::FILE:
typeString = Tr::tr("file", "display string for cmake type FILE");
break;
case ConfigModel::DataItem::DIRECTORY:
typeString = Tr::tr("directory", "display string for cmake type DIRECTORY");
break;
case ConfigModel::DataItem::STRING:
typeString = Tr::tr("string", "display string for cmake type STRING");
break;
case ConfigModel::DataItem::UNKNOWN:
return nullptr;
}
QAction *forceAction = new QAction(Tr::tr("Force to %1").arg(typeString), nullptr);
forceAction->setEnabled(m_configModel->canForceTo(idx, t));
connect(forceAction, &QAction::triggered,
this, [this, idx, t] { m_configModel->forceTo(idx, t); });
return forceAction;
}
bool CMakeBuildSettingsWidget::eventFilter(QObject *target, QEvent *event)
{
// handle context menu events: