1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmakewizard.cxx,v $
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"
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.
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): ";
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()))
67 iter
.SetValue(value
.c_str());
73 bool cmakewizard::AskAdvanced()
75 std::cout
<< "Would you like to see advanced options? [No]:";
78 fgets(buffer
, sizeof(buffer
)-1, stdin
);
81 if(buffer
[0] == 'y' || buffer
[0] == 'Y')
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();
103 make
.SetCMakeCommand(args
[0].c_str());
105 make
.SetCacheArgs(args
);
106 std::map
<std::string
,std::string
> askedCache
;
108 // continue asking questions until no new questions are asked
113 this->ShowMessage("Please wait while cmake processes CMakeLists.txt files....\n");
116 this->ShowMessage("\n");
117 // load the cache from disk
118 cmCacheManager
*cachem
= make
.GetCacheManager();
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
)
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
);
146 if(m_ShowAdvanced
|| !i
.GetPropertyAsBool("ADVANCED"))
148 this->AskUser(key
.c_str(), i
);
152 askedCache
[key
] = i
.GetValue();
154 cachem
->SaveCache(cmSystemTools::GetCurrentWorkingDirectory().c_str());
158 this->ShowMessage("CMake complete, run make to build project.\n");