2009-09-28 15:43:28 +00:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2002-01-21 20:30:43 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2002-01-21 20:30:43 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2001-11-30 21:48:52 +00:00
|
|
|
#include "cmakewizard.h"
|
2001-11-26 23:28:27 +00:00
|
|
|
#include "cmake.h"
|
2001-11-30 21:48:52 +00:00
|
|
|
#include "cmCacheManager.h"
|
2001-11-26 23:28:27 +00:00
|
|
|
|
2001-11-30 21:48:52 +00:00
|
|
|
cmakewizard::cmakewizard()
|
2001-11-26 23:28:27 +00:00
|
|
|
{
|
2006-03-15 16:02:08 +00:00
|
|
|
this->ShowAdvanced = false;
|
2001-11-30 21:48:52 +00:00
|
|
|
}
|
|
|
|
|
2006-03-10 18:06:26 +00:00
|
|
|
|
|
|
|
void cmakewizard::AskUser(const char* key,
|
|
|
|
cmCacheManager::CacheIterator& iter)
|
2001-11-30 21:48:52 +00:00
|
|
|
{
|
2003-01-30 18:19:58 +00:00
|
|
|
printf("Variable Name: %s\n", key);
|
2002-09-11 18:05:45 +00:00
|
|
|
const char* helpstring = iter.GetProperty("HELPSTRING");
|
2003-01-30 18:19:58 +00:00
|
|
|
printf("Description: %s\n", (helpstring?helpstring:"(none)"));
|
|
|
|
printf("Current Value: %s\n", iter.GetValue());
|
|
|
|
printf("New Value (Enter to keep current value): ");
|
2001-11-26 23:28:27 +00:00
|
|
|
char buffer[4096];
|
2013-05-21 21:33:54 +00:00
|
|
|
if(!fgets(buffer, static_cast<int>(sizeof(buffer) - 1), stdin))
|
2009-10-02 19:30:01 +00:00
|
|
|
{
|
|
|
|
buffer[0] = 0;
|
|
|
|
}
|
2006-03-10 18:06:26 +00:00
|
|
|
|
2002-09-17 18:19:50 +00:00
|
|
|
if(strlen(buffer) > 0)
|
2001-11-26 23:28:27 +00:00
|
|
|
{
|
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 )
|
2001-11-26 23:28:27 +00:00
|
|
|
{
|
2002-09-17 18:19:50 +00:00
|
|
|
value = sbuffer.substr(0, pos+1);
|
2001-11-26 23:28:27 +00:00
|
|
|
}
|
2006-03-10 18:06:26 +00:00
|
|
|
|
2002-09-17 18:19:50 +00:00
|
|
|
if ( value.size() > 0 )
|
2001-11-26 23:28:27 +00:00
|
|
|
{
|
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-11 18:05:45 +00:00
|
|
|
{
|
2002-09-17 18:19:50 +00:00
|
|
|
if(!cmSystemTools::IsOn(value.c_str()))
|
|
|
|
{
|
|
|
|
value = "OFF";
|
|
|
|
}
|
2002-09-11 18:05:45 +00:00
|
|
|
}
|
2002-09-17 18:19:50 +00:00
|
|
|
iter.SetValue(value.c_str());
|
2001-11-26 23:28:27 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-30 18:19:58 +00:00
|
|
|
printf("\n");
|
2001-11-26 23:28:27 +00:00
|
|
|
}
|
|
|
|
|
2001-11-30 21:48:52 +00:00
|
|
|
bool cmakewizard::AskAdvanced()
|
2001-11-26 23:28:27 +00:00
|
|
|
{
|
2006-03-10 18:06:26 +00:00
|
|
|
printf("Would you like to see advanced options? [No]:");
|
2001-11-26 23:28:27 +00:00
|
|
|
char buffer[4096];
|
2013-05-21 21:33:54 +00:00
|
|
|
if(!fgets(buffer, static_cast<int>(sizeof(buffer) - 1), stdin))
|
2009-10-02 19:30:01 +00:00
|
|
|
{
|
|
|
|
buffer[0] = 0;
|
|
|
|
}
|
2013-05-21 21:36:37 +00:00
|
|
|
else if(buffer[0] == 'y' || buffer[0] == 'Y')
|
2001-11-26 23:28:27 +00:00
|
|
|
{
|
2013-05-21 21:36:37 +00:00
|
|
|
return true;
|
2001-11-26 23:28:27 +00:00
|
|
|
}
|
2001-11-30 21:48:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cmakewizard::ShowMessage(const char* m)
|
|
|
|
{
|
2003-01-30 18:19:58 +00:00
|
|
|
printf("%s\n", m);
|
2001-11-30 21:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-08-26 19:06:52 +00:00
|
|
|
int cmakewizard::RunWizard(std::vector<std::string> const& args)
|
2001-11-30 21:48:52 +00:00
|
|
|
{
|
2006-03-15 16:02:08 +00:00
|
|
|
this->ShowAdvanced = this->AskAdvanced();
|
2001-11-30 21:48:52 +00:00
|
|
|
cmSystemTools::DisableRunCommandOutput();
|
2001-11-26 23:28:27 +00:00
|
|
|
cmake make;
|
2002-09-11 18:05:45 +00:00
|
|
|
make.SetArgs(args);
|
2002-09-17 17:59:58 +00:00
|
|
|
make.SetCMakeCommand(args[0].c_str());
|
|
|
|
make.LoadCache();
|
|
|
|
make.SetCacheArgs(args);
|
2004-09-29 20:07:07 +00:00
|
|
|
std::map<cmStdString, cmStdString> askedCache;
|
2001-11-26 23:28:27 +00:00
|
|
|
bool asked = false;
|
|
|
|
// continue asking questions until no new questions are asked
|
|
|
|
do
|
|
|
|
{
|
|
|
|
asked = false;
|
|
|
|
// run cmake
|
2006-03-10 18:06:26 +00:00
|
|
|
this->ShowMessage(
|
|
|
|
"Please wait while cmake processes CMakeLists.txt files....\n");
|
2002-09-11 18:05:45 +00:00
|
|
|
|
2002-09-17 17:59:58 +00:00
|
|
|
make.Configure();
|
2001-11-30 21:48:52 +00:00
|
|
|
this->ShowMessage("\n");
|
2001-11-26 23:28:27 +00:00
|
|
|
// load the cache from disk
|
2002-08-28 18:51:10 +00:00
|
|
|
cmCacheManager *cachem = make.GetCacheManager();
|
2003-08-06 22:39:16 +00:00
|
|
|
cachem->LoadCache(make.GetHomeOutputDirectory());
|
2002-08-21 15:59:52 +00:00
|
|
|
cmCacheManager::CacheIterator i = cachem->NewIterator();
|
2001-11-26 23:28:27 +00:00
|
|
|
// iterate over all entries in the cache
|
2002-08-21 15:59:52 +00:00
|
|
|
for(;!i.IsAtEnd(); i.Next())
|
2006-03-10 18:06:26 +00:00
|
|
|
{
|
2002-08-21 15:59:52 +00:00
|
|
|
std::string key = i.GetName();
|
2006-03-10 18:06:26 +00:00
|
|
|
if( i.GetType() == cmCacheManager::INTERNAL ||
|
2002-09-11 18:05:45 +00:00
|
|
|
i.GetType() == cmCacheManager::STATIC ||
|
|
|
|
i.GetType() == cmCacheManager::UNINITIALIZED )
|
2001-11-26 23:28:27 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(askedCache.count(key))
|
|
|
|
{
|
2002-09-11 18:05:45 +00:00
|
|
|
std::string& e = askedCache.find(key)->second;
|
|
|
|
if(e != i.GetValue())
|
2001-11-26 23:28:27 +00:00
|
|
|
{
|
2006-03-15 16:02:08 +00:00
|
|
|
if(this->ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
|
2001-11-30 21:48:52 +00:00
|
|
|
{
|
2002-09-12 13:00:30 +00:00
|
|
|
this->AskUser(key.c_str(), i);
|
2001-11-30 21:48:52 +00:00
|
|
|
asked = true;
|
|
|
|
}
|
2001-11-26 23:28:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2012-08-13 17:42:58 +00:00
|
|
|
{
|
2006-03-15 16:02:08 +00:00
|
|
|
if(this->ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
|
2001-11-30 21:48:52 +00:00
|
|
|
{
|
2002-09-12 13:00:30 +00:00
|
|
|
this->AskUser(key.c_str(), i);
|
2001-11-30 21:48:52 +00:00
|
|
|
asked = true;
|
|
|
|
}
|
2001-11-26 23:28:27 +00:00
|
|
|
}
|
2002-09-11 18:05:45 +00:00
|
|
|
askedCache[key] = i.GetValue();
|
2001-11-26 23:28:27 +00:00
|
|
|
}
|
2003-08-06 22:39:16 +00:00
|
|
|
cachem->SaveCache(make.GetHomeOutputDirectory());
|
2001-11-26 23:28:27 +00:00
|
|
|
}
|
|
|
|
while(asked);
|
2003-08-26 19:06:52 +00:00
|
|
|
if(make.Generate() == 0)
|
|
|
|
{
|
|
|
|
this->ShowMessage("CMake complete, run make to build project.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2001-11-26 23:28:27 +00:00
|
|
|
}
|