CMake/Source/cmakewizard.cxx

124 lines
3.3 KiB
C++
Raw Normal View History

2001-12-01 00:48:52 +03:00
#include "cmakewizard.h"
#include "cmake.h"
2001-12-01 00:48:52 +03:00
#include "cmCacheManager.h"
2001-12-01 00:48:52 +03:00
cmakewizard::cmakewizard()
{
2001-12-01 00:48:52 +03:00
m_ShowAdvanced = false;
}
2001-12-01 00:48:52 +03:00
void cmakewizard::AskUser(const char* key, cmCacheManager::CacheEntry & entry)
{
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])
{
cmCacheManager::CacheEntry *entry =
cmCacheManager::GetInstance()->GetCacheEntry(key);
if(entry)
{
entry->m_Value = buffer;
if(entry->m_Type == cmCacheManager::PATH ||
entry->m_Type == cmCacheManager::FILEPATH)
{
cmSystemTools::ConvertToUnixSlashes(entry->m_Value);
}
}
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()
{
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-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();
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");
make.Generate(args);
2001-12-01 00:48:52 +03:00
this->ShowMessage("\n");
// load the cache from disk
cmCacheManager::GetInstance()->
LoadCache(cmSystemTools::GetCurrentWorkingDirectory().c_str());
cmCacheManager::CacheEntryMap const& currentCache =
cmCacheManager::GetInstance()->GetCacheMap();
// iterate over all entries in the cache
for(cmCacheManager::CacheEntryMap::const_iterator i = currentCache.begin();
i != currentCache.end(); ++i)
{
std::string key = i->first;
cmCacheManager::CacheEntry ce = i->second;
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)
{
2001-12-01 00:48:52 +03:00
if(m_ShowAdvanced || !cmCacheManager::GetInstance()->IsAdvanced(key.c_str()))
{
this->AskUser(key.c_str(), ce);
asked = true;
}
}
}
else
2001-12-01 00:48:52 +03:00
{
if(m_ShowAdvanced || !cmCacheManager::GetInstance()->IsAdvanced(key.c_str()))
{
this->AskUser(key.c_str(), ce);
asked = true;
}
}
askedCache[key] = i->second;
}
cmCacheManager::GetInstance()->
SaveCache(cmSystemTools::GetCurrentWorkingDirectory().c_str());
}
while(asked);
2001-12-01 00:48:52 +03:00
this->ShowMessage("CMake complete, run make to build project.\n");
}