Commit 40ff6ab2 authored by dt's avatar dt
Browse files

Make msvc and cmake play together.

Note: This requires a cvs cmake and is not fully tested yet. This adds a
few missing pieces, so now opening new never built projects without a
.user file on systems with just one VS installation should work.
parent 560b0639
......@@ -41,6 +41,7 @@
#include <utils/pathchooser.h>
#include <projectexplorer/environment.h>
#include <projectexplorer/toolchain.h>
#include <QtGui/QVBoxLayout>
#include <QtGui/QFormLayout>
......@@ -187,6 +188,16 @@ void CMakeOpenProjectWizard::setBuildDirectory(const QString &directory)
m_buildDirectory = directory;
}
QString CMakeOpenProjectWizard::msvcVersion() const
{
return m_msvcVersion;
}
void CMakeOpenProjectWizard::setMsvcVersion(const QString &version)
{
m_msvcVersion = version;
}
QStringList CMakeOpenProjectWizard::arguments() const
{
return m_arguments;
......@@ -278,7 +289,7 @@ void CMakeRunPage::initWidgets()
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()));
......@@ -327,7 +338,7 @@ void CMakeRunPage::initializePage()
}
if (m_cmakeWizard->cmakeManager()->hasCodeBlocksMsvcGenerator()) {
m_generatorComboBox->setVisible(true);
QString generator;
QString cachedGenerator;
// Try to find out generator from CMakeCachhe file, if it exists
QFile fi(m_buildDirectory + "/CMakeCache.txt");
if (fi.exists()) {
......@@ -338,16 +349,32 @@ void CMakeRunPage::initializePage()
if (line.startsWith("CMAKE_GENERATOR:INTERNAL=")) {
int splitpos = line.indexOf('=');
if (splitpos != -1) {
generator = line.mid(splitpos).trimmed();
cachedGenerator = line.mid(splitpos).trimmed();
}
break;
}
}
}
}
m_generatorComboBox->clear();
// Find out whether we have multiple mvc versions
QStringList msvcVersions = ProjectExplorer::ToolChain::availableMSVCVersions();
qDebug()<<"msvcVersions:"<<msvcVersions;
if (msvcVersions.isEmpty()) {
} else if (msvcVersions.count() == 1) {
m_generatorComboBox->addItem(tr("NMake Generator"), msvcVersions.first());
} else {
foreach (const QString &msvcVersion, msvcVersions)
m_generatorComboBox->addItem(tr("NMake Generator (%1)").arg(msvcVersion), msvcVersion);
}
if (!generator.isEmpty()) {
m_generatorComboBox->setCurrentIndex((generator == "NMake Makefiles" ? 0 : 1));
}
if (cachedGenerator == "NMake Makefiles" && !msvcVersions.isEmpty())
m_generatorComboBox->setCurrentIndex(0);
m_generatorComboBox->addItem(tr("MinGW Generator"), "mingw");
if (cachedGenerator == "MinGW Makefiles")
m_generatorComboBox->setCurrentIndex(m_generatorComboBox->count() - 1);
} else {
// No new enough cmake, simply hide the combo box
m_generatorComboBox->setVisible(false);
......@@ -362,11 +389,31 @@ void CMakeRunPage::runCMake()
CMakeManager *cmakeManager = m_cmakeWizard->cmakeManager();
#ifdef Q_OS_WIN
const QString generator = m_generatorComboBox->currentIndex() == 0 ? QLatin1String("-GCodeBlocks - NMake Makefiles") : QLatin1String("-GCodeBlocks - MinGW Makefiles");
m_cmakeWizard->setMsvcVersion(QString());
QString generator = QLatin1String("-GCodeBlocks - MinGW Makefiles");
if (m_generatorComboBox->isVisible()) {
// the combobox is shown, check which generator is selected
int index = m_generatorComboBox->currentIndex();
if (index != -1) {
QString version = m_generatorComboBox->itemData(index).toString();
if (version != "mingw") {
generator = "-GCodeBlocks - NMake Makefiles";
m_cmakeWizard->setMsvcVersion(version);
}
}
}
#else // Q_OS_WIN
const QString generator = QLatin1String("-GCodeBlocks - Unix Makefiles");
QString generator = QLatin1String("-GCodeBlocks - Unix Makefiles");
#endif
m_cmakeProcess = cmakeManager->createXmlFile(arguments, m_cmakeWizard->sourceDirectory(), m_buildDirectory, m_cmakeWizard->environment(), generator);
ProjectExplorer::Environment env = m_cmakeWizard->environment();
if (!m_cmakeWizard->msvcVersion().isEmpty()) {
// Add the environment of that msvc version to environment
ProjectExplorer::ToolChain *tc = ProjectExplorer::ToolChain::createMSVCToolChain(m_cmakeWizard->msvcVersion(), false);
tc->addToEnvironment(env);
delete tc;
}
m_cmakeProcess = cmakeManager->createXmlFile(arguments, m_cmakeWizard->sourceDirectory(), m_buildDirectory, env, generator);
connect(m_cmakeProcess, SIGNAL(readyRead()), this, SLOT(cmakeReadyRead()));
connect(m_cmakeProcess, SIGNAL(finished(int)), this, SLOT(cmakeFinished()));
}
......
......@@ -83,6 +83,8 @@ public:
QStringList arguments() const;
void setArguments(const QStringList &args);
ProjectExplorer::Environment environment() const;
QString msvcVersion() const;
void setMsvcVersion(const QString &version);
private:
void init();
bool existsUpToDateXmlFile() const;
......@@ -91,6 +93,7 @@ private:
QString m_buildDirectory;
QString m_sourceDirectory;
QStringList m_arguments;
QString m_msvcVersion;
bool m_creatingCbpFiles;
ProjectExplorer::Environment m_environment;
};
......
......@@ -104,6 +104,7 @@ void CMakeProject::slotActiveBuildConfiguration()
mode,
environment(activeBuildConfiguration()));
copw.exec();
setValue(activeBuildConfiguration(), "msvcVersion", copw.msvcVersion());
}
// reparse
parseCMakeLists();
......@@ -129,8 +130,7 @@ void CMakeProject::updateToolChain(const QString &compiler)
newToolChain = ProjectExplorer::ToolChain::createGccToolChain("gcc");
} else if (compiler == "msvc8") {
// TODO MSVC toolchain
//newToolChain = ProjectExplorer::ToolChain::createMSVCToolChain("//TODO");
Q_ASSERT(false);
newToolChain = ProjectExplorer::ToolChain::createMSVCToolChain(value(activeBuildConfiguration(), "msvcVersion").toString(), false);
} else {
// TODO other toolchains
qDebug()<<"Not implemented yet!!! Qt Creator doesn't know which toolchain to use for"<<compiler;
......@@ -145,6 +145,13 @@ void CMakeProject::updateToolChain(const QString &compiler)
}
}
ProjectExplorer::ToolChain *CMakeProject::toolChain(const QString &buildConfiguration) const
{
if (buildConfiguration != activeBuildConfiguration())
qWarning()<<"CMakeProject asked for toolchain of a not active buildconfiguration";
return m_toolChain;
}
void CMakeProject::changeBuildDirectory(const QString &buildConfiguration, const QString &newBuildDirectory)
{
setValue(buildConfiguration, "buildDirectory", newBuildDirectory);
......@@ -515,6 +522,7 @@ QList<ProjectExplorer::BuildStepConfigWidget*> CMakeProject::subConfigWidgets()
CMakeOpenProjectWizard copw(projectManager(), sourceDirectory(), buildDirectory(buildConfiguration), environment(buildConfiguration));
if (copw.exec() == QDialog::Accepted) {
setValue(buildConfiguration, "buildDirectory", copw.buildDirectory());
setValue(buildConfiguration, "msvcVersion", copw.msvcVersion());
parseCMakeLists();
}
}
......@@ -567,6 +575,7 @@ void CMakeProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader
insertBuildStep(0, makeStep);
addBuildConfiguration("all");
setValue("all", "msvcVersion", copw.msvcVersion());
makeStep->setBuildTarget("all", "all", true);
if (!copw.buildDirectory().isEmpty())
setValue("all", "buildDirectory", copw.buildDirectory());
......@@ -577,6 +586,7 @@ void CMakeProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader
cleanMakeStep->setValue("clean", true);
setActiveBuildConfiguration("all");
} else {
// We have a user file, but we could still be missing the cbp file
// or simply run createXml with the saved settings
......@@ -599,6 +609,7 @@ void CMakeProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader
mode,
environment(activeBuildConfiguration()));
copw.exec();
setValue(activeBuildConfiguration(), "msvcVersion", copw.msvcVersion());
}
}
parseCMakeLists(); // Gets the directory from the active buildconfiguration
......
......@@ -106,6 +106,7 @@ public:
QString sourceDirectory() const;
ProjectExplorer::ToolChain::ToolChainType toolChainType() const;
ProjectExplorer::ToolChain *toolChain(const QString &buildConfiguration) const;
protected:
virtual void saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &writer);
......
......@@ -57,11 +57,8 @@ bool MakeStep::init(const QString &buildConfiguration)
setEnabled(buildConfiguration, true);
setWorkingDirectory(buildConfiguration, m_pro->buildDirectory(buildConfiguration));
#ifdef Q_OS_WIN
setCommand(buildConfiguration, "mingw32-make");
#else // Q_OS_WIN
setCommand(buildConfiguration, "make"); // TODO give full path here?
#endif // Q_OS_WIN
setCommand(buildConfiguration, m_pro->toolChain(buildConfiguration)->makeCommand());
if (!value(buildConfiguration, "cleanConfig").isValid() &&value("clean").isValid() && value("clean").toBool()) {
// Import old settings
......
......@@ -45,7 +45,7 @@ using namespace ProjectExplorer::Internal;
#ifdef Q_OS_WIN64
static const char * MSVC_RegKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VC7";
#else
static const char * MSVC_RegKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7";
static const char * MSVC_RegKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VC7";
#endif
bool ToolChain::equals(ToolChain *a, ToolChain *b)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment