2002-01-21 23:30:43 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: Insight Segmentation & Registration Toolkit
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
Copyright (c) 2002 Insight Consortium. All rights reserved.
|
|
|
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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.
|
|
|
|
|
|
|
|
=========================================================================*/
|
2001-12-01 00:48:52 +03:00
|
|
|
#include "cmakewizard.h"
|
2001-11-27 02:28:27 +03:00
|
|
|
#include "cmake.h"
|
2001-12-01 00:48:52 +03:00
|
|
|
#include "cmCacheManager.h"
|
2001-11-27 02:28:27 +03:00
|
|
|
|
2001-12-01 00:48:52 +03:00
|
|
|
cmakewizard::cmakewizard()
|
2001-11-27 02:28:27 +03:00
|
|
|
{
|
2001-12-01 00:48:52 +03:00
|
|
|
m_ShowAdvanced = false;
|
|
|
|
}
|
|
|
|
|
2001-11-27 02:28:27 +03:00
|
|
|
|
2002-08-28 22:51:10 +04:00
|
|
|
void cmakewizard::AskUser(const char* key, cmCacheManager::CacheEntry & entry,
|
|
|
|
cmCacheManager *cacheManager)
|
2001-12-01 00:48:52 +03:00
|
|
|
{
|
2001-11-27 02:28:27 +03:00
|
|
|
std::cout << "Variable Name: " << key << "\n";
|
|
|
|
std::cout << "Description: " << entry.m_HelpString << "\n";
|
|
|
|
std::cout << "Current Value: " << entry.m_Value.c_str() << "\n";
|
|
|
|
std::cout << "New Value (Enter to keep current value): ";
|
|
|
|
char buffer[4096];
|
|
|
|
buffer[0] = 0;
|
|
|
|
std::cin.getline(buffer, sizeof(buffer));
|
|
|
|
if(buffer[0])
|
|
|
|
{
|
2002-08-28 22:51:10 +04:00
|
|
|
cmCacheManager::CacheEntry *entry = cacheManager->GetCacheEntry(key);
|
2001-11-27 02:28:27 +03:00
|
|
|
if(entry)
|
|
|
|
{
|
|
|
|
entry->m_Value = buffer;
|
2001-12-07 01:09:06 +03:00
|
|
|
if(entry->m_Type == cmCacheManager::PATH ||
|
|
|
|
entry->m_Type == cmCacheManager::FILEPATH)
|
|
|
|
{
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(entry->m_Value);
|
|
|
|
}
|
2002-02-28 23:57:45 +03:00
|
|
|
if(entry->m_Type == cmCacheManager::BOOL)
|
|
|
|
{
|
|
|
|
if(!cmSystemTools::IsOn(buffer))
|
|
|
|
{
|
|
|
|
entry->m_Value = "OFF";
|
|
|
|
}
|
|
|
|
}
|
2001-11-27 02:28:27 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "strange error, should be in cache but is not... " << key << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout << "\n";
|
|
|
|
}
|
|
|
|
|
2001-12-01 00:48:52 +03:00
|
|
|
bool cmakewizard::AskAdvanced()
|
2001-11-27 02:28:27 +03:00
|
|
|
{
|
|
|
|
std::cout << "Would you like to see advanced options? [No]:";
|
|
|
|
char buffer[4096];
|
|
|
|
buffer[0] = 0;
|
|
|
|
std::cin.getline(buffer, sizeof(buffer));
|
|
|
|
if(buffer[0])
|
|
|
|
{
|
|
|
|
if(buffer[0] == 'y' || buffer[0] == 'Y')
|
|
|
|
{
|
2001-12-01 00:48:52 +03:00
|
|
|
return true;
|
2001-11-27 02:28:27 +03:00
|
|
|
}
|
|
|
|
}
|
2001-12-01 00:48:52 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cmakewizard::ShowMessage(const char* m)
|
|
|
|
{
|
|
|
|
std::cout << m << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cmakewizard::RunWizard(std::vector<std::string> const& args)
|
|
|
|
{
|
|
|
|
m_ShowAdvanced = this->AskAdvanced();
|
|
|
|
cmSystemTools::DisableRunCommandOutput();
|
2001-11-27 02:28:27 +03:00
|
|
|
cmake make;
|
|
|
|
cmCacheManager::CacheEntryMap askedCache;
|
|
|
|
bool asked = false;
|
|
|
|
// continue asking questions until no new questions are asked
|
|
|
|
do
|
|
|
|
{
|
|
|
|
asked = false;
|
|
|
|
// run cmake
|
2001-12-01 00:48:52 +03:00
|
|
|
this->ShowMessage("Please wait while cmake processes CMakeLists.txt files....\n");
|
2001-11-27 02:28:27 +03:00
|
|
|
make.Generate(args);
|
2001-12-01 00:48:52 +03:00
|
|
|
this->ShowMessage("\n");
|
2001-11-27 02:28:27 +03:00
|
|
|
// load the cache from disk
|
2002-08-28 22:51:10 +04:00
|
|
|
cmCacheManager *cachem = make.GetCacheManager();
|
2002-08-21 19:59:52 +04:00
|
|
|
cachem->
|
2001-11-27 02:28:27 +03:00
|
|
|
LoadCache(cmSystemTools::GetCurrentWorkingDirectory().c_str());
|
2002-08-21 19:59:52 +04:00
|
|
|
cmCacheManager::CacheIterator i = cachem->NewIterator();
|
2001-11-27 02:28:27 +03:00
|
|
|
// iterate over all entries in the cache
|
2002-08-21 19:59:52 +04:00
|
|
|
for(;!i.IsAtEnd(); i.Next())
|
2001-11-27 02:28:27 +03:00
|
|
|
{
|
2002-08-21 19:59:52 +04:00
|
|
|
std::string key = i.GetName();
|
|
|
|
cmCacheManager::CacheEntry ce = i.GetEntry();
|
2001-11-27 02:28:27 +03:00
|
|
|
if(ce.m_Type == cmCacheManager::INTERNAL
|
|
|
|
|| ce.m_Type == cmCacheManager::STATIC)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(askedCache.count(key))
|
|
|
|
{
|
|
|
|
cmCacheManager::CacheEntry& e = askedCache.find(key)->second;
|
|
|
|
if(e.m_Value != ce.m_Value)
|
|
|
|
{
|
2002-08-28 22:51:10 +04:00
|
|
|
if(m_ShowAdvanced || !cachem->IsAdvanced(key.c_str()))
|
2001-12-01 00:48:52 +03:00
|
|
|
{
|
2002-08-28 22:51:10 +04:00
|
|
|
this->AskUser(key.c_str(), ce, cachem);
|
2001-12-01 00:48:52 +03:00
|
|
|
asked = true;
|
|
|
|
}
|
2001-11-27 02:28:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2001-12-01 00:48:52 +03:00
|
|
|
{
|
2002-08-28 22:51:10 +04:00
|
|
|
if(m_ShowAdvanced || !cachem->IsAdvanced(key.c_str()))
|
2001-12-01 00:48:52 +03:00
|
|
|
{
|
2002-08-28 22:51:10 +04:00
|
|
|
this->AskUser(key.c_str(), ce, cachem);
|
2001-12-01 00:48:52 +03:00
|
|
|
asked = true;
|
|
|
|
}
|
2001-11-27 02:28:27 +03:00
|
|
|
}
|
2002-08-21 19:59:52 +04:00
|
|
|
askedCache[key] = i.GetEntry();
|
2001-11-27 02:28:27 +03:00
|
|
|
}
|
2002-08-28 22:51:10 +04:00
|
|
|
cachem->SaveCache(cmSystemTools::GetCurrentWorkingDirectory().c_str());
|
2001-11-27 02:28:27 +03:00
|
|
|
}
|
|
|
|
while(asked);
|
2001-12-01 00:48:52 +03:00
|
|
|
this->ShowMessage("CMake complete, run make to build project.\n");
|
2001-11-27 02:28:27 +03:00
|
|
|
}
|