CMake/Source/cmakewizard.cxx

160 lines
4.3 KiB
C++
Raw Normal View History

2002-01-21 20:30:43 +00:00
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
2002-01-21 20:30:43 +00:00
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.
2002-01-21 20:30:43 +00:00
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-11-30 21:48:52 +00:00
#include "cmakewizard.h"
#include "cmake.h"
2001-11-30 21:48:52 +00:00
#include "cmCacheManager.h"
// On Mac OSX getline looks like it is broken, so we have to use
// fgets. This is why we are including stdio.h.
#include <stdio.h>
2001-11-30 21:48:52 +00:00
cmakewizard::cmakewizard()
{
2001-11-30 21:48:52 +00:00
m_ShowAdvanced = false;
}
void cmakewizard::AskUser(const char* key, cmCacheManager::CacheIterator& iter)
2001-11-30 21:48:52 +00:00
{
std::cout << "Variable Name: " << key << "\n";
const char* helpstring = iter.GetProperty("HELPSTRING");
std::cout << "Description: " << (helpstring?helpstring:"(none)") << "\n";
std::cout << "Current Value: " << iter.GetValue() << "\n";
std::cout << "New Value (Enter to keep current value): ";
char buffer[4096];
buffer[0] = 0;
fgets(buffer, sizeof(buffer)-1, stdin);
2002-09-17 18:19:50 +00:00
if(strlen(buffer) > 0)
{
2002-09-17 18:19:50 +00:00
std::string sbuffer = buffer;
std::string::size_type pos = sbuffer.find_last_not_of(" \n\r\t");
std::string value = "";
if ( pos != std::string::npos )
{
2002-09-17 18:19:50 +00:00
value = sbuffer.substr(0, pos+1);
}
2002-09-17 18:19:50 +00:00
if ( value.size() > 0 )
{
2002-09-17 18:19:50 +00:00
if(iter.GetType() == cmCacheManager::PATH ||
iter.GetType() == cmCacheManager::FILEPATH)
{
cmSystemTools::ConvertToUnixSlashes(value);
}
if(iter.GetType() == cmCacheManager::BOOL)
{
2002-09-17 18:19:50 +00:00
if(!cmSystemTools::IsOn(value.c_str()))
{
value = "OFF";
}
}
2002-09-17 18:19:50 +00:00
iter.SetValue(value.c_str());
}
}
std::cout << "\n";
}
2001-11-30 21:48:52 +00:00
bool cmakewizard::AskAdvanced()
{
std::cout << "Would you like to see advanced options? [No]:";
char buffer[4096];
buffer[0] = 0;
fgets(buffer, sizeof(buffer)-1, stdin);
if(buffer[0])
{
if(buffer[0] == 'y' || buffer[0] == 'Y')
{
2001-11-30 21:48:52 +00:00
return true;
}
}
2001-11-30 21:48:52 +00: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;
make.SetArgs(args);
2002-09-17 17:59:58 +00:00
make.SetCMakeCommand(args[0].c_str());
make.LoadCache();
make.SetCacheArgs(args);
std::map<std::string,std::string> askedCache;
bool asked = false;
// continue asking questions until no new questions are asked
do
{
asked = false;
// run cmake
2001-11-30 21:48:52 +00:00
this->ShowMessage("Please wait while cmake processes CMakeLists.txt files....\n");
2002-09-17 17:59:58 +00:00
make.Configure();
2001-11-30 21:48:52 +00:00
this->ShowMessage("\n");
// load the cache from disk
cmCacheManager *cachem = make.GetCacheManager();
2002-08-21 15:59:52 +00:00
cachem->
LoadCache(cmSystemTools::GetCurrentWorkingDirectory().c_str());
2002-08-21 15:59:52 +00:00
cmCacheManager::CacheIterator i = cachem->NewIterator();
// iterate over all entries in the cache
2002-08-21 15:59:52 +00:00
for(;!i.IsAtEnd(); i.Next())
{
2002-08-21 15:59:52 +00:00
std::string key = i.GetName();
if( i.GetType() == cmCacheManager::INTERNAL ||
i.GetType() == cmCacheManager::STATIC ||
i.GetType() == cmCacheManager::UNINITIALIZED )
{
continue;
}
if(askedCache.count(key))
{
std::string& e = askedCache.find(key)->second;
if(e != i.GetValue())
{
if(m_ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
2001-11-30 21:48:52 +00:00
{
this->AskUser(key.c_str(), i);
2001-11-30 21:48:52 +00:00
asked = true;
}
}
}
else
2001-11-30 21:48:52 +00:00
{
if(m_ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
2001-11-30 21:48:52 +00:00
{
this->AskUser(key.c_str(), i);
2001-11-30 21:48:52 +00:00
asked = true;
}
}
askedCache[key] = i.GetValue();
}
cachem->SaveCache(cmSystemTools::GetCurrentWorkingDirectory().c_str());
}
while(asked);
2002-09-06 17:06:23 +00:00
make.Generate();
2001-11-30 21:48:52 +00:00
this->ShowMessage("CMake complete, run make to build project.\n");
}