ENH: mark some vars as advanced (and resort the list)
[cmake.git] / Source / cmakewizard.cxx
blobd94aff1313515959c6f29d6f9981e1ac3e3339e2
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmakewizard.cxx,v $
5 Language: C++
6 Date: $Date: 2002-09-18 12:13:53 $
7 Version: $Revision: 1.15 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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"
22 // On Mac OSX getline looks like it is broken, so we have to use
23 // fgets. This is why we are including stdio.h.
24 #include <stdio.h>
26 cmakewizard::cmakewizard()
28 m_ShowAdvanced = false;
32 void cmakewizard::AskUser(const char* key, cmCacheManager::CacheIterator& iter)
34 std::cout << "Variable Name: " << key << "\n";
35 const char* helpstring = iter.GetProperty("HELPSTRING");
36 std::cout << "Description: " << (helpstring?helpstring:"(none)") << "\n";
37 std::cout << "Current Value: " << iter.GetValue() << "\n";
38 std::cout << "New Value (Enter to keep current value): ";
39 char buffer[4096];
40 buffer[0] = 0;
41 fgets(buffer, sizeof(buffer)-1, stdin);
43 if(strlen(buffer) > 0)
45 std::string sbuffer = buffer;
46 std::string::size_type pos = sbuffer.find_last_not_of(" \n\r\t");
47 std::string value = "";
48 if ( pos != std::string::npos )
50 value = sbuffer.substr(0, pos+1);
53 if ( value.size() > 0 )
55 if(iter.GetType() == cmCacheManager::PATH ||
56 iter.GetType() == cmCacheManager::FILEPATH)
58 cmSystemTools::ConvertToUnixSlashes(value);
60 if(iter.GetType() == cmCacheManager::BOOL)
62 if(!cmSystemTools::IsOn(value.c_str()))
64 value = "OFF";
67 iter.SetValue(value.c_str());
70 std::cout << "\n";
73 bool cmakewizard::AskAdvanced()
75 std::cout << "Would you like to see advanced options? [No]:";
76 char buffer[4096];
77 buffer[0] = 0;
78 fgets(buffer, sizeof(buffer)-1, stdin);
79 if(buffer[0])
81 if(buffer[0] == 'y' || buffer[0] == 'Y')
83 return true;
86 return false;
90 void cmakewizard::ShowMessage(const char* m)
92 std::cout << m << "\n";
97 void cmakewizard::RunWizard(std::vector<std::string> const& args)
99 m_ShowAdvanced = this->AskAdvanced();
100 cmSystemTools::DisableRunCommandOutput();
101 cmake make;
102 make.SetArgs(args);
103 make.SetCMakeCommand(args[0].c_str());
104 make.LoadCache();
105 make.SetCacheArgs(args);
106 std::map<std::string,std::string> askedCache;
107 bool asked = false;
108 // continue asking questions until no new questions are asked
111 asked = false;
112 // run cmake
113 this->ShowMessage("Please wait while cmake processes CMakeLists.txt files....\n");
115 make.Configure();
116 this->ShowMessage("\n");
117 // load the cache from disk
118 cmCacheManager *cachem = make.GetCacheManager();
119 cachem->
120 LoadCache(cmSystemTools::GetCurrentWorkingDirectory().c_str());
121 cmCacheManager::CacheIterator i = cachem->NewIterator();
122 // iterate over all entries in the cache
123 for(;!i.IsAtEnd(); i.Next())
125 std::string key = i.GetName();
126 if( i.GetType() == cmCacheManager::INTERNAL ||
127 i.GetType() == cmCacheManager::STATIC ||
128 i.GetType() == cmCacheManager::UNINITIALIZED )
130 continue;
132 if(askedCache.count(key))
134 std::string& e = askedCache.find(key)->second;
135 if(e != i.GetValue())
137 if(m_ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
139 this->AskUser(key.c_str(), i);
140 asked = true;
144 else
146 if(m_ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
148 this->AskUser(key.c_str(), i);
149 asked = true;
152 askedCache[key] = i.GetValue();
154 cachem->SaveCache(cmSystemTools::GetCurrentWorkingDirectory().c_str());
156 while(asked);
157 make.Generate();
158 this->ShowMessage("CMake complete, run make to build project.\n");