1 /****************************************************************************
2 **
3 ** Copyright (C) 2019 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #include "qmakesettings.h"
27 
28 #include <coreplugin/icore.h>
29 
30 #include <projectexplorer/projectexplorerconstants.h>
31 
32 #include <utils/layoutbuilder.h>
33 
34 using namespace Utils;
35 
36 namespace QmakeProjectManager {
37 namespace Internal {
38 
QmakeSettings()39 QmakeSettings::QmakeSettings()
40 {
41     setAutoApply(false);
42 
43     registerAspect(&m_warnAgainstUnalignedBuildDir);
44     m_warnAgainstUnalignedBuildDir.setSettingsKey("QmakeProjectManager/WarnAgainstUnalignedBuildDir");
45     m_warnAgainstUnalignedBuildDir.setDefaultValue(HostOsInfo::isWindowsHost());
46     m_warnAgainstUnalignedBuildDir.setLabelText(tr("Warn if a project's source and "
47             "build directories are not at the same level"));
48     m_warnAgainstUnalignedBuildDir.setToolTip(tr("Qmake has subtle bugs that "
49             "can be triggered if source and build directory are not at the same level."));
50 
51     registerAspect(&m_alwaysRunQmake);
52     m_alwaysRunQmake.setSettingsKey("QmakeProjectManager/AlwaysRunQmake");
53     m_alwaysRunQmake.setLabelText(tr("Run qmake on every build"));
54     m_alwaysRunQmake.setToolTip(tr("This option can help to prevent failures on "
55             "incremental builds, but might slow them down unnecessarily in the general case."));
56 
57     registerAspect(&m_ignoreSystemFunction);
58     m_ignoreSystemFunction.setSettingsKey("QmakeProjectManager/RunSystemFunction");
59     m_ignoreSystemFunction.setLabelText(tr("Ignore qmake's system() function when parsing a project"));
60     m_ignoreSystemFunction.setToolTip(tr("Checking this option avoids unwanted side effects, "
61              "but may result in inexact parsing results."));
62     // The settings value has been stored with the opposite meaning for a while.
63     // Avoid changing the stored value, but flip it on read/write:
64     const auto invertBoolVariant = [](const QVariant &v) { return QVariant(!v.toBool()); };
65     m_ignoreSystemFunction.setFromSettingsTransformation(invertBoolVariant);
66     m_ignoreSystemFunction.setToSettingsTransformation(invertBoolVariant);
67 
68     readSettings(Core::ICore::settings());
69 }
70 
warnAgainstUnalignedBuildDir()71 bool QmakeSettings::warnAgainstUnalignedBuildDir()
72 {
73     return instance().m_warnAgainstUnalignedBuildDir.value();
74 }
75 
alwaysRunQmake()76 bool QmakeSettings::alwaysRunQmake()
77 {
78     return instance().m_alwaysRunQmake.value();
79 }
80 
runSystemFunction()81 bool QmakeSettings::runSystemFunction()
82 {
83     return !instance().m_ignoreSystemFunction.value(); // Note: negated.
84 }
85 
instance()86 QmakeSettings &QmakeSettings::instance()
87 {
88     static QmakeSettings theSettings;
89     return theSettings;
90 }
91 
92 class SettingsWidget final : public Core::IOptionsPageWidget
93 {
94     Q_DECLARE_TR_FUNCTIONS(QmakeProjectManager::Internal::QmakeSettingsPage)
95 
96 public:
SettingsWidget()97     SettingsWidget()
98     {
99         auto &s = QmakeSettings::instance();
100         using namespace Layouting;
101         Column {
102             s.m_warnAgainstUnalignedBuildDir,
103             s.m_alwaysRunQmake,
104             s.m_ignoreSystemFunction,
105             Stretch()
106         }.attachTo(this);
107     }
108 
apply()109     void apply() final
110     {
111         auto &s = QmakeSettings::instance();
112         if (s.isDirty()) {
113             s.apply();
114             s.writeSettings(Core::ICore::settings());
115         }
116     }
117 };
118 
QmakeSettingsPage()119 QmakeSettingsPage::QmakeSettingsPage()
120 {
121     setId("K.QmakeProjectManager.QmakeSettings");
122     setDisplayName(SettingsWidget::tr("Qmake"));
123     setCategory(ProjectExplorer::Constants::BUILD_AND_RUN_SETTINGS_CATEGORY);
124     setWidgetCreator([] { return new SettingsWidget; });
125 }
126 
127 } // namespace Internal
128 } // namespace QmakeProjectManager
129