2007-11-02 18:55:57 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
2007-11-02 18:50:17 +03:00
|
|
|
|
|
|
|
#include "QCMake.h"
|
|
|
|
|
|
|
|
#include <QDir>
|
2007-11-05 21:20:54 +03:00
|
|
|
#include <QCoreApplication>
|
2007-11-02 18:50:17 +03:00
|
|
|
|
|
|
|
#include "cmake.h"
|
|
|
|
#include "cmCacheManager.h"
|
|
|
|
#include "cmSystemTools.h"
|
2007-11-05 21:20:54 +03:00
|
|
|
#include "cmExternalMakefileProjectGenerator.h"
|
2007-11-02 18:50:17 +03:00
|
|
|
|
|
|
|
QCMake::QCMake(QObject* p)
|
|
|
|
: QObject(p)
|
|
|
|
{
|
2008-03-12 05:51:56 +03:00
|
|
|
this->SuppressDevWarnings = false;
|
2007-11-05 21:20:54 +03:00
|
|
|
qRegisterMetaType<QCMakeCacheProperty>();
|
|
|
|
qRegisterMetaType<QCMakeCachePropertyList>();
|
2007-11-02 18:50:17 +03:00
|
|
|
|
2008-02-15 02:18:10 +03:00
|
|
|
QDir execDir(QCoreApplication::applicationDirPath());
|
|
|
|
|
|
|
|
#if defined(Q_OS_MAC)
|
2008-02-16 21:05:03 +03:00
|
|
|
if(execDir.exists("../bin/cmake"))
|
|
|
|
{
|
|
|
|
execDir.cd("../bin");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
execDir.cd("../../../"); // path to cmake in build directory (need to fix for deployment)
|
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
#endif
|
2008-02-15 02:18:10 +03:00
|
|
|
|
|
|
|
QString cmakeCommand = QString("cmake")+cmSystemTools::GetExecutableExtension();
|
|
|
|
cmakeCommand = execDir.filePath(cmakeCommand);
|
|
|
|
|
2007-11-02 18:50:17 +03:00
|
|
|
cmSystemTools::DisableRunCommandOutput();
|
|
|
|
cmSystemTools::SetRunCommandHideConsole(true);
|
|
|
|
cmSystemTools::SetErrorCallback(QCMake::errorCallback, this);
|
2008-02-15 02:18:10 +03:00
|
|
|
cmSystemTools::FindExecutableDirectory(cmakeCommand.toAscii().data());
|
2007-11-02 18:50:17 +03:00
|
|
|
|
|
|
|
this->CMakeInstance = new cmake;
|
2008-02-15 02:18:10 +03:00
|
|
|
this->CMakeInstance->SetCMakeCommand(cmakeCommand.toAscii().data());
|
2008-02-15 20:12:48 +03:00
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
this->CMakeInstance->SetCMakeEditCommand("cmake-gui.app/Contents/MacOS/cmake-gui");
|
|
|
|
#else
|
2008-02-12 17:49:42 +03:00
|
|
|
this->CMakeInstance->SetCMakeEditCommand("cmake-gui");
|
2008-02-15 20:12:48 +03:00
|
|
|
#endif
|
2007-11-02 18:50:17 +03:00
|
|
|
this->CMakeInstance->SetProgressCallback(QCMake::progressCallback, this);
|
2007-11-05 21:20:54 +03:00
|
|
|
|
|
|
|
std::vector<std::string> generators;
|
|
|
|
this->CMakeInstance->GetRegisteredGenerators(generators);
|
|
|
|
std::vector<std::string>::iterator iter;
|
|
|
|
for(iter = generators.begin(); iter != generators.end(); ++iter)
|
|
|
|
{
|
2007-11-09 00:47:00 +03:00
|
|
|
this->AvailableGenerators.append(iter->c_str());
|
2007-11-05 21:20:54 +03:00
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QCMake::~QCMake()
|
|
|
|
{
|
|
|
|
delete this->CMakeInstance;
|
|
|
|
//cmDynamicLoader::FlushCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QCMake::loadCache(const QString& dir)
|
|
|
|
{
|
|
|
|
this->setBinaryDirectory(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QCMake::setSourceDirectory(const QString& dir)
|
|
|
|
{
|
2007-11-04 02:48:59 +03:00
|
|
|
if(this->SourceDirectory != dir)
|
|
|
|
{
|
2008-04-08 03:19:50 +04:00
|
|
|
this->SourceDirectory = QDir::fromNativeSeparators(dir);
|
|
|
|
emit this->sourceDirChanged(this->SourceDirectory);
|
2007-11-04 02:48:59 +03:00
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void QCMake::setBinaryDirectory(const QString& dir)
|
|
|
|
{
|
2007-11-04 02:48:59 +03:00
|
|
|
if(this->BinaryDirectory != dir)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2008-04-08 03:19:50 +04:00
|
|
|
this->BinaryDirectory = QDir::fromNativeSeparators(dir);
|
|
|
|
emit this->binaryDirChanged(this->BinaryDirectory);
|
2007-11-04 02:48:59 +03:00
|
|
|
cmCacheManager *cachem = this->CMakeInstance->GetCacheManager();
|
2007-11-05 21:20:54 +03:00
|
|
|
this->setGenerator(QString());
|
2008-04-08 03:19:50 +04:00
|
|
|
if(!this->CMakeInstance->GetCacheManager()->LoadCache(
|
|
|
|
this->BinaryDirectory.toLocal8Bit().data()))
|
2007-11-05 21:20:54 +03:00
|
|
|
{
|
2008-04-08 03:19:50 +04:00
|
|
|
QDir testDir(this->BinaryDirectory);
|
2007-11-05 21:20:54 +03:00
|
|
|
if(testDir.exists("CMakeCache.txt"))
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("There is a CMakeCache.txt file for the current binary "
|
|
|
|
"tree but cmake does not have permission to read it. "
|
|
|
|
"Please check the permissions of the directory you are trying to run CMake on.");
|
|
|
|
}
|
|
|
|
}
|
2008-03-12 05:51:56 +03:00
|
|
|
|
2007-11-04 02:48:59 +03:00
|
|
|
QCMakeCachePropertyList props = this->properties();
|
|
|
|
emit this->propertiesChanged(props);
|
|
|
|
cmCacheManager::CacheIterator itm = cachem->NewIterator();
|
|
|
|
if ( itm.Find("CMAKE_HOME_DIRECTORY"))
|
|
|
|
{
|
|
|
|
setSourceDirectory(itm.GetValue());
|
|
|
|
}
|
2007-11-05 21:20:54 +03:00
|
|
|
if ( itm.Find("CMAKE_GENERATOR"))
|
|
|
|
{
|
|
|
|
const char* extraGen = cachem->GetCacheValue("CMAKE_EXTRA_GENERATOR");
|
|
|
|
std::string curGen = cmExternalMakefileProjectGenerator::
|
|
|
|
CreateFullGeneratorName(itm.GetValue(), extraGen);
|
2007-11-09 00:47:00 +03:00
|
|
|
this->setGenerator(curGen.c_str());
|
2007-11-05 21:20:54 +03:00
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
void QCMake::setGenerator(const QString& gen)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
if(this->Generator != gen)
|
|
|
|
{
|
|
|
|
this->Generator = gen;
|
|
|
|
emit this->generatorChanged(this->Generator);
|
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void QCMake::configure()
|
|
|
|
{
|
|
|
|
this->CMakeInstance->SetHomeDirectory(this->SourceDirectory.toAscii().data());
|
|
|
|
this->CMakeInstance->SetStartDirectory(this->SourceDirectory.toAscii().data());
|
|
|
|
this->CMakeInstance->SetHomeOutputDirectory(this->BinaryDirectory.toAscii().data());
|
|
|
|
this->CMakeInstance->SetStartOutputDirectory(this->BinaryDirectory.toAscii().data());
|
|
|
|
this->CMakeInstance->SetGlobalGenerator(
|
2007-11-05 21:20:54 +03:00
|
|
|
this->CMakeInstance->CreateGlobalGenerator(this->Generator.toAscii().data()));
|
2007-11-02 18:50:17 +03:00
|
|
|
this->CMakeInstance->LoadCache();
|
2008-03-12 05:51:56 +03:00
|
|
|
this->CMakeInstance->SetSuppressDevWarnings(this->SuppressDevWarnings);
|
2008-02-08 19:26:08 +03:00
|
|
|
this->CMakeInstance->PreLoadCMakeFiles();
|
2007-11-02 18:50:17 +03:00
|
|
|
|
|
|
|
cmSystemTools::ResetErrorOccuredFlag();
|
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
int err = this->CMakeInstance->Configure();
|
2007-11-02 18:50:17 +03:00
|
|
|
|
|
|
|
emit this->propertiesChanged(this->properties());
|
2007-11-05 21:20:54 +03:00
|
|
|
emit this->configureDone(err);
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void QCMake::generate()
|
|
|
|
{
|
|
|
|
cmSystemTools::ResetErrorOccuredFlag();
|
2007-11-05 21:20:54 +03:00
|
|
|
int err = this->CMakeInstance->Generate();
|
|
|
|
emit this->generateDone(err);
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
2007-11-13 07:54:49 +03:00
|
|
|
void QCMake::setProperties(const QCMakeCachePropertyList& newProps)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2007-11-13 07:54:49 +03:00
|
|
|
QCMakeCachePropertyList props = newProps;
|
|
|
|
|
2007-11-08 18:17:37 +03:00
|
|
|
QStringList toremove;
|
2007-11-13 07:54:49 +03:00
|
|
|
|
|
|
|
// set the value of properties
|
2007-11-02 18:50:17 +03:00
|
|
|
cmCacheManager *cachem = this->CMakeInstance->GetCacheManager();
|
2007-11-08 18:17:37 +03:00
|
|
|
for(cmCacheManager::CacheIterator i = cachem->NewIterator();
|
|
|
|
!i.IsAtEnd(); i.Next())
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2007-11-08 18:17:37 +03:00
|
|
|
|
|
|
|
if(i.GetType() == cmCacheManager::INTERNAL ||
|
|
|
|
i.GetType() == cmCacheManager::STATIC)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QCMakeCacheProperty prop;
|
|
|
|
prop.Key = i.GetName();
|
|
|
|
int idx = props.indexOf(prop);
|
|
|
|
if(idx == -1)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2007-11-08 18:17:37 +03:00
|
|
|
toremove.append(i.GetName());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prop = props[idx];
|
2007-11-03 17:30:52 +03:00
|
|
|
if(prop.Value.type() == QVariant::Bool)
|
|
|
|
{
|
2007-11-08 18:17:37 +03:00
|
|
|
i.SetValue(prop.Value.toBool() ? "ON" : "OFF");
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-08 18:17:37 +03:00
|
|
|
i.SetValue(prop.Value.toString().toAscii().data());
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-13 07:54:49 +03:00
|
|
|
props.removeAt(idx);
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
2007-11-08 18:17:37 +03:00
|
|
|
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
2007-11-08 18:17:37 +03:00
|
|
|
|
2007-11-13 07:54:49 +03:00
|
|
|
// remove some properites
|
2007-11-08 18:17:37 +03:00
|
|
|
foreach(QString s, toremove)
|
|
|
|
{
|
|
|
|
cachem->RemoveCacheEntry(s.toAscii().data());
|
|
|
|
}
|
|
|
|
|
2007-11-13 07:54:49 +03:00
|
|
|
// add some new properites
|
|
|
|
foreach(QCMakeCacheProperty s, props)
|
|
|
|
{
|
|
|
|
if(s.Type == QCMakeCacheProperty::BOOL)
|
|
|
|
{
|
|
|
|
this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(),
|
|
|
|
s.Value.toBool() ? "ON" : "OFF",
|
|
|
|
s.Help.toAscii().data(),
|
|
|
|
cmCacheManager::BOOL);
|
|
|
|
}
|
|
|
|
else if(s.Type == QCMakeCacheProperty::STRING)
|
|
|
|
{
|
|
|
|
this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(),
|
|
|
|
s.Value.toString().toAscii().data(),
|
|
|
|
s.Help.toAscii().data(),
|
|
|
|
cmCacheManager::STRING);
|
|
|
|
}
|
|
|
|
else if(s.Type == QCMakeCacheProperty::PATH)
|
|
|
|
{
|
|
|
|
this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(),
|
|
|
|
s.Value.toString().toAscii().data(),
|
|
|
|
s.Help.toAscii().data(),
|
|
|
|
cmCacheManager::PATH);
|
|
|
|
}
|
|
|
|
else if(s.Type == QCMakeCacheProperty::FILEPATH)
|
|
|
|
{
|
|
|
|
this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(),
|
|
|
|
s.Value.toString().toAscii().data(),
|
|
|
|
s.Help.toAscii().data(),
|
|
|
|
cmCacheManager::FILEPATH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-03 17:30:52 +03:00
|
|
|
cachem->SaveCache(this->BinaryDirectory.toAscii().data());
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
QCMakeCachePropertyList QCMake::properties() const
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
|
|
|
QCMakeCachePropertyList ret;
|
|
|
|
|
|
|
|
cmCacheManager *cachem = this->CMakeInstance->GetCacheManager();
|
|
|
|
for(cmCacheManager::CacheIterator i = cachem->NewIterator();
|
|
|
|
!i.IsAtEnd(); i.Next())
|
|
|
|
{
|
|
|
|
|
|
|
|
if(i.GetType() == cmCacheManager::INTERNAL ||
|
2008-02-14 16:55:29 +03:00
|
|
|
i.GetType() == cmCacheManager::STATIC ||
|
|
|
|
i.GetType() == cmCacheManager::UNINITIALIZED)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QCMakeCacheProperty prop;
|
|
|
|
prop.Key = i.GetName();
|
|
|
|
prop.Help = i.GetProperty("HELPSTRING");
|
|
|
|
prop.Value = i.GetValue();
|
|
|
|
prop.Advanced = i.GetPropertyAsBool("ADVANCED");
|
|
|
|
|
|
|
|
if(i.GetType() == cmCacheManager::BOOL)
|
|
|
|
{
|
|
|
|
prop.Type = QCMakeCacheProperty::BOOL;
|
2007-11-03 17:30:52 +03:00
|
|
|
prop.Value = cmSystemTools::IsOn(i.GetValue());
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
else if(i.GetType() == cmCacheManager::PATH)
|
|
|
|
{
|
|
|
|
prop.Type = QCMakeCacheProperty::PATH;
|
|
|
|
}
|
|
|
|
else if(i.GetType() == cmCacheManager::FILEPATH)
|
|
|
|
{
|
|
|
|
prop.Type = QCMakeCacheProperty::FILEPATH;
|
|
|
|
}
|
|
|
|
else if(i.GetType() == cmCacheManager::STRING)
|
|
|
|
{
|
|
|
|
prop.Type = QCMakeCacheProperty::STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.append(prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QCMake::interrupt()
|
|
|
|
{
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QCMake::progressCallback(const char* msg, float percent, void* cd)
|
|
|
|
{
|
|
|
|
QCMake* self = reinterpret_cast<QCMake*>(cd);
|
2007-11-03 17:30:52 +03:00
|
|
|
if(percent >= 0)
|
|
|
|
{
|
|
|
|
emit self->progressChanged(msg, percent);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
emit self->outputMessage(msg);
|
|
|
|
}
|
2008-02-01 18:41:29 +03:00
|
|
|
QCoreApplication::processEvents();
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
2007-11-09 23:18:49 +03:00
|
|
|
void QCMake::errorCallback(const char* msg, const char* /*title*/,
|
|
|
|
bool& /*stop*/, void* cd)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
|
|
|
QCMake* self = reinterpret_cast<QCMake*>(cd);
|
2007-11-09 23:18:49 +03:00
|
|
|
emit self->errorMessage(msg);
|
2008-02-01 18:41:29 +03:00
|
|
|
QCoreApplication::processEvents();
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
2007-11-07 03:25:43 +03:00
|
|
|
QString QCMake::binaryDirectory() const
|
|
|
|
{
|
|
|
|
return this->BinaryDirectory;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QCMake::sourceDirectory() const
|
|
|
|
{
|
|
|
|
return this->SourceDirectory;
|
|
|
|
}
|
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
QString QCMake::generator() const
|
|
|
|
{
|
|
|
|
return this->Generator;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList QCMake::availableGenerators() const
|
|
|
|
{
|
|
|
|
return this->AvailableGenerators;
|
|
|
|
}
|
|
|
|
|
2007-11-06 09:16:11 +03:00
|
|
|
void QCMake::deleteCache()
|
|
|
|
{
|
|
|
|
// delete cache
|
|
|
|
this->CMakeInstance->GetCacheManager()->DeleteCache(this->BinaryDirectory.toAscii().data());
|
|
|
|
// reload to make our cache empty
|
|
|
|
this->CMakeInstance->GetCacheManager()->LoadCache(this->BinaryDirectory.toAscii().data());
|
|
|
|
// emit no generator and no properties
|
|
|
|
this->setGenerator(QString());
|
|
|
|
QCMakeCachePropertyList props = this->properties();
|
|
|
|
emit this->propertiesChanged(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QCMake::reloadCache()
|
|
|
|
{
|
|
|
|
// emit that the cache was cleaned out
|
|
|
|
QCMakeCachePropertyList props;
|
|
|
|
emit this->propertiesChanged(props);
|
|
|
|
// reload
|
|
|
|
this->CMakeInstance->GetCacheManager()->LoadCache(this->BinaryDirectory.toAscii().data());
|
|
|
|
// emit new cache properties
|
|
|
|
props = this->properties();
|
|
|
|
emit this->propertiesChanged(props);
|
|
|
|
}
|
2008-04-03 01:41:24 +04:00
|
|
|
|
|
|
|
void QCMake::setDebugOutput(bool flag)
|
|
|
|
{
|
|
|
|
if(flag != this->CMakeInstance->GetDebugOutput())
|
|
|
|
{
|
|
|
|
this->CMakeInstance->SetDebugOutputOn(flag);
|
|
|
|
emit this->debugOutputChanged(flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QCMake::getDebugOutput() const
|
|
|
|
{
|
|
|
|
return this->CMakeInstance->GetDebugOutput();
|
|
|
|
}
|
|
|
|
|
2007-11-06 09:16:11 +03:00
|
|
|
|
2008-03-12 05:51:56 +03:00
|
|
|
void QCMake::SetSuppressDevWarnings(bool value)
|
|
|
|
{
|
|
|
|
this->SuppressDevWarnings = value;
|
|
|
|
}
|