CMakeSetupGUIImplementation.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. /**
  9. * Constructor
  10. */
  11. CMakeSetupGUIImplementation
  12. ::CMakeSetupGUIImplementation()
  13. {
  14. }
  15. /**
  16. * Destructor
  17. */
  18. CMakeSetupGUIImplementation
  19. ::~CMakeSetupGUIImplementation()
  20. {
  21. }
  22. /**
  23. * Show the graphic interface
  24. */
  25. void
  26. CMakeSetupGUIImplementation
  27. ::Show( void )
  28. {
  29. dialogWindow->show();
  30. }
  31. /**
  32. * Hide the graphic interface
  33. */
  34. void
  35. CMakeSetupGUIImplementation
  36. ::Close( void )
  37. {
  38. dialogWindow->hide();
  39. }
  40. /**
  41. * Browse for the path to the sources
  42. */
  43. void
  44. CMakeSetupGUIImplementation
  45. ::BrowseForSourcePath( void )
  46. {
  47. const char * path =
  48. fl_file_chooser(
  49. "Path to Sources",
  50. "",
  51. sourcePathTextInput->value() );
  52. if( !path )
  53. {
  54. return;
  55. }
  56. SetSourcePath( path );
  57. }
  58. /**
  59. * Browse for the path to the binaries
  60. */
  61. void
  62. CMakeSetupGUIImplementation
  63. ::BrowseForBinaryPath( void )
  64. {
  65. const char * path =
  66. fl_file_chooser(
  67. "Path to Binaries",
  68. "",
  69. binaryPathTextInput->value() );
  70. if( !path )
  71. {
  72. return;
  73. }
  74. binaryPathTextInput->value( path );
  75. }
  76. /**
  77. * Set the source path
  78. */
  79. void
  80. CMakeSetupGUIImplementation
  81. ::SetSourcePath( const char * path )
  82. {
  83. if( VerifySourcePath( path ) )
  84. {
  85. sourcePathTextInput->value( path );
  86. }
  87. }
  88. /**
  89. * Set the binary path
  90. */
  91. void
  92. CMakeSetupGUIImplementation
  93. ::SetBinaryPath( const char * path )
  94. {
  95. if( VerifyBinaryPath( path ) )
  96. {
  97. binaryPathTextInput->value( path );
  98. }
  99. }
  100. /**
  101. * Verify the path to binaries
  102. */
  103. bool
  104. CMakeSetupGUIImplementation
  105. ::VerifyBinaryPath( const char * path )
  106. {
  107. if( !path || strlen(path)==0 )
  108. {
  109. fl_alert("Please select the path to the binaries");
  110. return false;
  111. }
  112. if( !filename_isdir( path ) )
  113. {
  114. fl_alert("%s \n Doesn't exist or is not a directory",path);
  115. return false;
  116. }
  117. return true;
  118. }
  119. /**
  120. * Verify the path to sources
  121. */
  122. bool
  123. CMakeSetupGUIImplementation
  124. ::VerifySourcePath( const char * path )
  125. {
  126. if( !path || strlen(path)==0 )
  127. {
  128. fl_alert("Please select the path to the sources");
  129. return false;
  130. }
  131. if( !filename_isdir( path ) )
  132. {
  133. fl_alert("%s \n Doesn't exist or is not a directory",path);
  134. return false;
  135. }
  136. return true;
  137. }
  138. /**
  139. * Build the project files
  140. */
  141. void
  142. CMakeSetupGUIImplementation
  143. ::BuildProjectFiles( void )
  144. {
  145. // Verify that source path is a valid directory
  146. if( !VerifySourcePath( sourcePathTextInput->value() ) )
  147. {
  148. return;
  149. }
  150. // Verify that binary path is a valid directory
  151. if( !VerifyBinaryPath( binaryPathTextInput->value() ) )
  152. {
  153. return;
  154. }
  155. SaveCacheFromGUI();
  156. fl_message("Building project files ... please wait");
  157. }
  158. /**
  159. * Load Cache from disk to GUI
  160. */
  161. void
  162. CMakeSetupGUIImplementation
  163. ::LoadCacheFromDiskToGUI( void )
  164. {
  165. const char * m_WhereBuild = binaryPathTextInput->value();
  166. if( m_WhereBuild != "" )
  167. {
  168. cmCacheManager::GetInstance()->LoadCache(m_WhereBuild);
  169. // Make sure the internal "CMAKE" cache entry is set.
  170. const char* cacheValue = cmCacheManager::GetInstance()->GetCacheValue("CMAKE");
  171. if(!cacheValue)
  172. {
  173. // Find our own exectuable.
  174. std::string cMakeCMD = "\""+cmSystemTools::GetProgramPath(_pgmptr);
  175. cMakeCMD += "/CMakeSetupCMD.exe\"";
  176. // Save the value in the cache
  177. cmCacheManager::GetInstance()->AddCacheEntry("CMAKE",
  178. cMakeCMD.c_str(),
  179. "Path to CMake executable.",
  180. cmCacheManager::INTERNAL);
  181. }
  182. this->FillCacheGUIFromCacheManager();
  183. }
  184. }
  185. /**
  186. * Save Cache from disk to GUI
  187. */
  188. void
  189. CMakeSetupGUIImplementation
  190. ::SaveCacheFromGUI( void )
  191. {
  192. }
  193. /**
  194. * Fill Cache GUI from cache manager
  195. */
  196. void
  197. CMakeSetupGUIImplementation
  198. ::FillCacheGUIFromCacheManager( void )
  199. {
  200. const cmCacheManager::CacheEntryMap &cache =
  201. cmCacheManager::GetInstance()->GetCacheMap();
  202. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  203. i != cache.end(); ++i)
  204. {
  205. const char* key = i->first.c_str();
  206. const cmCacheManager::CacheEntry& value = i->second;
  207. /*
  208. switch(value.m_Type )
  209. {
  210. case cmCacheManager::BOOL:
  211. if(cmCacheManager::GetInstance()->IsOn(key))
  212. {
  213. m_CacheEntriesList.AddProperty(key,
  214. "ON",
  215. value.m_HelpString.c_str(),
  216. CPropertyList::CHECKBOX,"");
  217. }
  218. else
  219. {
  220. m_CacheEntriesList.AddProperty(key,
  221. "OFF",
  222. value.m_HelpString.c_str(),
  223. CPropertyList::CHECKBOX,"");
  224. }
  225. break;
  226. case cmCacheManager::PATH:
  227. m_CacheEntriesList.AddProperty(key,
  228. value.m_Value.c_str(),
  229. value.m_HelpString.c_str(),
  230. CPropertyList::PATH,"");
  231. break;
  232. case cmCacheManager::FILEPATH:
  233. m_CacheEntriesList.AddProperty(key,
  234. value.m_Value.c_str(),
  235. value.m_HelpString.c_str(),
  236. CPropertyList::FILE,"");
  237. break;
  238. case cmCacheManager::STRING:
  239. m_CacheEntriesList.AddProperty(key,
  240. value.m_Value.c_str(),
  241. value.m_HelpString.c_str(),
  242. CPropertyList::EDIT,"");
  243. break;
  244. case cmCacheManager::INTERNAL:
  245. break;
  246. }
  247. */
  248. }
  249. this->UpdateData(false);
  250. }
  251. /**
  252. * UpdateData
  253. */
  254. void
  255. CMakeSetupGUIImplementation
  256. ::UpdateData( bool option )
  257. {
  258. dialogWindow->redraw();
  259. Fl::check();
  260. }