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
|
|
|
|
2002-09-17 21:48:30 +04:00
|
|
|
|
|
|
|
// 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-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-09-12 17:00:30 +04:00
|
|
|
void cmakewizard::AskUser(const char* key, cmCacheManager::CacheIterator& iter)
|
2001-12-01 00:48:52 +03:00
|
|
|
{
|
2001-11-27 02:28:27 +03:00
|
|
|
std::cout << "Variable Name: " << key << "\n";
|
2002-09-11 22:05:45 +04:00
|
|
|
const char* helpstring = iter.GetProperty("HELPSTRING");
|
|
|
|
std::cout << "Description: " << (helpstring?helpstring:"(none)") << "\n";
|
|
|
|
std::cout << "Current Value: " << iter.GetValue() << "\n";
|
2001-11-27 02:28:27 +03:00
|
|
|
std::cout << "New Value (Enter to keep current value): ";
|
|
|
|
char buffer[4096];
|
|
|
|
buffer[0] = 0;
|
2002-09-17 21:48:30 +04:00
|
|
|
fgets(buffer, sizeof(buffer)-1, stdin);
|
2002-09-17 22:19:50 +04:00
|
|
|
|
|
|
|
if(strlen(buffer) > 0)
|
2001-11-27 02:28:27 +03:00
|
|
|
{
|
2002-09-17 22:19:50 +04: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-27 02:28:27 +03:00
|
|
|
{
|
2002-09-17 22:19:50 +04:00
|
|
|
value = sbuffer.substr(0, pos+1);
|
2001-11-27 02:28:27 +03:00
|
|
|
}
|
2002-09-17 22:19:50 +04:00
|
|
|
|
|
|
|
if ( value.size() > 0 )
|
2001-11-27 02:28:27 +03:00
|
|
|
{
|
2002-09-17 22:19:50 +04:00
|
|
|
if(iter.GetType() == cmCacheManager::PATH ||
|
|
|
|
iter.GetType() == cmCacheManager::FILEPATH)
|
|
|
|
{
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(value);
|
|
|
|
}
|
|
|
|
if(iter.GetType() == cmCacheManager::BOOL)
|
2002-09-11 22:05:45 +04:00
|
|
|
{
|
2002-09-17 22:19:50 +04:00
|
|
|
if(!cmSystemTools::IsOn(value.c_str()))
|
|
|
|
{
|
|
|
|
value = "OFF";
|
|
|
|
}
|
2002-09-11 22:05:45 +04:00
|
|
|
}
|
2002-09-17 22:19:50 +04:00
|
|
|
iter.SetValue(value.c_str());
|
2001-11-27 02:28:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
2002-09-17 21:48:30 +04:00
|
|
|
fgets(buffer, sizeof(buffer)-1, stdin);
|
2001-11-27 02:28:27 +03:00
|
|
|
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;
|
2002-09-11 22:05:45 +04:00
|
|
|
make.SetArgs(args);
|
2002-09-17 21:59:58 +04:00
|
|
|
make.SetCMakeCommand(args[0].c_str());
|
|
|
|
make.LoadCache();
|
|
|
|
make.SetCacheArgs(args);
|
2002-09-11 22:05:45 +04:00
|
|
|
std::map<std::string,std::string> askedCache;
|
2001-11-27 02:28:27 +03:00
|
|
|
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");
|
2002-09-11 22:05:45 +04:00
|
|
|
|
2002-09-17 21:59:58 +04:00
|
|
|
make.Configure();
|
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();
|
2002-09-11 22:05:45 +04:00
|
|
|
if( i.GetType() == cmCacheManager::INTERNAL ||
|
|
|
|
i.GetType() == cmCacheManager::STATIC ||
|
|
|
|
i.GetType() == cmCacheManager::UNINITIALIZED )
|
2001-11-27 02:28:27 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(askedCache.count(key))
|
|
|
|
{
|
2002-09-11 22:05:45 +04:00
|
|
|
std::string& e = askedCache.find(key)->second;
|
|
|
|
if(e != i.GetValue())
|
2001-11-27 02:28:27 +03:00
|
|
|
{
|
2002-09-11 22:05:45 +04:00
|
|
|
if(m_ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
|
2001-12-01 00:48:52 +03:00
|
|
|
{
|
2002-09-12 17:00:30 +04:00
|
|
|
this->AskUser(key.c_str(), i);
|
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-09-11 22:05:45 +04:00
|
|
|
if(m_ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
|
2001-12-01 00:48:52 +03:00
|
|
|
{
|
2002-09-12 17:00:30 +04:00
|
|
|
this->AskUser(key.c_str(), i);
|
2001-12-01 00:48:52 +03:00
|
|
|
asked = true;
|
|
|
|
}
|
2001-11-27 02:28:27 +03:00
|
|
|
}
|
2002-09-11 22:05:45 +04:00
|
|
|
askedCache[key] = i.GetValue();
|
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);
|
2002-09-06 21:06:23 +04:00
|
|
|
make.Generate();
|
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
|
|
|
}
|