CMakeSetupGUIImplementation.cxx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. #include "CMakeSetupGUIImplementation.h"
  2. #include "Fl/fl_file_chooser.H"
  3. #include "Fl/filename.H"
  4. #include "Fl/fl_ask.H"
  5. #include "cstring"
  6. #include "../cmCacheManager.h"
  7. #include "../cmMakefile.h"
  8. #include <iostream>
  9. #include "FLTKPropertyList.h"
  10. #include "Fl/fl_draw.H"
  11. #include "../cmake.h"
  12. /**
  13. * Constructor
  14. */
  15. CMakeSetupGUIImplementation
  16. ::CMakeSetupGUIImplementation()
  17. {
  18. m_BuildPathChanged = false;
  19. char fname[1024];
  20. //::GetModuleFileName(NULL,fname,1023);
  21. m_PathToExecutable = cmSystemTools::GetProgramPath(fname).c_str();
  22. m_PathToExecutable += "/cmake.exe";
  23. std::cout << "Path to executable = " << m_PathToExecutable << std::endl;
  24. }
  25. /**
  26. * Destructor
  27. */
  28. CMakeSetupGUIImplementation
  29. ::~CMakeSetupGUIImplementation()
  30. {
  31. }
  32. /**
  33. * Show the graphic interface
  34. */
  35. void
  36. CMakeSetupGUIImplementation
  37. ::Show( void )
  38. {
  39. dialogWindow->show();
  40. }
  41. /**
  42. * Hide the graphic interface
  43. */
  44. void
  45. CMakeSetupGUIImplementation
  46. ::Close( void )
  47. {
  48. dialogWindow->hide();
  49. }
  50. /**
  51. * Browse for the path to the sources
  52. */
  53. void
  54. CMakeSetupGUIImplementation
  55. ::BrowseForSourcePath( void )
  56. {
  57. const char * path =
  58. fl_file_chooser(
  59. "Path to Sources",
  60. "",
  61. sourcePathTextInput->value() );
  62. if( !path )
  63. {
  64. return;
  65. }
  66. SetSourcePath( path );
  67. }
  68. /**
  69. * Browse for the path to the binaries
  70. */
  71. void
  72. CMakeSetupGUIImplementation
  73. ::BrowseForBinaryPath( void )
  74. {
  75. const char * path =
  76. fl_file_chooser(
  77. "Path to Binaries",
  78. "",
  79. binaryPathTextInput->value() );
  80. if( !path )
  81. {
  82. return;
  83. }
  84. SetBinaryPath( path );
  85. }
  86. /**
  87. * Set the source path
  88. */
  89. void
  90. CMakeSetupGUIImplementation
  91. ::SetSourcePath( const char * path )
  92. {
  93. if( VerifySourcePath( path ) )
  94. {
  95. m_WhereSource = path;
  96. sourcePathTextInput->value( path );
  97. }
  98. }
  99. /**
  100. * Set the binary path
  101. */
  102. void
  103. CMakeSetupGUIImplementation
  104. ::SetBinaryPath( const char * path )
  105. {
  106. if( VerifyBinaryPath( path ) )
  107. {
  108. if( m_WhereBuild != path )
  109. {
  110. m_BuildPathChanged = true;
  111. m_WhereBuild = path;
  112. }
  113. binaryPathTextInput->value( path );
  114. }
  115. LoadCacheFromDiskToGUI();
  116. }
  117. /**
  118. * Verify the path to binaries
  119. */
  120. bool
  121. CMakeSetupGUIImplementation
  122. ::VerifyBinaryPath( const char * path )
  123. {
  124. if( !path || strlen(path)==0 )
  125. {
  126. fl_alert("Please select the path to the binaries");
  127. return false;
  128. }
  129. if( !filename_isdir( path ) )
  130. {
  131. fl_alert("%s \n Doesn't exist or is not a directory",path);
  132. return false;
  133. }
  134. return true;
  135. }
  136. /**
  137. * Verify the path to sources
  138. */
  139. bool
  140. CMakeSetupGUIImplementation
  141. ::VerifySourcePath( const char * path )
  142. {
  143. if( !path || strlen(path)==0 )
  144. {
  145. fl_alert("Please select the path to the sources");
  146. return false;
  147. }
  148. if( !filename_isdir( path ) )
  149. {
  150. fl_alert("%s \n Doesn't exist or is not a directory",path);
  151. return false;
  152. }
  153. return true;
  154. }
  155. /**
  156. * Build the project files
  157. */
  158. void
  159. CMakeSetupGUIImplementation
  160. ::BuildProjectFiles( void )
  161. {
  162. // Verify that source path is a valid directory
  163. if( !VerifySourcePath( sourcePathTextInput->value() ) )
  164. {
  165. return;
  166. }
  167. // Verify that binary path is a valid directory
  168. if( !VerifyBinaryPath( binaryPathTextInput->value() ) )
  169. {
  170. return;
  171. }
  172. SaveCacheFromGUI();
  173. // set the wait cursor
  174. fl_cursor(FL_CURSOR_WAIT,FL_WHITE,FL_BLACK);
  175. // get all the info from the dialog
  176. // this->UpdateData();
  177. if(!m_BuildPathChanged)
  178. {
  179. // if the build path has not changed save the
  180. // current GUI values to the cache
  181. this->SaveCacheFromGUI();
  182. }
  183. // Make sure we are working from the cache on disk
  184. this->LoadCacheFromDiskToGUI();
  185. // create a cmake object
  186. cmake make;
  187. // create the arguments for the cmake object
  188. std::vector<std::string> args;
  189. args.push_back( m_PathToExecutable.c_str() );
  190. std::string arg;
  191. arg = "-H";
  192. arg += m_WhereSource;
  193. args.push_back(arg);
  194. arg = "-B";
  195. arg += m_WhereBuild;
  196. args.push_back(arg);
  197. // run the generate process
  198. if(make.Generate(args) != 0)
  199. {
  200. cmSystemTools::Error(
  201. "Error in generation process, project files may be invalid");
  202. }
  203. // update the GUI with any new values in the caused by the
  204. // generation process
  205. this->LoadCacheFromDiskToGUI();
  206. // path is up-to-date now
  207. m_BuildPathChanged = false;
  208. // put the cursor back
  209. fl_cursor(FL_CURSOR_DEFAULT,FL_WHITE,FL_BLACK);
  210. fl_message("Done !");
  211. }
  212. /**
  213. * Load Cache from disk to GUI
  214. */
  215. void
  216. CMakeSetupGUIImplementation
  217. ::LoadCacheFromDiskToGUI( void )
  218. {
  219. if( m_WhereBuild != "" )
  220. {
  221. cmCacheManager::GetInstance()->LoadCache( m_WhereBuild.c_str() );
  222. this->FillCacheGUIFromCacheManager();
  223. }
  224. }
  225. /**
  226. * Save Cache from disk to GUI
  227. */
  228. void
  229. CMakeSetupGUIImplementation
  230. ::SaveCacheFromGUI( void )
  231. {
  232. this->FillCacheManagerFromCacheGUI();
  233. if( m_WhereBuild != "" )
  234. {
  235. cmCacheManager::GetInstance()->SaveCache(
  236. m_WhereBuild.c_str() );
  237. }
  238. }
  239. /**
  240. * Fill Cache GUI from cache manager
  241. */
  242. void
  243. CMakeSetupGUIImplementation
  244. ::FillCacheGUIFromCacheManager( void )
  245. {
  246. // Prepare to add rows to the scroll
  247. propertyListPack->begin();
  248. const cmCacheManager::CacheEntryMap &cache =
  249. cmCacheManager::GetInstance()->GetCacheMap();
  250. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  251. i != cache.end(); ++i)
  252. {
  253. const char* key = i->first.c_str();
  254. const cmCacheManager::CacheEntry& value = i->second;
  255. switch(value.m_Type )
  256. {
  257. case cmCacheManager::BOOL:
  258. if(cmCacheManager::GetInstance()->IsOn(key))
  259. {
  260. m_CacheEntriesList.AddProperty(key,
  261. "ON",
  262. value.m_HelpString.c_str(),
  263. fltk::PropertyList::CHECKBOX,"");
  264. }
  265. else
  266. {
  267. m_CacheEntriesList.AddProperty(key,
  268. "OFF",
  269. value.m_HelpString.c_str(),
  270. fltk::PropertyList::CHECKBOX,"");
  271. }
  272. break;
  273. case cmCacheManager::PATH:
  274. m_CacheEntriesList.AddProperty(key,
  275. value.m_Value.c_str(),
  276. value.m_HelpString.c_str(),
  277. fltk::PropertyList::PATH,"");
  278. break;
  279. case cmCacheManager::FILEPATH:
  280. m_CacheEntriesList.AddProperty(key,
  281. value.m_Value.c_str(),
  282. value.m_HelpString.c_str(),
  283. fltk::PropertyList::FILE,"");
  284. break;
  285. case cmCacheManager::STRING:
  286. m_CacheEntriesList.AddProperty(key,
  287. value.m_Value.c_str(),
  288. value.m_HelpString.c_str(),
  289. fltk::PropertyList::EDIT,"");
  290. break;
  291. case cmCacheManager::INTERNAL:
  292. break;
  293. }
  294. }
  295. propertyListPack->end();
  296. propertyListPack->init_sizes();
  297. cacheValuesScroll->position( 0, 0 );
  298. this->UpdateData(false);
  299. }
  300. /**
  301. * UpdateData
  302. */
  303. void
  304. CMakeSetupGUIImplementation
  305. ::UpdateData( bool option )
  306. {
  307. dialogWindow->redraw();
  308. Fl::check();
  309. }
  310. /**
  311. * Fill cache manager from Cache GUI
  312. */
  313. void
  314. CMakeSetupGUIImplementation
  315. ::FillCacheManagerFromCacheGUI( void )
  316. {
  317. cmCacheManager::GetInstance()->GetCacheMap();
  318. std::set<fltk::PropertyItem*> items = m_CacheEntriesList.GetItems();
  319. for(std::set<fltk::PropertyItem*>::iterator i = items.begin();
  320. i != items.end(); ++i)
  321. {
  322. fltk::PropertyItem* item = *i;
  323. cmCacheManager::CacheEntry *entry =
  324. cmCacheManager::GetInstance()->GetCacheEntry(
  325. (const char*)item->m_propName.c_str() );
  326. if (entry)
  327. {
  328. entry->m_Value = item->m_curValue;
  329. }
  330. }
  331. }