| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 | 
							- /*=========================================================================
 
-   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.
 
- =========================================================================*/
 
- #include "QCMake.h"
 
- #include <QDir>
 
- #include <QCoreApplication>
 
- #include "cmake.h"
 
- #include "cmCacheManager.h"
 
- #include "cmSystemTools.h"
 
- #include "cmExternalMakefileProjectGenerator.h"
 
- QCMake::QCMake(QObject* p)
 
-   : QObject(p)
 
- {
 
-   qRegisterMetaType<QCMakeCacheProperty>();
 
-   qRegisterMetaType<QCMakeCachePropertyList>();
 
-   
 
-   QDir appDir(QCoreApplication::applicationDirPath());
 
- #if defined(Q_OS_WIN)
 
-   this->CMakeExecutable = appDir.filePath("cmake.exe");
 
- #elif defined(Q_OS_MAC)
 
-   appDir.cd("../../../");  // path to cmake in build directory (need to fix for deployment)
 
-   this->CMakeExecutable = appDir.filePath("cmake");
 
- #else
 
-   this->CMakeExecutable = appDir.filePath("cmake");
 
- #endif
 
-   // TODO: check for existence?
 
-   cmSystemTools::DisableRunCommandOutput();
 
-   cmSystemTools::SetRunCommandHideConsole(true);
 
-   cmSystemTools::SetErrorCallback(QCMake::errorCallback, this);
 
-   this->CMakeInstance = new cmake;
 
-   this->CMakeInstance->SetProgressCallback(QCMake::progressCallback, this);
 
-   std::vector<std::string> generators;
 
-   this->CMakeInstance->GetRegisteredGenerators(generators);
 
-   std::vector<std::string>::iterator iter;
 
-   for(iter = generators.begin(); iter != generators.end(); ++iter)
 
-     {
 
-     this->AvailableGenerators.append(iter->c_str());
 
-     }
 
- }
 
- QCMake::~QCMake()
 
- {
 
-   delete this->CMakeInstance;
 
-   //cmDynamicLoader::FlushCache();
 
- }
 
- void QCMake::loadCache(const QString& dir)
 
- {
 
-   this->setBinaryDirectory(dir);
 
- }
 
- void QCMake::setSourceDirectory(const QString& dir)
 
- {
 
-   if(this->SourceDirectory != dir)
 
-     {
 
-     this->SourceDirectory = dir;
 
-     emit this->sourceDirChanged(dir);
 
-     }
 
- }
 
- void QCMake::setBinaryDirectory(const QString& dir)
 
- {
 
-   if(this->BinaryDirectory != dir)
 
-     {
 
-     cmCacheManager *cachem = this->CMakeInstance->GetCacheManager();
 
-     this->BinaryDirectory = dir;
 
-     this->setGenerator(QString());
 
-     if(!this->CMakeInstance->GetCacheManager()->LoadCache(dir.toLocal8Bit().data()))
 
-       {
 
-       QDir testDir(dir);
 
-       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.");
 
-         }
 
-       }
 
-     QCMakeCachePropertyList props = this->properties();
 
-     emit this->propertiesChanged(props);
 
-     cmCacheManager::CacheIterator itm = cachem->NewIterator();
 
-     if ( itm.Find("CMAKE_HOME_DIRECTORY"))
 
-       {
 
-       setSourceDirectory(itm.GetValue());
 
-       }
 
-     if ( itm.Find("CMAKE_GENERATOR"))
 
-       {
 
-       const char* extraGen = cachem->GetCacheValue("CMAKE_EXTRA_GENERATOR");
 
-       std::string curGen = cmExternalMakefileProjectGenerator::
 
-                               CreateFullGeneratorName(itm.GetValue(), extraGen);
 
-       this->setGenerator(curGen.c_str());
 
-       }
 
-     }
 
- }
 
- void QCMake::setGenerator(const QString& gen)
 
- {
 
-   if(this->Generator != gen)
 
-     {
 
-     this->Generator = gen;
 
-     emit this->generatorChanged(this->Generator);
 
-     }
 
- }
 
