diff --git a/src/plugins/qt4projectmanager/qt4nodes.cpp b/src/plugins/qt4projectmanager/qt4nodes.cpp index e9ef013d8a31a9eb0fb8a45ad8d79a68cbd40627..9bad0d2f20a6c30dc05af8905a7a0227e7b9de99 100644 --- a/src/plugins/qt4projectmanager/qt4nodes.cpp +++ b/src/plugins/qt4projectmanager/qt4nodes.cpp @@ -714,7 +714,6 @@ void Qt4ProFileNode::update() // update other variables QHash<Qt4Variable, QStringList> newVarValues; - newVarValues[CxxCompilerVar] << reader->value(QLatin1String("QMAKE_CXX")); newVarValues[DefinesVar] = reader->values(QLatin1String("DEFINES")); newVarValues[IncludePathVar] = includePaths(reader); newVarValues[UiDirVar] = uiDirPaths(reader); diff --git a/src/plugins/qt4projectmanager/qt4nodes.h b/src/plugins/qt4projectmanager/qt4nodes.h index f5599e90b61c944a4be5ee014150072d3e7926f7..070bd39c5df901fafaa80fea9e3d80b0b2b42e24 100644 --- a/src/plugins/qt4projectmanager/qt4nodes.h +++ b/src/plugins/qt4projectmanager/qt4nodes.h @@ -97,7 +97,6 @@ enum Qt4ProjectType { enum Qt4Variable { DefinesVar = 1, IncludePathVar, - CxxCompilerVar, UiDirVar, MocDirVar, PkgConfigVar diff --git a/src/plugins/qt4projectmanager/qt4project.cpp b/src/plugins/qt4projectmanager/qt4project.cpp index 593aadbf9b80cd12fdbbd5ae33ca698c391b5f87..ebdbf43d3fe4401dfc2f9d6560e0066c30789c21 100644 --- a/src/plugins/qt4projectmanager/qt4project.cpp +++ b/src/plugins/qt4projectmanager/qt4project.cpp @@ -225,7 +225,6 @@ void Qt4ProjectFile::modified(Core::IFile::ReloadBehavior *) */ Qt4Project::Qt4Project(Qt4Manager *manager, const QString& fileName) : - m_toolChain(0), m_manager(manager), m_rootProjectNode(0), m_nodesWatcher(new Internal::Qt4NodesWatcher(this)), @@ -251,8 +250,6 @@ Qt4Project::~Qt4Project() { m_manager->unregisterProject(this); delete m_projectFiles; - delete m_toolChain; - m_toolChain = 0; } void Qt4Project::defaultQtVersionChanged() @@ -380,57 +377,7 @@ void Qt4Project::scheduleUpdateCodeModel(Qt4ProjectManager::Internal::Qt4ProFile QString Qt4Project::makeCommand(const QString &buildConfiguration) const { - return toolChain(buildConfiguration)->makeCommand(); -} - -ProjectExplorer::ToolChain *Qt4Project::toolChain(const QString &buildConfiguration) const -{ - if (debug) - qDebug()<<"Qt4Project::toolChain() for buildconfiguration:"<<buildConfiguration; - Q_UNUSED(buildConfiguration); - ToolChain *m_test= 0; - QtVersion *version = qtVersion(activeBuildConfiguration()); - ToolChain::ToolChainType t = version->toolchainType(); - if (t == ToolChain::MinGW) { - QStringList list = rootProjectNode()->variableValue(Internal::CxxCompilerVar); - QString qmake_cxx = list.isEmpty() ? QString::null : list.first(); - Environment env = Environment::systemEnvironment(); - qtVersion(activeBuildConfiguration())->addToEnvironment(env); - env.prependOrSetPath(qtVersion(activeBuildConfiguration())->mingwDirectory()+"/bin"); - qmake_cxx = env.searchInPath(qmake_cxx); - m_test = ToolChain::createMinGWToolChain(qmake_cxx, version->mingwDirectory()); - //qDebug()<<"Mingw ToolChain"; - } else if(t == ToolChain::MSVC) { - m_test = ToolChain::createMSVCToolChain(version->msvcVersion(), version->isMSVC64Bit()); - //qDebug()<<"MSVC ToolChain ("<<version->msvcVersion()<<")"; - } else if(t == ToolChain::WINCE) { - m_test = ToolChain::createWinCEToolChain(version->msvcVersion(), version->wincePlatform()); - //qDebug()<<"WinCE ToolChain ("<<version->msvcVersion()<<","<<version->wincePlatform()<<")"; - } else if(t == ToolChain::GCC || t == ToolChain::LinuxICC) { - QStringList list = rootProjectNode()->variableValue(Internal::CxxCompilerVar); - QString qmake_cxx = list.isEmpty() ? QString::null : list.first(); - Environment env = Environment::systemEnvironment(); - qtVersion(activeBuildConfiguration())->addToEnvironment(env); - qmake_cxx = env.searchInPath(qmake_cxx); - if (qmake_cxx.isEmpty()) { - // macx-xcode mkspec resets the value of QMAKE_CXX. - // Unfortunately, we need a valid QMAKE_CXX to configure the parser. - qmake_cxx = QLatin1String("cc"); - } - m_test = ToolChain::createGccToolChain(qmake_cxx); - //qDebug()<<"GCC ToolChain ("<<qmake_cxx<<")"; - } else { - qDebug()<<"Could not detect ToolChain for"<<version->mkspec(); - qDebug()<<"Qt Creator doesn't know about the system includes, nor the systems defines."; - } - - if (ToolChain::equals(m_test, m_toolChain)) { - delete m_test; - } else { - delete m_toolChain; - m_toolChain = m_test; - } - return m_toolChain; + return qtVersion(buildConfiguration)->toolChain()->makeCommand(); } void Qt4Project::updateCodeModel() @@ -449,7 +396,7 @@ void Qt4Project::updateCodeModel() QStringList predefinedFrameworkPaths; QByteArray predefinedMacros; - ToolChain *tc = toolChain(activeBuildConfiguration()); + ToolChain *tc = qtVersion(activeBuildConfiguration())->toolChain(); QList<HeaderPath> allHeaderPaths; if (tc) { predefinedMacros = tc->predefinedMacros(); @@ -755,9 +702,6 @@ ProjectExplorer::Environment Qt4Project::baseEnvironment(const QString &buildCon { Environment env = useSystemEnvironment(buildConfiguration) ? Environment(QProcess::systemEnvironment()) : Environment(); qtVersion(buildConfiguration)->addToEnvironment(env); - ToolChain *tc = toolChain(buildConfiguration); - if (tc) - tc->addToEnvironment(env); return env; } diff --git a/src/plugins/qt4projectmanager/qt4project.h b/src/plugins/qt4projectmanager/qt4project.h index 1bf27c59d0afbc0aae5ce6983430a553d369ac47..d89158737a1d74e02b0d60a5446d82034edeb66e 100644 --- a/src/plugins/qt4projectmanager/qt4project.h +++ b/src/plugins/qt4projectmanager/qt4project.h @@ -223,10 +223,6 @@ private: static void findProFile(const QString& fileName, Internal::Qt4ProFileNode *root, QList<Internal::Qt4ProFileNode *> &list); static bool hasSubNode(Internal::Qt4PriFileNode *root, const QString &path); - ProjectExplorer::ToolChain *toolChain(const QString &buildConfiguration) const; - mutable ProjectExplorer::ToolChain *m_toolChain; - - QList<Internal::Qt4ProFileNode *> m_applicationProFileChange; ProjectExplorer::ProjectExplorerPlugin *projectExplorer() const; diff --git a/src/plugins/qt4projectmanager/qtversionmanager.cpp b/src/plugins/qt4projectmanager/qtversionmanager.cpp index 608e05b8a519eb4c0b51ff167b0d9a61db7e8239..62c59936aae2f101de038e98d5c26ffbe05e96d7 100644 --- a/src/plugins/qt4projectmanager/qtversionmanager.cpp +++ b/src/plugins/qt4projectmanager/qtversionmanager.cpp @@ -30,6 +30,7 @@ #include "qtversionmanager.h" #include "qt4projectmanagerconstants.h" +#include "profilereader.h" #include <projectexplorer/debugginghelper.h> #include <projectexplorer/projectexplorer.h> @@ -39,6 +40,7 @@ #include <help/helpplugin.h> #include <utils/qtcassert.h> + #include <QtCore/QProcess> #include <QtCore/QSettings> #include <QtCore/QTime> @@ -314,10 +316,11 @@ void QtVersionManager::setNewQtVersions(QList<QtVersion *> newVersions, int newD QtVersion::QtVersion(const QString &name, const QString &path, int id, bool isSystemVersion) : m_name(name), m_isSystemVersion(isSystemVersion), + m_hasDebuggingHelper(false), m_notInstalled(false), m_defaultConfigIsDebug(true), m_defaultConfigIsDebugAndRelease(true), - m_hasDebuggingHelper(false) + m_toolChain(0) { if (id == -1) m_id = getUniqueId(); @@ -328,15 +331,22 @@ QtVersion::QtVersion(const QString &name, const QString &path, int id, bool isSy QtVersion::QtVersion(const QString &name, const QString &path) : m_name(name), - m_versionInfoUpToDate(false), - m_mkspecUpToDate(false), m_isSystemVersion(false), - m_hasDebuggingHelper(false) + m_hasDebuggingHelper(false), + m_mkspecUpToDate(false), + m_versionInfoUpToDate(false), + m_toolChain(0) { m_id = getUniqueId(); setPath(path); } +QtVersion::~QtVersion() +{ + m_toolChain = 0; + delete m_toolChain; +} + QString QtVersion::name() const { return m_name; @@ -376,6 +386,13 @@ QHash<QString,QString> QtVersion::versionInfo() const return m_versionInfo; } +QString QtVersion::qmakeCXX() const +{ + updateQMakeCXX(); + return m_qmakeCXX; +} + + void QtVersion::setName(const QString &name) { m_name = name; @@ -390,6 +407,9 @@ void QtVersion::setPath(const QString &path) m_designerCommand = m_linguistCommand = m_qmakeCommand = m_uicCommand = QString::null; // TODO do i need to optimize this? m_hasDebuggingHelper = !debuggingHelperLibrary().isEmpty(); + m_qmakeCXX = QString::null; + m_qmakeCXXUpToDate = false; + m_toolChainUpToDate = false; } void QtVersion::updateSourcePath() @@ -757,6 +777,73 @@ QString QtVersion::qmakeCommand() const return QString::null; } +void QtVersion::updateQMakeCXX() const +{ + if (m_qmakeCXXUpToDate) + return; + ProFileReader *reader = new ProFileReader(); + reader->setCumulative(false); + reader->setParsePreAndPostFiles(false); + reader->readProFile(mkspecPath() + "/qmake.conf"); + m_qmakeCXX = reader->value("QMAKE_CXX"); + delete reader; + m_qmakeCXXUpToDate = true; +} + +ProjectExplorer::ToolChain *QtVersion::toolChain() const +{ + updateToolChain(); + return m_toolChain; +} + +void QtVersion::updateToolChain() const +{ + if (m_toolChainUpToDate) + return; + ProjectExplorer::ToolChain *m_test= 0; + ProjectExplorer::ToolChain::ToolChainType t = toolchainType(); + if (t == ProjectExplorer::ToolChain::MinGW) { + QString qmake_cxx = qmakeCXX(); + ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment(); + //addToEnvironment(env); + env.prependOrSetPath(mingwDirectory()+"/bin"); + qmake_cxx = env.searchInPath(qmake_cxx); + m_test = ProjectExplorer::ToolChain::createMinGWToolChain(qmake_cxx, mingwDirectory()); + //qDebug()<<"Mingw ToolChain"; + } else if(t == ProjectExplorer::ToolChain::MSVC) { + m_test = ProjectExplorer::ToolChain::createMSVCToolChain(msvcVersion(), isMSVC64Bit()); + //qDebug()<<"MSVC ToolChain ("<<version->msvcVersion()<<")"; + } else if(t == ProjectExplorer::ToolChain::WINCE) { + m_test = ProjectExplorer::ToolChain::createWinCEToolChain(msvcVersion(), wincePlatform()); + //qDebug()<<"WinCE ToolChain ("<<version->msvcVersion()<<","<<version->wincePlatform()<<")"; + } else if(t == ProjectExplorer::ToolChain::GCC || t == ProjectExplorer::ToolChain::LinuxICC) { + QString qmake_cxx = qmakeCXX(); + ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment(); + //addToEnvironment(env); + qmake_cxx = env.searchInPath(qmake_cxx); + if (qmake_cxx.isEmpty()) { + // macx-xcode mkspec resets the value of QMAKE_CXX. + // Unfortunately, we need a valid QMAKE_CXX to configure the parser. + qmake_cxx = QLatin1String("cc"); + } + m_test = ProjectExplorer::ToolChain::createGccToolChain(qmake_cxx); + //qDebug()<<"GCC ToolChain ("<<qmake_cxx<<")"; + } else { + qDebug()<<"Could not detect ToolChain for"<<mkspec(); + qDebug()<<"Qt Creator doesn't know about the system includes, nor the systems defines."; + } + + if (ProjectExplorer::ToolChain::equals(m_test, m_toolChain)) { + delete m_test; + } else { + delete m_toolChain; + m_toolChain = m_test; + } + + m_toolChainUpToDate = true; +} + + QString QtVersion::findQtBinary(const QStringList &possibleCommands) const { const QString qtdirbin = versionInfo().value(QLatin1String("QT_INSTALL_BINS")) + QLatin1Char('/'); @@ -849,6 +936,7 @@ QString QtVersion::mingwDirectory() const void QtVersion::setMingwDirectory(const QString &directory) { m_mingwDirectory = directory; + m_toolChainUpToDate = false; } QString QtVersion::msvcVersion() const @@ -865,9 +953,10 @@ QString QtVersion::wincePlatform() const void QtVersion::setMsvcVersion(const QString &version) { m_msvcVersion = version; + m_toolChainUpToDate = false; } -void QtVersion::addToEnvironment(ProjectExplorer::Environment &env) +void QtVersion::addToEnvironment(ProjectExplorer::Environment &env) const { env.set("QTDIR", m_path); QString qtdirbin = versionInfo().value("QT_INSTALL_BINS"); @@ -875,6 +964,9 @@ void QtVersion::addToEnvironment(ProjectExplorer::Environment &env) // add libdir, includedir and bindir // or add Mingw dirs // or do nothing on other + ProjectExplorer::ToolChain *tc = toolChain(); + if (tc) + tc->addToEnvironment(env); } int QtVersion::uniqueId() const @@ -946,36 +1038,9 @@ QString QtVersion::buildDebuggingHelperLibrary() ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment(); addToEnvironment(env); - // TODO this is a hack to get, to be removed and rewritten for 1.2 - // For MSVC and MINGW, we need a toolchain to get the right environment - ProjectExplorer::ToolChain::ToolChainType t = toolchainType(); - ProjectExplorer::ToolChain *toolChain = 0; - if (t == ProjectExplorer::ToolChain::MinGW) - toolChain = ProjectExplorer::ToolChain::createMinGWToolChain("g++", mingwDirectory()); - else if(t == ProjectExplorer::ToolChain::MSVC) - toolChain = ProjectExplorer::ToolChain::createMSVCToolChain(msvcVersion(), isMSVC64Bit()); - if (toolChain) { - toolChain->addToEnvironment(env); - delete toolChain; - toolChain = 0; - } - - QString make; - // TODO this is butt ugly - // only qt4projects have a toolchain() method. (Reason mostly, that in order to create - // the toolchain, we need to have the path to gcc - // which might depend on environment settings of the project - // so we hardcode the toolchainType to make conversation here - // and think about how to fix that later - if (t == ProjectExplorer::ToolChain::MinGW) - make = "mingw32-make.exe"; - else if(t == ProjectExplorer::ToolChain::MSVC || t == ProjectExplorer::ToolChain::WINCE) - make = "nmake.exe"; - else if (t == ProjectExplorer::ToolChain::GCC || t == ProjectExplorer::ToolChain::LinuxICC) - make = "make"; - + ProjectExplorer::ToolChain *tc = toolChain(); QString directory = DebuggingHelperLibrary::copyDebuggingHelperLibrary(qtInstallData, path()); - QString output = DebuggingHelperLibrary::buildDebuggingHelperLibrary(directory, make, qmakeCommand(), mkspec(), env); + QString output = DebuggingHelperLibrary::buildDebuggingHelperLibrary(directory, tc->makeCommand(), qmakeCommand(), mkspec(), env); m_hasDebuggingHelper = !debuggingHelperLibrary().isEmpty(); return output; } diff --git a/src/plugins/qt4projectmanager/qtversionmanager.h b/src/plugins/qt4projectmanager/qtversionmanager.h index c407f6f879e7ee185e043785ad97b489367d0923..f81d139314a7115cca97d4cca0398b3c10722a50 100644 --- a/src/plugins/qt4projectmanager/qtversionmanager.h +++ b/src/plugins/qt4projectmanager/qtversionmanager.h @@ -51,8 +51,9 @@ public: QtVersion(const QString &name, const QString &path); QtVersion(const QString &name, const QString &path, int id, bool isSystemVersion = false); QtVersion() - :m_name(QString::null), m_path(QString::null), m_id(-1) - { } + :m_name(QString::null), m_id(-1), m_toolChain(0) + { setPath(QString::null); } + ~QtVersion(); bool isValid() const; //TOOD check that the dir exists and the name is non empty bool isInstalled() const; @@ -67,6 +68,8 @@ public: QString uicCommand() const; QString designerCommand() const; QString linguistCommand() const; + QString qmakeCXX() const; + ProjectExplorer::ToolChain *toolChain() const; QString qtVersionString() const; // Returns the PREFIX, BINPREFIX, DOCPREFIX and similar information @@ -79,7 +82,7 @@ public: QString msvcVersion() const; QString wincePlatform() const; void setMsvcVersion(const QString &version); - void addToEnvironment(ProjectExplorer::Environment &env); + void addToEnvironment(ProjectExplorer::Environment &env) const; bool hasDebuggingHelper() const; QString debuggingHelperLibrary() const; @@ -104,32 +107,41 @@ private: void setName(const QString &name); void setPath(const QString &path); void updateSourcePath(); - void updateVersionInfo() const; void updateMkSpec() const; + void updateVersionInfo() const; + void updateQMakeCXX() const; + void updateToolChain() const; QString findQtBinary(const QStringList &possibleName) const; QString m_name; - mutable bool m_versionInfoUpToDate; - mutable bool m_mkspecUpToDate; QString m_path; QString m_sourcePath; - mutable QString m_mkspec; // updated lazily - mutable QString m_mkspecFullPath; QString m_mingwDirectory; QString m_msvcVersion; - mutable QHash<QString,QString> m_versionInfo; // updated lazily int m_id; bool m_isSystemVersion; + bool m_hasDebuggingHelper; + + mutable bool m_mkspecUpToDate; + mutable QString m_mkspec; // updated lazily + mutable QString m_mkspecFullPath; + + mutable bool m_versionInfoUpToDate; + mutable QHash<QString,QString> m_versionInfo; // updated lazily mutable bool m_notInstalled; mutable bool m_defaultConfigIsDebug; mutable bool m_defaultConfigIsDebugAndRelease; + mutable QString m_qmakeCommand; + mutable QString m_qtVersionString; mutable QString m_uicCommand; mutable QString m_designerCommand; mutable QString m_linguistCommand; - // This is updated on first call to qmakeCommand - // That function is called from updateVersionInfo() - mutable QString m_qtVersionString; - bool m_hasDebuggingHelper; + + mutable bool m_qmakeCXXUpToDate; + mutable QString m_qmakeCXX; + + mutable bool m_toolChainUpToDate; + mutable ProjectExplorer::ToolChain *m_toolChain; }; class QtVersionManager : public QObject diff --git a/src/shared/proparser/profileevaluator.cpp b/src/shared/proparser/profileevaluator.cpp index 04652b7db9f5f481bccc41148deecd6099114bad..133fd2a702ec411862218ba1b0563cbb5677ff5c 100644 --- a/src/shared/proparser/profileevaluator.cpp +++ b/src/shared/proparser/profileevaluator.cpp @@ -221,6 +221,7 @@ public: ProFile *m_prevProFile; // See m_prevLineNo QStringList m_addUserConfigCmdArgs; QStringList m_removeUserConfigCmdArgs; + bool m_parsePreAndPostFiles; }; ProFileEvaluator::Private::Private(ProFileEvaluator *q_) @@ -240,6 +241,7 @@ ProFileEvaluator::Private::Private(ProFileEvaluator *q_) m_invertNext = false; m_skipLevel = 0; m_isFirstVariableValue = true; + m_parsePreAndPostFiles = true; } bool ProFileEvaluator::Private::read(ProFile *pro) @@ -648,11 +650,9 @@ bool ProFileEvaluator::Private::visitBeginProFile(ProFile * pro) m_profileStack.push(pro); const QString mkspecDirectory = propertyValue(QLatin1String("QMAKE_MKSPECS")); - if (!mkspecDirectory.isEmpty()) { + if (!mkspecDirectory.isEmpty() && m_parsePreAndPostFiles) { bool cumulative = m_cumulative; m_cumulative = false; - // This is what qmake does, everything set in the mkspec is also set - // But this also creates a lot of problems evaluateFile(mkspecDirectory + QLatin1String("/default/qmake.conf"), &ok); evaluateFile(mkspecDirectory + QLatin1String("/features/default_pre.prf"), &ok); @@ -677,7 +677,7 @@ bool ProFileEvaluator::Private::visitEndProFile(ProFile * pro) m_lineNo = pro->lineNumber(); if (m_profileStack.count() == 1 && !m_oldPath.isEmpty()) { const QString &mkspecDirectory = propertyValue(QLatin1String("QMAKE_MKSPECS")); - if (!mkspecDirectory.isEmpty()) { + if (!mkspecDirectory.isEmpty() && m_parsePreAndPostFiles) { bool cumulative = m_cumulative; m_cumulative = false; @@ -2322,6 +2322,11 @@ void ProFileEvaluator::setUserConfigCmdArgs(const QStringList &addUserConfigCmdA d->m_removeUserConfigCmdArgs = removeUserConfigCmdArgs; } +void ProFileEvaluator::setParsePreAndPostFiles(bool on) +{ + d->m_parsePreAndPostFiles = on; +} + void evaluateProFile(const ProFileEvaluator &visitor, QHash<QByteArray, QStringList> *varMap) { QStringList sourceFiles; diff --git a/src/shared/proparser/profileevaluator.h b/src/shared/proparser/profileevaluator.h index b6df287b7d79d444ea2bc9bd7aad40f902449daa..d7eb5a549a8ba6f122581c7fc0b7a5c8c0dbe51c 100644 --- a/src/shared/proparser/profileevaluator.h +++ b/src/shared/proparser/profileevaluator.h @@ -66,6 +66,7 @@ public: void setCumulative(bool on); // Default is true! void setOutputDir(const QString &dir); // Default is empty void setUserConfigCmdArgs(const QStringList &addUserConfigCmdArgs, const QStringList &removeUserConfigCmdArgs); + void setParsePreAndPostFiles(bool on); // Default is true bool queryProFile(ProFile *pro); bool accept(ProFile *pro);