1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmakewizard.cxx,v $
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"
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): ");
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()))
63 iter
.SetValue(value
.c_str());
69 bool cmakewizard::AskAdvanced()
71 printf("Would you like to see advanced options? [No]:");
74 fgets(buffer
, sizeof(buffer
)-1, stdin
);
77 if(buffer
[0] == 'y' || buffer
[0] == 'Y')
86 void cmakewizard::ShowMessage(const char* m
)
93 int cmakewizard::RunWizard(std::vector
<std::string
> const& args
)
95 this->ShowAdvanced
= this->AskAdvanced();
96 cmSystemTools::DisableRunCommandOutput();
99 make
.SetCMakeCommand(args
[0].c_str());
101 make
.SetCacheArgs(args
);
102 std::map
<cmStdString
, cmStdString
> askedCache
;
104 // continue asking questions until no new questions are asked
110 "Please wait while cmake processes CMakeLists.txt files....\n");
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
)
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
);
142 if(this->ShowAdvanced
|| !i
.GetPropertyAsBool("ADVANCED"))
144 this->AskUser(key
.c_str(), i
);
148 askedCache
[key
] = i
.GetValue();
150 cachem
->SaveCache(make
.GetHomeOutputDirectory());
153 if(make
.Generate() == 0)
155 this->ShowMessage("CMake complete, run make to build project.\n");