From 560b06391d10a8be5b63f2405b9dae4ff8d3194a Mon Sep 17 00:00:00 2001 From: dt Date: Thu, 2 Jul 2009 11:30:29 +0200 Subject: [PATCH] Add msvc support to cmake plugin. Depends on a cvs version of cmake. The CodeBlocks - NMake Makefiles generator combination is only available in the cvs version of cmake. This has not been extensively tested at all. --- .../cmakeopenprojectwizard.cpp | 47 ++++++++++++++++++- .../cmakeopenprojectwizard.h | 2 + .../cmakeprojectmanager.cpp | 28 ++++++++--- .../cmakeprojectmanager/cmakeprojectmanager.h | 7 ++- 4 files changed, 76 insertions(+), 8 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp index f92ad07a6d7..c82205da100 100644 --- a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp @@ -27,6 +27,15 @@ ** **************************************************************************/ + +/// TODO +/// To check +/// a) with an old cmake +/// => should not show combobox always use mingw generator +/// b) with an new cmake +/// always show combo box, defaulting if there's already a existing build + + #include "cmakeopenprojectwizard.h" #include "cmakeprojectmanager.h" @@ -268,12 +277,15 @@ void CMakeRunPage::initWidgets() m_argumentsLineEdit = new QLineEdit(this); connect(m_argumentsLineEdit,SIGNAL(returnPressed()), this, SLOT(runCMake())); + m_generatorComboBox = new QComboBox(this); + m_generatorComboBox->addItems(QStringList() << tr("NMake Generator") << tr("MinGW Generator")); m_runCMake = new QPushButton(this); m_runCMake->setText(tr("Run CMake")); connect(m_runCMake, SIGNAL(clicked()), this, SLOT(runCMake())); QHBoxLayout *hbox = new QHBoxLayout; hbox->addWidget(m_argumentsLineEdit); + hbox->addWidget(m_generatorComboBox); hbox->addWidget(m_runCMake); fl->addRow(tr("Arguments"), hbox); @@ -313,6 +325,33 @@ void CMakeRunPage::initializePage() "Some projects require command line arguments to the " "initial cmake call.")); } + if (m_cmakeWizard->cmakeManager()->hasCodeBlocksMsvcGenerator()) { + m_generatorComboBox->setVisible(true); + QString generator; + // Try to find out generator from CMakeCachhe file, if it exists + QFile fi(m_buildDirectory + "/CMakeCache.txt"); + if (fi.exists()) { + // Cache exists, then read it... + if (fi.open(QIODevice::ReadOnly)) { + while (fi.canReadLine()) { + QString line = fi.readLine(); + if (line.startsWith("CMAKE_GENERATOR:INTERNAL=")) { + int splitpos = line.indexOf('='); + if (splitpos != -1) { + generator = line.mid(splitpos).trimmed(); + } + break; + } + } + } + } + if (!generator.isEmpty()) { + m_generatorComboBox->setCurrentIndex((generator == "NMake Makefiles" ? 0 : 1)); + } + } else { + // No new enough cmake, simply hide the combo box + m_generatorComboBox->setVisible(false); + } } void CMakeRunPage::runCMake() @@ -321,7 +360,13 @@ void CMakeRunPage::runCMake() m_argumentsLineEdit->setEnabled(false); QStringList arguments = ProjectExplorer::Environment::parseCombinedArgString(m_argumentsLineEdit->text()); CMakeManager *cmakeManager = m_cmakeWizard->cmakeManager(); - m_cmakeProcess = cmakeManager->createXmlFile(arguments, m_cmakeWizard->sourceDirectory(), m_buildDirectory, m_cmakeWizard->environment()); + +#ifdef Q_OS_WIN + const QString generator = m_generatorComboBox->currentIndex() == 0 ? QLatin1String("-GCodeBlocks - NMake Makefiles") : QLatin1String("-GCodeBlocks - MinGW Makefiles"); +#else // Q_OS_WIN + const QString generator = QLatin1String("-GCodeBlocks - Unix Makefiles"); +#endif + m_cmakeProcess = cmakeManager->createXmlFile(arguments, m_cmakeWizard->sourceDirectory(), m_buildDirectory, m_cmakeWizard->environment(), generator); connect(m_cmakeProcess, SIGNAL(readyRead()), this, SLOT(cmakeReadyRead())); connect(m_cmakeProcess, SIGNAL(finished(int)), this, SLOT(cmakeFinished())); } diff --git a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h index 05c7267d97a..0838b133d30 100644 --- a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h +++ b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -147,6 +148,7 @@ private: QPushButton *m_runCMake; QProcess *m_cmakeProcess; QLineEdit *m_argumentsLineEdit; + QComboBox *m_generatorComboBox; QLabel *m_descriptionLabel; bool m_complete; Mode m_mode; diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp index a868427ffb3..1461c75b075 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp @@ -92,11 +92,16 @@ QString CMakeManager::cmakeExecutable() const return m_settingsPage->cmakeExecutable(); } +bool CMakeManager::hasCodeBlocksMsvcGenerator() const +{ + return m_settingsPage->hasCodeBlocksMsvcGenerator(); +} + // TODO need to refactor this out // we probably want the process instead of this function // cmakeproject then could even run the cmake process in the background, adding the files afterwards // sounds like a plan -QProcess *CMakeManager::createXmlFile(const QStringList &arguments, const QString &sourceDirectory, const QDir &buildDirectory, const ProjectExplorer::Environment &env) +QProcess *CMakeManager::createXmlFile(const QStringList &arguments, const QString &sourceDirectory, const QDir &buildDirectory, const ProjectExplorer::Environment &env, const QString &generator) { // We create a cbp file, only if we didn't find a cbp file in the base directory // Yet that can still override cbp files in subdirectories @@ -115,11 +120,6 @@ QProcess *CMakeManager::createXmlFile(const QStringList &arguments, const QStrin cmake->setProcessChannelMode(QProcess::MergedChannels); cmake->setEnvironment(env.toStringList()); -#ifdef Q_OS_WIN - const QString generator = QLatin1String("-GCodeBlocks - MinGW Makefiles"); -#else // Q_OS_WIN - const QString generator = QLatin1String("-GCodeBlocks - Unix Makefiles"); -#endif // Q_OS_WIN const QString srcdir = buildDirectory.exists(QLatin1String("CMakeCache.txt")) ? QString(QLatin1Char('.')) : sourceDirectory; qDebug()<start(cmakeExecutable(), QStringList() << srcdir << arguments << generator); @@ -185,6 +185,7 @@ void CMakeRunner::run(QFutureInterface &fi) m_mutex.lock(); m_supportsQtCreator = response.contains(QLatin1String("QtCreator")); + m_hasCodeBlocksMsvcGenerator = response.contains(QLatin1String("CodeBlocks - NMake Makefiles")); m_version = versionRegexp.cap(1); if (!(versionRegexp.capturedTexts().size() > 3)) m_version += QLatin1Char('.') + versionRegexp.cap(3); @@ -230,6 +231,15 @@ bool CMakeRunner::supportsQtCreator() const return result; } +bool CMakeRunner::hasCodeBlocksMsvcGenerator() const +{ + waitForUpToDate(); + m_mutex.lock(); + bool result = m_hasCodeBlocksMsvcGenerator; + m_mutex.unlock(); + return result; +} + void CMakeRunner::waitForUpToDate() const { m_future.waitForFinished(); @@ -317,6 +327,12 @@ QString CMakeSettingsPage::cmakeExecutable() const return m_cmakeRunner.executable(); } +bool CMakeSettingsPage::hasCodeBlocksMsvcGenerator() const +{ + return m_cmakeRunner.hasCodeBlocksMsvcGenerator(); +} + + void CMakeSettingsPage::askUserForCMakeExecutable() { // TODO implement diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h index c6e37e4e2d0..798a6b36ac1 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h @@ -62,7 +62,9 @@ public: QProcess* createXmlFile(const QStringList &arguments, const QString &sourceDirectory, const QDir &buildDirectory, - const ProjectExplorer::Environment &env); + const ProjectExplorer::Environment &env, + const QString &generator); + bool hasCodeBlocksMsvcGenerator() const; static QString findCbpFile(const QDir &); static QString findDumperLibrary(const ProjectExplorer::Environment &env); @@ -82,6 +84,7 @@ public: QString executable() const; QString version() const; bool supportsQtCreator() const; + bool hasCodeBlocksMsvcGenerator() const; private: void run(QFutureInterface &fi); @@ -89,6 +92,7 @@ private: QString m_executable; QString m_version; bool m_supportsQtCreator; + bool m_hasCodeBlocksMsvcGenerator; bool m_cacheUpToDate; mutable QFuture m_future; mutable QMutex m_mutex; @@ -111,6 +115,7 @@ public: QString cmakeExecutable() const; void askUserForCMakeExecutable(); + bool hasCodeBlocksMsvcGenerator() const; private: void updateCachedInformation() const; void saveSettings() const;