- 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(
 
-     this->CMakeInstance->CreateGlobalGenerator(this->Generator.toAscii().data()));
 
-   this->CMakeInstance->SetCMakeCommand(this->CMakeExecutable.toAscii().data());
 
-   this->CMakeInstance->LoadCache();
 
-   cmSystemTools::ResetErrorOccuredFlag();
 
-   int err = this->CMakeInstance->Configure();
 
-   emit this->propertiesChanged(this->properties());
 
-   emit this->configureDone(err);
 
- }
 
- void QCMake::generate()
 
- {
 
-   cmSystemTools::ResetErrorOccuredFlag();
 
-   int err = this->CMakeInstance->Generate();
 
-   emit this->generateDone(err);
 
- }
 
-   
 
- void QCMake::setProperties(const QCMakeCachePropertyList& newProps)
 
- {
 
-   QCMakeCachePropertyList props = newProps;
 
-   QStringList toremove;
 
-   // set the value of properties
 
-   cmCacheManager *cachem = this->CMakeInstance->GetCacheManager();
 
-   for(cmCacheManager::CacheIterator i = cachem->NewIterator();
 
-       !i.IsAtEnd(); i.Next())
 
-     {
 
-     if(i.GetType() == cmCacheManager::INTERNAL ||
 
-        i.GetType() == cmCacheManager::STATIC)
 
-       {
 
-       continue;
 
-       }
 
-     QCMakeCacheProperty prop;
 
-     prop.Key = i.GetName();
 
-     int idx = props.indexOf(prop);
 
-     if(idx == -1)
 
-       {
 
-       toremove.append(i.GetName());
 
-       }
 
-     else
 
-       {
 
-       prop = props[idx];
 
-       if(prop.Value.type() == QVariant::Bool)
 
-         {
 
-         i.SetValue(prop.Value.toBool() ? "ON" : "OFF");
 
-         }
 
-       else
 
-         {
 
-         i.SetValue(prop.Value.toString().toAscii().data());
 
-         }
 
-       props.removeAt(idx);
 
-       }
 
-     }
 
-   // remove some properites
 
-   foreach(QString s, toremove)
 
-     {
 
-     cachem->RemoveCacheEntry(s.toAscii().data());
 
-     }
 
-   
 
-   // 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);
 
-       }
 
-     }
 
-   
 
-   cachem->SaveCache(this->BinaryDirectory.toAscii().data());
 
- }
 
- QCMakeCachePropertyList QCMake::properties() const
 
- {
 
-   QCMakeCachePropertyList ret;
 
-   cmCacheManager *cachem = this->CMakeInstance->GetCacheManager();
 
-   for(cmCacheManager::CacheIterator i = cachem->NewIterator();
 
-       !i.IsAtEnd(); i.Next())
 
-     {
 
-     if(i.GetType() == cmCacheManager::INTERNAL ||
 
-        i.GetType() == cmCacheManager::STATIC)
 
-       {
 
-       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;
 
-       prop.Value = cmSystemTools::IsOn(i.GetValue());
 
-       }
 
-     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);
 
-   if(percent >= 0)
 
-     {
 
-     emit self->progressChanged(msg, percent);
 
-     }
 
-   else
 
-     {
 
-     emit self->outputMessage(msg);
 
-     }
 
- }
 
- void QCMake::errorCallback(const char* msg, const char* /*title*/,
 
-                            bool& /*stop*/, void* cd)
 
- {
 
-   QCMake* self = reinterpret_cast<QCMake*>(cd);
 
-   emit self->errorMessage(msg);
 
- }
 
- QString QCMake::binaryDirectory() const
 
- {
 
-   return this->BinaryDirectory;
 
- }
 
- QString QCMake::sourceDirectory() const
 
- {
 
-   return this->SourceDirectory;
 
- }
 
- QString QCMake::generator() const
 
- {
 
-   return this->Generator;
 
- }
 
- QStringList QCMake::availableGenerators() const
 
- {
 
-   return this->AvailableGenerators;
 
- }
 
- 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);
 
- }
 
 
  |