1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmakewizard.h"
14 #include "cmCacheManager.h"
16 cmakewizard::cmakewizard()
18 this->ShowAdvanced = false;
22 void cmakewizard::AskUser(const char* key,
23 cmCacheManager::CacheIterator& iter)
25 printf("Variable Name: %s\n", key);
26 const char* helpstring = iter.GetProperty("HELPSTRING");
27 printf("Description: %s\n", (helpstring?helpstring:"(none)"));
28 printf("Current Value: %s\n", iter.GetValue());
29 printf("New Value (Enter to keep current value): ");
31 if(!fgets(buffer, sizeof(buffer)-1, stdin))
36 if(strlen(buffer) > 0)
38 std::string sbuffer = buffer;
39 std::string::size_type pos = sbuffer.find_last_not_of(" \n\r\t");
40 std::string value = "";
41 if ( pos != std::string::npos )
43 value = sbuffer.substr(0, pos+1);
46 if ( value.size() > 0 )
48 if(iter.GetType() == cmCacheManager::PATH ||
49 iter.GetType() == cmCacheManager::FILEPATH)
51 cmSystemTools::ConvertToUnixSlashes(value);
53 if(iter.GetType() == cmCacheManager::BOOL)
55 if(!cmSystemTools::IsOn(value.c_str()))
60 iter.SetValue(value.c_str());
66 bool cmakewizard::AskAdvanced()
68 printf("Would you like to see advanced options? [No]:");
70 if(!fgets(buffer, sizeof(buffer)-1, stdin))
76 if(buffer[0] == 'y' || buffer[0] == 'Y')
85 void cmakewizard::ShowMessage(const char* m)
92 int cmakewizard::RunWizard(std::vector<std::string> const& args)
94 this->ShowAdvanced = this->AskAdvanced();
95 cmSystemTools::DisableRunCommandOutput();
98 make.SetCMakeCommand(args[0].c_str());
100 make.SetCacheArgs(args);
101 std::map<cmStdString, cmStdString> askedCache;
103 // continue asking questions until no new questions are asked
109 "Please wait while cmake processes CMakeLists.txt files....\n");
112 this->ShowMessage("\n");
113 // load the cache from disk
114 cmCacheManager *cachem = make.GetCacheManager();
115 cachem->LoadCache(make.GetHomeOutputDirectory());
116 cmCacheManager::CacheIterator i = cachem->NewIterator();
117 // iterate over all entries in the cache
118 for(;!i.IsAtEnd(); i.Next())
120 std::string key = i.GetName();
121 if( i.GetType() == cmCacheManager::INTERNAL ||
122 i.GetType() == cmCacheManager::STATIC ||
123 i.GetType() == cmCacheManager::UNINITIALIZED )
127 if(askedCache.count(key))
129 std::string& e = askedCache.find(key)->second;
130 if(e != i.GetValue())
132 if(this->ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
134 this->AskUser(key.c_str(), i);
141 if(this->ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
143 this->AskUser(key.c_str(), i);
147 askedCache[key] = i.GetValue();
149 cachem->SaveCache(make.GetHomeOutputDirectory());
152 if(make.Generate() == 0)
154 this->ShowMessage("CMake complete, run make to build project.\n");