CMakeSetupDialog.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. // pcbuilderdialogDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CMakeSetup.h"
  5. #include "CMakeSetupDialog.h"
  6. #include "../cmDSWMakefile.h"
  7. #include "../cmMSProjectGenerator.h"
  8. #include "../cmCacheManager.h"
  9. #include "../cmMakefile.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CAboutDlg dialog used for App About
  17. class CAboutDlg : public CDialog
  18. {
  19. public:
  20. CAboutDlg();
  21. // Dialog Data
  22. //{{AFX_DATA(CAboutDlg)
  23. enum { IDD = IDD_ABOUTBOX };
  24. //}}AFX_DATA
  25. // ClassWizard generated virtual function overrides
  26. //{{AFX_VIRTUAL(CAboutDlg)
  27. protected:
  28. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  29. //}}AFX_VIRTUAL
  30. // Implementation
  31. protected:
  32. //{{AFX_MSG(CAboutDlg)
  33. //}}AFX_MSG
  34. DECLARE_MESSAGE_MAP()
  35. };
  36. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  37. {
  38. //{{AFX_DATA_INIT(CAboutDlg)
  39. //}}AFX_DATA_INIT
  40. }
  41. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  42. {
  43. CDialog::DoDataExchange(pDX);
  44. //{{AFX_DATA_MAP(CAboutDlg)
  45. //}}AFX_DATA_MAP
  46. }
  47. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  48. //{{AFX_MSG_MAP(CAboutDlg)
  49. // No message handlers
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP();
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CMakeSetupDialog dialog
  54. CMakeSetupDialog::CMakeSetupDialog(CWnd* pParent /*=NULL*/)
  55. : CDialog(CMakeSetupDialog::IDD, pParent)
  56. {
  57. m_RegistryKey = "Software\\Kitware\\CMakeSetup\\Settings\\StartPath";
  58. //{{AFX_DATA_INIT(CMakeSetupDialog)
  59. m_WhereBuild = _T("");
  60. m_WhereSource = _T("");
  61. //}}AFX_DATA_INIT
  62. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  63. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  64. m_BuildPathChanged = false;
  65. }
  66. void CMakeSetupDialog::DoDataExchange(CDataExchange* pDX)
  67. {
  68. CDialog::DoDataExchange(pDX);
  69. //{{AFX_DATA_MAP(CMakeSetupDialog)
  70. DDX_Control(pDX, IDC_WhereSource, m_WhereSourceControl);
  71. DDX_Control(pDX, IDC_WhereBuild, m_WhereBuildControl);
  72. DDX_Control(pDX, IDC_LIST2, m_CacheEntriesList);
  73. DDX_CBString(pDX, IDC_WhereBuild, m_WhereBuild);
  74. DDX_CBString(pDX, IDC_WhereSource, m_WhereSource);
  75. //}}AFX_DATA_MAP
  76. }
  77. BEGIN_MESSAGE_MAP(CMakeSetupDialog, CDialog)
  78. //{{AFX_MSG_MAP(CMakeSetupDialog)
  79. ON_WM_SYSCOMMAND()
  80. ON_WM_PAINT()
  81. ON_WM_QUERYDRAGICON()
  82. ON_BN_CLICKED(IDC_BuildProjects, OnBuildProjects)
  83. ON_CBN_EDITCHANGE(IDC_WhereBuild, OnChangeWhereBuild)
  84. ON_BN_CLICKED(IDC_BUTTON2, OnBrowseWhereSource)
  85. ON_BN_CLICKED(IDC_BUTTON3, OnBrowseWhereBuild)
  86. ON_CBN_SELENDOK(IDC_WhereBuild, OnSelendokWhereBuild)
  87. ON_CBN_SELENDOK(IDC_WhereSource, OnSelendokWhereSource)
  88. ON_CBN_EDITCHANGE(IDC_WhereSource, OnChangeWhereSource)
  89. //}}AFX_MSG_MAP
  90. END_MESSAGE_MAP()
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CMakeSetupDialog message handlers
  93. BOOL CMakeSetupDialog::OnInitDialog()
  94. {
  95. CDialog::OnInitDialog();
  96. // Add "About..." menu item to system menu.
  97. // IDM_ABOUTBOX must be in the system command range.
  98. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  99. ASSERT(IDM_ABOUTBOX < 0xF000);
  100. CMenu* pSysMenu = GetSystemMenu(FALSE);
  101. if (pSysMenu != NULL)
  102. {
  103. CString strAboutMenu;
  104. strAboutMenu.LoadString(IDS_ABOUTBOX);
  105. if (!strAboutMenu.IsEmpty())
  106. {
  107. pSysMenu->AppendMenu(MF_SEPARATOR);
  108. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  109. }
  110. }
  111. // Set the icon for this dialog. The framework does this automatically
  112. // when the application's main window is not a dialog
  113. SetIcon(m_hIcon, TRUE); // Set big icon
  114. SetIcon(m_hIcon, FALSE); // Set small icon
  115. // Load source and build dirs from registry
  116. this->LoadFromRegistry();
  117. // try to load the cmake cache from disk
  118. this->LoadCacheFromDiskToGUI();
  119. // Set the version number
  120. char tmp[1024];
  121. sprintf(tmp,"Version %s", cmMakefile::GetVersion());
  122. SetDlgItemText(IDC_CMAKE_VERSION, tmp);
  123. return TRUE; // return TRUE unless you set the focus to a control
  124. }
  125. // About dialog invoke
  126. void CMakeSetupDialog::OnSysCommand(UINT nID, LPARAM lParam)
  127. {
  128. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  129. {
  130. CAboutDlg dlgAbout;
  131. dlgAbout.DoModal();
  132. }
  133. else
  134. {
  135. CDialog::OnSysCommand(nID, lParam);
  136. }
  137. }
  138. // If you add a minimize button to your dialog, you will need the code below
  139. // to draw the icon. For MFC applications using the document/view model,
  140. // this is automatically done for you by the framework.
  141. void CMakeSetupDialog::OnPaint()
  142. {
  143. if (IsIconic())
  144. {
  145. CPaintDC dc(this); // device context for painting
  146. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  147. // Center icon in client rectangle
  148. int cxIcon = GetSystemMetrics(SM_CXICON);
  149. int cyIcon = GetSystemMetrics(SM_CYICON);
  150. CRect rect;
  151. GetClientRect(&rect);
  152. int x = (rect.Width() - cxIcon + 1) / 2;
  153. int y = (rect.Height() - cyIcon + 1) / 2;
  154. // Draw the icon
  155. dc.DrawIcon(x, y, m_hIcon);
  156. }
  157. else
  158. {
  159. CDialog::OnPaint();
  160. }
  161. }
  162. // The system calls this to obtain the cursor to display while the user drags
  163. // the minimized window.
  164. HCURSOR CMakeSetupDialog::OnQueryDragIcon()
  165. {
  166. return (HCURSOR) m_hIcon;
  167. }
  168. // Insane Microsoft way of setting the initial directory
  169. // for the Shbrowseforfolder function...
  170. // SetSelProc
  171. // Callback procedure to set the initial selection of the browser.
  172. int CALLBACK CMakeSetupDialog_SetSelProc( HWND hWnd, UINT uMsg,
  173. LPARAM lParam, LPARAM lpData )
  174. {
  175. if (uMsg==BFFM_INITIALIZED)
  176. {
  177. ::SendMessage(hWnd, BFFM_SETSELECTION, TRUE, lpData );
  178. }
  179. return 0;
  180. }
  181. // Browse button
  182. bool CMakeSetupDialog::Browse(CString &result, const char *title)
  183. {
  184. // don't know what to do with initial right now...
  185. char szPathName[4096];
  186. BROWSEINFO bi;
  187. bi.hwndOwner = m_hWnd;
  188. bi.pidlRoot = NULL;
  189. bi.pszDisplayName = (LPTSTR)szPathName;
  190. bi.lpszTitle = title;
  191. bi.ulFlags = BIF_BROWSEINCLUDEFILES;
  192. // set up initial directory code
  193. bi.lpfn = CMakeSetupDialog_SetSelProc;
  194. bi.lParam = (LPARAM)(LPCSTR) result;
  195. // open the directory chooser
  196. LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
  197. // get the result
  198. bool bSuccess = (SHGetPathFromIDList(pidl, szPathName) ? true : false);
  199. if(bSuccess)
  200. {
  201. result = szPathName;
  202. }
  203. return bSuccess;
  204. }
  205. void CMakeSetupDialog::SaveToRegistry()
  206. {
  207. HKEY hKey;
  208. DWORD dwDummy;
  209. if(RegCreateKeyEx(HKEY_CURRENT_USER,
  210. m_RegistryKey,
  211. 0, "", REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE,
  212. NULL, &hKey, &dwDummy) != ERROR_SUCCESS)
  213. {
  214. return;
  215. }
  216. else
  217. {
  218. // load some values
  219. CString regvalue;
  220. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource","C:\\");
  221. if(m_WhereSource != regvalue)
  222. {
  223. regvalue = "";
  224. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource3","");
  225. RegSetValueEx(hKey, _T("WhereSource4"), 0, REG_SZ,
  226. (CONST BYTE *)(const char *)regvalue,
  227. regvalue.GetLength());
  228. regvalue = "";
  229. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource2","");
  230. RegSetValueEx(hKey, _T("WhereSource3"), 0, REG_SZ,
  231. (CONST BYTE *)(const char *)regvalue,
  232. regvalue.GetLength());
  233. regvalue = "";
  234. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource","");
  235. RegSetValueEx(hKey, _T("WhereSource2"), 0, REG_SZ,
  236. (CONST BYTE *)(const char *)regvalue,
  237. regvalue.GetLength());
  238. RegSetValueEx(hKey, _T("WhereSource"), 0, REG_SZ,
  239. (CONST BYTE *)(const char *)m_WhereSource,
  240. m_WhereSource.GetLength());
  241. }
  242. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild","C:\\");
  243. if(m_WhereBuild != regvalue)
  244. {
  245. regvalue = "";
  246. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild3","");
  247. RegSetValueEx(hKey, _T("WhereBuild4"), 0, REG_SZ,
  248. (CONST BYTE *)(const char *)regvalue,
  249. regvalue.GetLength());
  250. regvalue = "";
  251. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild2","");
  252. RegSetValueEx(hKey, _T("WhereBuild3"), 0, REG_SZ,
  253. (CONST BYTE *)(const char *)regvalue,
  254. regvalue.GetLength());
  255. regvalue = "";
  256. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild","");
  257. RegSetValueEx(hKey, _T("WhereBuild2"), 0, REG_SZ,
  258. (CONST BYTE *)(const char *)regvalue,
  259. regvalue.GetLength());
  260. RegSetValueEx(hKey, _T("WhereBuild"), 0, REG_SZ,
  261. (CONST BYTE *)(const char *)m_WhereBuild,
  262. m_WhereBuild.GetLength());
  263. }
  264. }
  265. RegCloseKey(hKey);
  266. }
  267. void CMakeSetupDialog::ReadRegistryValue(HKEY hKey,
  268. CString *val,
  269. const char *key,
  270. const char *adefault)
  271. {
  272. DWORD dwType, dwSize;
  273. char *pb;
  274. dwType = REG_SZ;
  275. pb = val->GetBuffer(MAX_PATH);
  276. dwSize = MAX_PATH;
  277. if(RegQueryValueEx(hKey,_T(key), NULL, &dwType,
  278. (BYTE *)pb, &dwSize) != ERROR_SUCCESS)
  279. {
  280. val->ReleaseBuffer();
  281. *val = _T(adefault);
  282. }
  283. else
  284. {
  285. val->ReleaseBuffer();
  286. }
  287. }
  288. void CMakeSetupDialog::LoadFromRegistry()
  289. {
  290. HKEY hKey;
  291. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  292. m_RegistryKey,
  293. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  294. {
  295. return;
  296. }
  297. else
  298. {
  299. // load some values
  300. this->ReadRegistryValue(hKey, &(m_WhereSource),"WhereSource","C:\\");
  301. this->ReadRegistryValue(hKey, &(m_WhereBuild),"WhereBuild","C:\\");
  302. m_WhereSourceControl.AddString(m_WhereSource);
  303. m_WhereBuildControl.AddString(m_WhereBuild);
  304. CString regvalue;
  305. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource2","C:\\");
  306. m_WhereSourceControl.AddString(regvalue);
  307. regvalue = "";
  308. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild2","C:\\");
  309. m_WhereBuildControl.AddString(regvalue);
  310. regvalue = "";
  311. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource3","C:\\");
  312. m_WhereSourceControl.AddString(regvalue);
  313. regvalue = "";
  314. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild3","C:\\");
  315. m_WhereBuildControl.AddString(regvalue);
  316. regvalue = "";
  317. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource4","C:\\");
  318. m_WhereSourceControl.AddString(regvalue);
  319. regvalue = "";
  320. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild4","C:\\");
  321. m_WhereBuildControl.AddString(regvalue);
  322. }
  323. RegCloseKey(hKey);
  324. }
  325. // Callback for browse source button
  326. void CMakeSetupDialog::OnBrowseWhereSource()
  327. {
  328. this->UpdateData();
  329. Browse(m_WhereSource, "Enter Path to Source");
  330. this->UpdateData(false);
  331. this->OnChangeWhereSource();
  332. }
  333. // Callback for browser build button
  334. void CMakeSetupDialog::OnBrowseWhereBuild()
  335. {
  336. this->UpdateData();
  337. Browse(m_WhereBuild, "Enter Path to Build");
  338. this->UpdateData(false);
  339. this->OnChangeWhereBuild();
  340. }
  341. // Callback for build projects button
  342. void CMakeSetupDialog::OnBuildProjects()
  343. {
  344. if(!cmSystemTools::FileExists(m_WhereBuild))
  345. {
  346. std::string message =
  347. "Build directory does not exist, should I create it?\n\n"
  348. "Directory: ";
  349. message += (const char*)m_WhereBuild;
  350. if(MessageBox(message.c_str(), "Create Directory", MB_OKCANCEL) == IDOK)
  351. {
  352. cmSystemTools::MakeDirectory(m_WhereBuild);
  353. }
  354. else
  355. {
  356. MessageBox("Build Project aborted, nothing done.");
  357. return;
  358. }
  359. }
  360. ::SetCursor(LoadCursor(NULL, IDC_WAIT));
  361. // get all the info from the screen
  362. this->UpdateData();
  363. if(!m_BuildPathChanged)
  364. {
  365. // if the build path has not changed save the
  366. // current GUI values to the cache
  367. this->SaveCacheFromGUI();
  368. }
  369. // Make sure we are working from the cache on disk
  370. this->LoadCacheFromDiskToGUI();
  371. // duh
  372. // Create a makefile object
  373. cmMakefile makefile;
  374. makefile.SetMakefileGenerator(new cmMSProjectGenerator);
  375. makefile.GetMakefileGenerator()->ComputeSystemInfo();
  376. makefile.SetHomeDirectory(m_WhereSource);
  377. makefile.SetStartOutputDirectory(m_WhereBuild);
  378. makefile.SetHomeOutputDirectory(m_WhereBuild);
  379. makefile.SetStartDirectory(m_WhereSource);
  380. makefile.MakeStartDirectoriesCurrent();
  381. CString makefileIn = m_WhereSource;
  382. makefileIn += "/CMakeLists.txt";
  383. makefile.ReadListFile(makefileIn);
  384. if(!cmCacheManager::GetInstance()->GetCacheValue("CMAKE_CXX"))
  385. {
  386. if(!makefile.GetDefinition("CMAKE_CXX"))
  387. {
  388. makefile.AddDefinition("CMAKE_CXX", "VC60");
  389. }
  390. cmCacheManager::GetInstance()->AddCacheEntry("CMAKE_CXX", "VC60",
  391. "Compiler used", cmCacheManager::STRING);
  392. }
  393. // Generate the project files
  394. makefile.GenerateMakefile();
  395. // Save the cache
  396. cmCacheManager::GetInstance()->SaveCache(&makefile);
  397. // end duh
  398. // update the GUI with any new values in the caused by the
  399. // generation process
  400. this->LoadCacheFromDiskToGUI();
  401. cmCacheManager::GetInstance()->DefineCache(&makefile);
  402. // save source and build paths to registry
  403. this->SaveToRegistry();
  404. // path is not up-to-date
  405. m_BuildPathChanged = false;
  406. ::SetCursor(LoadCursor(NULL, IDC_ARROW));
  407. }
  408. // callback for combo box menu where build selection
  409. void CMakeSetupDialog::OnSelendokWhereBuild()
  410. {
  411. m_WhereBuildControl.GetLBText(m_WhereBuildControl.GetCurSel(), m_WhereBuild);
  412. this->UpdateData(FALSE);
  413. this->OnChangeWhereBuild();
  414. }
  415. // callback for combo box menu where source selection
  416. void CMakeSetupDialog::OnSelendokWhereSource()
  417. {
  418. m_WhereSourceControl.GetLBText(m_WhereSourceControl.GetCurSel(), m_WhereSource);
  419. this->UpdateData(FALSE);
  420. this->OnChangeWhereSource();
  421. }
  422. // callback for chaing source directory
  423. void CMakeSetupDialog::OnChangeWhereSource()
  424. {
  425. }
  426. // callback for changing the build directory
  427. void CMakeSetupDialog::OnChangeWhereBuild()
  428. {
  429. this->UpdateData();
  430. std::string cachefile = m_WhereBuild;
  431. cachefile += "/CMakeCache.txt";
  432. m_CacheEntriesList.RemoveAll();
  433. if(cmSystemTools::FileExists(cachefile.c_str()))
  434. {
  435. m_CacheEntriesList.ShowWindow(SW_SHOW);
  436. this->LoadCacheFromDiskToGUI();
  437. m_BuildPathChanged = true;
  438. }
  439. }
  440. // copy from the cache manager to the cache edit list box
  441. void CMakeSetupDialog::FillCacheGUIFromCacheManager()
  442. {
  443. const cmCacheManager::CacheEntryMap &cache =
  444. cmCacheManager::GetInstance()->GetCacheMap();
  445. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  446. i != cache.end(); ++i)
  447. {
  448. const char* key = i->first.c_str();
  449. const cmCacheManager::CacheEntry& value = i->second;
  450. switch(value.m_Type )
  451. {
  452. case cmCacheManager::BOOL:
  453. if(cmCacheManager::GetInstance()->IsOn(key))
  454. {
  455. m_CacheEntriesList.AddProperty(key,
  456. "ON",
  457. value.m_HelpString.c_str(),
  458. CPropertyList::CHECKBOX,"");
  459. }
  460. else
  461. {
  462. m_CacheEntriesList.AddProperty(key,
  463. "OFF",
  464. value.m_HelpString.c_str(),
  465. CPropertyList::CHECKBOX,"");
  466. }
  467. break;
  468. case cmCacheManager::PATH:
  469. m_CacheEntriesList.AddProperty(key,
  470. value.m_Value.c_str(),
  471. value.m_HelpString.c_str(),
  472. CPropertyList::PATH,"");
  473. break;
  474. case cmCacheManager::FILEPATH:
  475. m_CacheEntriesList.AddProperty(key,
  476. value.m_Value.c_str(),
  477. value.m_HelpString.c_str(),
  478. CPropertyList::FILE,"");
  479. break;
  480. case cmCacheManager::STRING:
  481. m_CacheEntriesList.AddProperty(key,
  482. value.m_Value.c_str(),
  483. value.m_HelpString.c_str(),
  484. CPropertyList::EDIT,"");
  485. break;
  486. case cmCacheManager::INTERNAL:
  487. break;
  488. }
  489. }
  490. this->UpdateData(FALSE);
  491. }
  492. // copy from the list box to the cache manager
  493. void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
  494. {
  495. cmCacheManager::GetInstance()->GetCacheMap();
  496. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  497. for(std::set<CPropertyItem*>::iterator i = items.begin();
  498. i != items.end(); ++i)
  499. {
  500. CPropertyItem* item = *i;
  501. cmCacheManager::CacheEntry *entry =
  502. cmCacheManager::GetInstance()->GetCacheEntry((const char*)item->m_propName);
  503. if (entry)
  504. {
  505. entry->m_Value = item->m_curValue;
  506. }
  507. }
  508. }
  509. //! Load cache file from m_WhereBuild and display in GUI editor
  510. void CMakeSetupDialog::LoadCacheFromDiskToGUI()
  511. {
  512. if(m_WhereBuild != "")
  513. {
  514. cmCacheManager::GetInstance()->LoadCache(m_WhereBuild);
  515. // Find our own exectuable.
  516. char fname[1024];
  517. ::GetModuleFileName(NULL,fname,1023);
  518. std::string root = cmSystemTools::GetProgramPath(fname);
  519. std::string::size_type slashPos = root.rfind("/");
  520. if(slashPos != std::string::npos)
  521. {
  522. root = root.substr(0, slashPos);
  523. }
  524. cmCacheManager::GetInstance()->AddCacheEntry
  525. ("CMAKE_ROOT", root.c_str(),
  526. "Path to CMake installation.", cmCacheManager::INTERNAL);
  527. std::string cMakeCMD = "\""+cmSystemTools::GetProgramPath(fname);
  528. cMakeCMD += "/cmake.exe\"";
  529. // Save the value in the cache
  530. cmCacheManager::GetInstance()->AddCacheEntry("CMAKE_COMMAND",
  531. cMakeCMD.c_str(),
  532. "Path to CMake executable.",
  533. cmCacheManager::INTERNAL);
  534. this->FillCacheGUIFromCacheManager();
  535. }
  536. }
  537. //! Save GUI values to cmCacheManager and then save to disk.
  538. void CMakeSetupDialog::SaveCacheFromGUI()
  539. {
  540. this->FillCacheManagerFromCacheGUI();
  541. if(m_WhereBuild != "")
  542. {
  543. cmCacheManager::GetInstance()->SaveCache(m_WhereBuild);
  544. }
  545. }