KWSys Nightly Date Stamp
[cmake.git] / Source / cmakewizard.cxx
blobc6307cadef8f1409e4d3a6199f72409d10e49d75
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmakewizard.cxx,v $
5 Language: C++
6 Date: $Date: 2006-03-15 16:02:07 $
7 Version: $Revision: 1.23 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmakewizard.h"
18 #include "cmake.h"
19 #include "cmCacheManager.h"
21 cmakewizard::cmakewizard()
23 this->ShowAdvanced = false;
27 void cmakewizard::AskUser(const char* key,
28 cmCacheManager::CacheIterator& iter)
30 printf("Variable Name: %s\n", key);
31 const char* helpstring = iter.GetProperty("HELPSTRING");
32 printf("Description: %s\n", (helpstring?helpstring:"(none)"));
33 printf("Current Value: %s\n", iter.GetValue());
34 printf("New Value (Enter to keep current value): ");
35 char buffer[4096];
36 buffer[0] = 0;
37 fgets(buffer, sizeof(buffer)-1, stdin);
39 if(strlen(buffer) > 0)
41 std::string sbuffer = buffer;
42 std::string::size_type pos = sbuffer.find_last_not_of(" \n\r\t");
43 std::string value = "";
44 if ( pos != std::string::npos )
46 value = sbuffer.substr(0, pos+1);
49 if ( value.size() > 0 )
51 if(iter.GetType() == cmCacheManager::PATH ||
52 iter.GetType() == cmCacheManager::FILEPATH)
54 cmSystemTools::ConvertToUnixSlashes(value);
56 if(iter.GetType() == cmCacheManager::BOOL)
58 if(!cmSystemTools::IsOn(value.c_str()))
60 value = "OFF";
63 iter.SetValue(value.c_str());
66 printf("\n");
69 bool cmakewizard::AskAdvanced()
71 printf("Would you like to see advanced options? [No]:");
72 char buffer[4096];
73 buffer[0] = 0;
74 fgets(buffer, sizeof(buffer)-1, stdin);
75 if(buffer[0])
77 if(buffer[0] == 'y' || buffer[0] == 'Y')
79 return true;
82 return false;
86 void cmakewizard::ShowMessage(const char* m)
88 printf("%s\n", m);
93 int cmakewizard::RunWizard(std::vector<std::string> const& args)
95 this->ShowAdvanced = this->AskAdvanced();
96 cmSystemTools::DisableRunCommandOutput();
97 cmake make;
98 make.SetArgs(args);
99 make.SetCMakeCommand(args[0].c_str());
100 make.LoadCache();
101 make.SetCacheArgs(args);
102 std::map<cmStdString, cmStdString> askedCache;
103 bool asked = false;
104 // continue asking questions until no new questions are asked
107 asked = false;
108 // run cmake
109 this->ShowMessage(
110 "Please wait while cmake processes CMakeLists.txt files....\n");
112 make.Configure();
113 this->ShowMessage("\n");
114 // load the cache from disk
115 cmCacheManager *cachem = make.GetCacheManager();
116 cachem->LoadCache(make.GetHomeOutputDirectory());
117 cmCacheManager::CacheIterator i = cachem->NewIterator();
118 // iterate over all entries in the cache
119 for(;!i.IsAtEnd(); i.Next())
121 std::string key = i.GetName();
122 if( i.GetType() == cmCacheManager::INTERNAL ||
123 i.GetType() == cmCacheManager::STATIC ||
124 i.GetType() == cmCacheManager::UNINITIALIZED )
126 continue;
128 if(askedCache.count(key))
130 std::string& e = askedCache.find(key)->second;
131 if(e != i.GetValue())
133 if(this->ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
135 this->AskUser(key.c_str(), i);
136 asked = true;
140 else
142 if(this->ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
144 this->AskUser(key.c_str(), i);
145 asked = true;
148 askedCache[key] = i.GetValue();
150 cachem->SaveCache(make.GetHomeOutputDirectory());
152 while(asked);
153 if(make.Generate() == 0)
155 this->ShowMessage("CMake complete, run make to build project.\n");
156 return 0;
158 return 1;