CMakeSetupDialog.cpp 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. // pcbuilderdialogDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CMakeSetup.h"
  5. #include "MakeHelp.h"
  6. #include "PathDialog.h"
  7. #include "CMakeSetupDialog.h"
  8. #include "CMakeCommandLineInfo.h"
  9. #include "../cmCacheManager.h"
  10. #include "../cmake.h"
  11. #include "../cmMakefileGenerator.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CAboutDlg dialog used for App About
  19. class CAboutDlg : public CDialog
  20. {
  21. public:
  22. CAboutDlg();
  23. // Dialog Data
  24. //{{AFX_DATA(CAboutDlg)
  25. enum { IDD = IDD_ABOUTBOX };
  26. //}}AFX_DATA
  27. // ClassWizard generated virtual function overrides
  28. //{{AFX_VIRTUAL(CAboutDlg)
  29. protected:
  30. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  31. //}}AFX_VIRTUAL
  32. // Implementation
  33. protected:
  34. //{{AFX_MSG(CAboutDlg)
  35. //}}AFX_MSG
  36. DECLARE_MESSAGE_MAP()
  37. };
  38. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  39. {
  40. //{{AFX_DATA_INIT(CAboutDlg)
  41. //}}AFX_DATA_INIT
  42. }
  43. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CDialog::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(CAboutDlg)
  47. //}}AFX_DATA_MAP
  48. }
  49. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  50. //{{AFX_MSG_MAP(CAboutDlg)
  51. // No message handlers
  52. //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP();
  54. void MFCMessageCallback(const char* m, const char* title, bool& nomore)
  55. {
  56. std::string message = m;
  57. message += "\n\n(Press Cancel to suppress any further messages.)";
  58. if(::MessageBox(0, message.c_str(), title,
  59. MB_OKCANCEL) == IDCANCEL)
  60. {
  61. nomore = true;
  62. }
  63. }
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CMakeSetupDialog dialog
  66. CMakeSetupDialog::CMakeSetupDialog(const CMakeCommandLineInfo& cmdInfo,
  67. CWnd* pParent /*=NULL*/)
  68. : CDialog(CMakeSetupDialog::IDD, pParent)
  69. {
  70. cmSystemTools::SetErrorCallback(MFCMessageCallback);
  71. m_RegistryKey = "Software\\Kitware\\CMakeSetup\\Settings\\StartPath";
  72. //{{AFX_DATA_INIT(CMakeSetupDialog)
  73. m_WhereSource = cmdInfo.m_WhereSource;
  74. m_WhereBuild = cmdInfo.m_WhereBuild;
  75. m_GeneratorChoiceString = cmdInfo.m_GeneratorChoiceString;
  76. m_AdvancedValues = cmdInfo.m_AdvancedValues;
  77. //}}AFX_DATA_INIT
  78. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  79. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  80. m_BuildPathChanged = false;
  81. // Find the path to the cmake.exe executable
  82. char fname[1024];
  83. ::GetModuleFileName(NULL,fname,1023);
  84. // extract just the path part
  85. m_PathToExecutable = cmSystemTools::GetProgramPath(fname).c_str();
  86. // add the cmake.exe to the path
  87. m_PathToExecutable += "/cmake.exe";
  88. m_oldCX = -1;
  89. m_deltaXRemainder = 0;
  90. }
  91. void CMakeSetupDialog::DoDataExchange(CDataExchange* pDX)
  92. {
  93. CDialog::DoDataExchange(pDX);
  94. //{{AFX_DATA_MAP(CMakeSetupDialog)
  95. DDX_Control(pDX, IDC_HELP_BUTTON, m_HelpButton);
  96. DDX_Control(pDX, IDC_Generator, m_GeneratorChoice);
  97. DDX_Control(pDX, IDC_OK, m_OKButton);
  98. DDX_Control(pDX, IDCANCEL, m_CancelButton);
  99. DDX_CBStringExact(pDX, IDC_WhereSource, m_WhereSource);
  100. DDX_CBStringExact(pDX, IDC_WhereBuild, m_WhereBuild);
  101. DDX_Control(pDX, IDC_FRAME, m_ListFrame);
  102. DDX_Control(pDX, IDC_WhereSource, m_WhereSourceControl);
  103. DDX_Control(pDX, IDC_WhereBuild, m_WhereBuildControl);
  104. DDX_Control(pDX, IDC_LIST2, m_CacheEntriesList);
  105. DDX_Control(pDX, IDC_MouseHelpCaption, m_MouseHelp);
  106. DDX_Control(pDX, IDC_CMAKE_VERSION, m_VersionDisplay);
  107. DDX_Control(pDX, IDC_BuildProjects, m_Configure);
  108. DDX_CBStringExact(pDX, IDC_Generator, m_GeneratorChoiceString);
  109. DDX_Check(pDX, IDC_AdvancedValues, m_AdvancedValues);
  110. //}}AFX_DATA_MAP
  111. }
  112. BEGIN_MESSAGE_MAP(CMakeSetupDialog, CDialog)
  113. //{{AFX_MSG_MAP(CMakeSetupDialog)
  114. ON_WM_SYSCOMMAND()
  115. ON_WM_PAINT()
  116. ON_WM_QUERYDRAGICON()
  117. ON_BN_CLICKED(IDC_BUTTON2, OnBrowseWhereSource)
  118. ON_BN_CLICKED(IDC_BuildProjects, OnConfigure)
  119. ON_BN_CLICKED(IDC_BUTTON3, OnBrowseWhereBuild)
  120. ON_CBN_EDITCHANGE(IDC_WhereBuild, OnChangeWhereBuild)
  121. ON_CBN_SELCHANGE(IDC_WhereBuild, OnSelendokWhereBuild)
  122. ON_CBN_EDITCHANGE(IDC_WhereSource, OnChangeWhereSource)
  123. ON_CBN_SELENDOK(IDC_WhereSource, OnSelendokWhereSource)
  124. ON_WM_SIZE()
  125. ON_WM_GETMINMAXINFO()
  126. ON_BN_CLICKED(IDC_OK, OnOk)
  127. ON_CBN_EDITCHANGE(IDC_Generator, OnEditchangeGenerator)
  128. ON_BN_CLICKED(IDC_HELP_BUTTON, OnHelpButton)
  129. ON_BN_CLICKED(IDCANCEL, OnCancel)
  130. ON_BN_CLICKED(IDC_AdvancedValues, OnAdvancedValues)
  131. ON_BN_DOUBLECLICKED(IDC_AdvancedValues, OnDoubleclickedAdvancedValues)
  132. //}}AFX_MSG_MAP
  133. END_MESSAGE_MAP()
  134. /////////////////////////////////////////////////////////////////////////////
  135. // CMakeSetupDialog message handlers
  136. BOOL CMakeSetupDialog::OnInitDialog()
  137. {
  138. CDialog::OnInitDialog();
  139. // Add "Create shortcut" menu item to system menu.
  140. // IDM_CREATESHORTCUT must be in the system command range.
  141. ASSERT((IDM_CREATESHORTCUT & 0xFFF0) == IDM_CREATESHORTCUT);
  142. ASSERT(IDM_CREATESHORTCUT < 0xF000);
  143. // Add "About..." menu item to system menu.
  144. // IDM_ABOUTBOX must be in the system command range.
  145. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  146. ASSERT(IDM_ABOUTBOX < 0xF000);
  147. CMenu* pSysMenu = GetSystemMenu(FALSE);
  148. if (pSysMenu != NULL)
  149. {
  150. CString strCreateShortcutMenu;
  151. strCreateShortcutMenu.LoadString(IDS_CREATESHORTCUT);
  152. if (!strCreateShortcutMenu.IsEmpty())
  153. {
  154. pSysMenu->AppendMenu(MF_SEPARATOR);
  155. pSysMenu->AppendMenu(MF_STRING,
  156. IDM_CREATESHORTCUT,
  157. strCreateShortcutMenu);
  158. }
  159. CString strAboutMenu;
  160. strAboutMenu.LoadString(IDS_ABOUTBOX);
  161. if (!strAboutMenu.IsEmpty())
  162. {
  163. pSysMenu->AppendMenu(MF_SEPARATOR);
  164. pSysMenu->AppendMenu(MF_STRING,
  165. IDM_ABOUTBOX,
  166. strAboutMenu);
  167. }
  168. }
  169. // Set the icon for this dialog. The framework does this automatically
  170. // when the application's main window is not a dialog
  171. SetIcon(m_hIcon, TRUE); // Set big icon
  172. SetIcon(m_hIcon, FALSE); // Set small icon
  173. // Load source and build dirs from registry
  174. this->LoadFromRegistry();
  175. cmake m; // force a register of generators
  176. std::vector<std::string> names;
  177. cmMakefileGenerator::GetRegisteredGenerators(names);
  178. for(std::vector<std::string>::iterator i = names.begin();
  179. i != names.end(); ++i)
  180. {
  181. m_GeneratorChoice.AddString(i->c_str());
  182. }
  183. m_GeneratorChoiceString = "Visual Studio 6";
  184. // try to load the cmake cache from disk
  185. this->LoadCacheFromDiskToGUI();
  186. m_WhereBuildControl.LimitText(2048);
  187. m_WhereSourceControl.LimitText(2048);
  188. m_GeneratorChoice.LimitText(2048);
  189. // Set the version number
  190. char tmp[1024];
  191. sprintf(tmp,"Version %d.%d", cmMakefile::GetMajorVersion(),
  192. cmMakefile::GetMinorVersion());
  193. SetDlgItemText(IDC_CMAKE_VERSION, tmp);
  194. this->UpdateData(FALSE);
  195. return TRUE; // return TRUE unless you set the focus to a control
  196. }
  197. // About dialog invoke
  198. void CMakeSetupDialog::OnSysCommand(UINT nID, LPARAM lParam)
  199. {
  200. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  201. {
  202. CAboutDlg dlgAbout;
  203. dlgAbout.DoModal();
  204. }
  205. else if ((nID & 0xFFF0) == IDM_CREATESHORTCUT)
  206. {
  207. CreateShortcut();
  208. }
  209. else
  210. {
  211. CDialog::OnSysCommand(nID, lParam);
  212. }
  213. }
  214. // If you add a minimize button to your dialog, you will need the code below
  215. // to draw the icon. For MFC applications using the document/view model,
  216. // this is automatically done for you by the framework.
  217. void CMakeSetupDialog::OnPaint()
  218. {
  219. if (IsIconic())
  220. {
  221. CPaintDC dc(this); // device context for painting
  222. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  223. // Center icon in client rectangle
  224. int cxIcon = GetSystemMetrics(SM_CXICON);
  225. int cyIcon = GetSystemMetrics(SM_CYICON);
  226. CRect rect;
  227. GetClientRect(&rect);
  228. int x = (rect.Width() - cxIcon + 1) / 2;
  229. int y = (rect.Height() - cyIcon + 1) / 2;
  230. // Draw the icon
  231. dc.DrawIcon(x, y, m_hIcon);
  232. }
  233. else
  234. {
  235. CDialog::OnPaint();
  236. }
  237. }
  238. // The system calls this to obtain the cursor to display while the user drags
  239. // the minimized window.
  240. HCURSOR CMakeSetupDialog::OnQueryDragIcon()
  241. {
  242. return (HCURSOR) m_hIcon;
  243. }
  244. // Browse button
  245. bool CMakeSetupDialog::Browse(CString &result, const char *title)
  246. {
  247. CPathDialog dlg("Select Path", title, result);
  248. if(dlg.DoModal()==IDOK)
  249. {
  250. result = dlg.GetPathName();
  251. return true;
  252. }
  253. else
  254. {
  255. return false;
  256. }
  257. }
  258. void CMakeSetupDialog::SaveToRegistry()
  259. {
  260. HKEY hKey;
  261. DWORD dwDummy;
  262. if(RegCreateKeyEx(HKEY_CURRENT_USER,
  263. m_RegistryKey,
  264. 0, "", REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE,
  265. NULL, &hKey, &dwDummy) != ERROR_SUCCESS)
  266. {
  267. return;
  268. }
  269. else
  270. {
  271. // save some values
  272. CString regvalue;
  273. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource1","C:\\");
  274. int shiftEnd = 9;
  275. if(m_WhereSource != regvalue)
  276. {
  277. char keyName[1024];
  278. char keyName2[1024];
  279. int i;
  280. for (i = 2; i < 10; ++i)
  281. {
  282. regvalue = "";
  283. sprintf(keyName,"WhereSource%i",i);
  284. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  285. // check for short circuit, if the new value is already in
  286. // the list then we stop
  287. if (m_WhereSource == regvalue)
  288. {
  289. shiftEnd = i - 1;
  290. }
  291. }
  292. for (i = shiftEnd; i; --i)
  293. {
  294. regvalue = "";
  295. sprintf(keyName,"WhereSource%i",i);
  296. sprintf(keyName2,"WhereSource%i",i+1);
  297. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  298. if (strlen(regvalue))
  299. {
  300. RegSetValueEx(hKey, _T(keyName2), 0, REG_SZ,
  301. (CONST BYTE *)(const char *)regvalue,
  302. regvalue.GetLength());
  303. }
  304. }
  305. RegSetValueEx(hKey, _T("WhereSource1"), 0, REG_SZ,
  306. (CONST BYTE *)(const char *)m_WhereSource,
  307. m_WhereSource.GetLength());
  308. }
  309. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild1","C:\\");
  310. if(m_WhereBuild != regvalue)
  311. {
  312. int i;
  313. char keyName[1024];
  314. char keyName2[1024];
  315. for (i = 2; i < 10; ++i)
  316. {
  317. regvalue = "";
  318. sprintf(keyName,"WhereBuild%i",i);
  319. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  320. // check for short circuit, if the new value is already in
  321. // the list then we stop
  322. if (m_WhereBuild == regvalue)
  323. {
  324. shiftEnd = i - 1;
  325. }
  326. }
  327. for (i = shiftEnd; i; --i)
  328. {
  329. regvalue = "";
  330. sprintf(keyName,"WhereBuild%i",i);
  331. sprintf(keyName2,"WhereBuild%i",i+1);
  332. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  333. if (strlen(regvalue))
  334. {
  335. RegSetValueEx(hKey, _T(keyName2), 0, REG_SZ,
  336. (CONST BYTE *)(const char *)regvalue,
  337. regvalue.GetLength());
  338. }
  339. }
  340. RegSetValueEx(hKey, _T("WhereBuild1"), 0, REG_SZ,
  341. (CONST BYTE *)(const char *)m_WhereBuild,
  342. m_WhereBuild.GetLength());
  343. }
  344. }
  345. RegCloseKey(hKey);
  346. }
  347. void CMakeSetupDialog::ReadRegistryValue(HKEY hKey,
  348. CString *val,
  349. const char *key,
  350. const char *adefault)
  351. {
  352. DWORD dwType, dwSize;
  353. char *pb;
  354. dwType = REG_SZ;
  355. pb = val->GetBuffer(MAX_PATH);
  356. dwSize = MAX_PATH;
  357. if(RegQueryValueEx(hKey,_T(key), NULL, &dwType,
  358. (BYTE *)pb, &dwSize) != ERROR_SUCCESS)
  359. {
  360. val->ReleaseBuffer();
  361. *val = _T(adefault);
  362. }
  363. else
  364. {
  365. val->ReleaseBuffer();
  366. }
  367. }
  368. void CMakeSetupDialog::LoadFromRegistry()
  369. {
  370. HKEY hKey;
  371. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  372. m_RegistryKey,
  373. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  374. {
  375. return;
  376. }
  377. else
  378. {
  379. // load some values
  380. if (m_WhereSource.IsEmpty())
  381. {
  382. this->ReadRegistryValue(hKey, &(m_WhereSource),"WhereSource1","C:\\");
  383. }
  384. if (m_WhereBuild.IsEmpty())
  385. {
  386. this->ReadRegistryValue(hKey, &(m_WhereBuild),"WhereBuild1","C:\\");
  387. }
  388. m_WhereSourceControl.AddString(m_WhereSource);
  389. m_WhereBuildControl.AddString(m_WhereBuild);
  390. char keyname[1024];
  391. CString regvalue;
  392. int i;
  393. for (i = 2; i <= 10; ++i)
  394. {
  395. sprintf(keyname,"WhereSource%i",i);
  396. regvalue = "";
  397. this->ReadRegistryValue(hKey, &(regvalue),keyname,"C:\\");
  398. if (strcmp("C:\\",regvalue))
  399. {
  400. m_WhereSourceControl.AddString(regvalue);
  401. }
  402. sprintf(keyname,"WhereBuild%i",i);
  403. regvalue = "";
  404. this->ReadRegistryValue(hKey, &(regvalue),keyname,"C:\\");
  405. if (strcmp("C:\\",regvalue))
  406. {
  407. m_WhereBuildControl.AddString(regvalue);
  408. }
  409. }
  410. }
  411. RegCloseKey(hKey);
  412. }
  413. // Callback for browse source button
  414. void CMakeSetupDialog::OnBrowseWhereSource()
  415. {
  416. this->UpdateData();
  417. Browse(m_WhereSource, "Enter Path to Source");
  418. this->UpdateData(false);
  419. this->OnChangeWhereSource();
  420. }
  421. // Callback for browser build button
  422. void CMakeSetupDialog::OnBrowseWhereBuild()
  423. {
  424. this->UpdateData();
  425. Browse(m_WhereBuild, "Enter Path to Build");
  426. this->UpdateData(false);
  427. this->OnChangeWhereBuild();
  428. }
  429. void CMakeSetupDialog::RunCMake(bool generateProjectFiles)
  430. {
  431. if(!cmSystemTools::FileExists(m_WhereBuild))
  432. {
  433. std::string message =
  434. "Build directory does not exist, should I create it?\n\n"
  435. "Directory: ";
  436. message += (const char*)m_WhereBuild;
  437. if(MessageBox(message.c_str(), "Create Directory", MB_OKCANCEL) == IDOK)
  438. {
  439. cmSystemTools::MakeDirectory(m_WhereBuild);
  440. }
  441. else
  442. {
  443. MessageBox("Build Project aborted, nothing done.");
  444. return;
  445. }
  446. }
  447. // set the wait cursor
  448. ::SetCursor(LoadCursor(NULL, IDC_WAIT));
  449. // get all the info from the dialog
  450. this->UpdateData();
  451. // always save the current gui values to disk
  452. this->SaveCacheFromGUI();
  453. // Make sure we are working from the cache on disk
  454. this->LoadCacheFromDiskToGUI();
  455. m_OKButton.EnableWindow(false);
  456. // create a cmake object
  457. cmake make;
  458. // create the arguments for the cmake object
  459. std::vector<std::string> args;
  460. args.push_back((const char*)m_PathToExecutable);
  461. std::string arg;
  462. arg = "-H";
  463. arg += m_WhereSource;
  464. args.push_back(arg);
  465. arg = "-B";
  466. arg += m_WhereBuild;
  467. args.push_back(arg);
  468. arg = "-G";
  469. arg += m_GeneratorChoiceString;
  470. args.push_back(arg);
  471. // run the generate process
  472. if(make.Generate(args, generateProjectFiles) != 0)
  473. {
  474. cmSystemTools::Error(
  475. "Error in generation process, project files may be invalid");
  476. }
  477. // update the GUI with any new values in the caused by the
  478. // generation process
  479. this->LoadCacheFromDiskToGUI();
  480. // save source and build paths to registry
  481. this->SaveToRegistry();
  482. // path is up-to-date now
  483. m_BuildPathChanged = false;
  484. // put the cursor back
  485. ::SetCursor(LoadCursor(NULL, IDC_ARROW));
  486. cmSystemTools::ResetErrorOccuredFlag();
  487. }
  488. // Callback for build projects button
  489. void CMakeSetupDialog::OnConfigure()
  490. {
  491. // enable error messages each time configure is pressed
  492. cmSystemTools::EnableMessages();
  493. this->RunCMake(false);
  494. }
  495. // callback for combo box menu where build selection
  496. void CMakeSetupDialog::OnSelendokWhereBuild()
  497. {
  498. m_WhereBuildControl.GetLBText(m_WhereBuildControl.GetCurSel(),
  499. m_WhereBuild);
  500. m_WhereBuildControl.SetWindowText( m_WhereBuild);
  501. this->UpdateData(FALSE);
  502. this->OnChangeWhereBuild();
  503. }
  504. // callback for combo box menu where source selection
  505. void CMakeSetupDialog::OnSelendokWhereSource()
  506. {
  507. m_WhereSourceControl.GetLBText(m_WhereSourceControl.GetCurSel(),
  508. m_WhereSource);
  509. this->UpdateData(FALSE);
  510. this->OnChangeWhereSource();
  511. }
  512. // callback for chaing source directory
  513. void CMakeSetupDialog::OnChangeWhereSource()
  514. {
  515. }
  516. // callback for changing the build directory
  517. void CMakeSetupDialog::OnChangeWhereBuild()
  518. {
  519. this->UpdateData();
  520. m_CacheEntriesList.RemoveAll();
  521. m_CacheEntriesList.ShowWindow(SW_SHOW);
  522. this->LoadCacheFromDiskToGUI();
  523. m_BuildPathChanged = true;
  524. }
  525. // copy from the cache manager to the cache edit list box
  526. void CMakeSetupDialog::FillCacheGUIFromCacheManager()
  527. {
  528. int size = m_CacheEntriesList.GetItems().size();
  529. bool reverseOrder = false;
  530. // if there are already entries in the cache, then
  531. // put the new ones in the top, so they show up first
  532. if(size)
  533. {
  534. reverseOrder = true;
  535. }
  536. // all the current values are not new any more
  537. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  538. for(std::set<CPropertyItem*>::iterator i = items.begin();
  539. i != items.end(); ++i)
  540. {
  541. CPropertyItem* item = *i;
  542. item->m_NewValue = false;
  543. }
  544. const cmCacheManager::CacheEntryMap &cache =
  545. cmCacheManager::GetInstance()->GetCacheMap();
  546. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  547. i != cache.end(); ++i)
  548. {
  549. const char* key = i->first.c_str();
  550. cmCacheManager::CacheEntry value = i->second;
  551. // if value has trailing space or tab, enclose it in single quotes
  552. // to enforce the fact that it has 'invisible' trailing stuff
  553. if (value.m_Value.size() &&
  554. (value.m_Value[value.m_Value.size() - 1] == ' ' ||
  555. value.m_Value[value.m_Value.size() - 1] == '\t'))
  556. {
  557. value.m_Value = '\'' + value.m_Value + '\'';
  558. }
  559. if(!m_AdvancedValues)
  560. {
  561. std::string advancedVar = key;
  562. advancedVar += "-ADVANCED";
  563. if(cmCacheManager::GetInstance()->GetCacheEntry(advancedVar.c_str()))
  564. {
  565. continue;
  566. }
  567. }
  568. switch(value.m_Type )
  569. {
  570. case cmCacheManager::BOOL:
  571. if(cmSystemTools::IsOn(value.m_Value.c_str()))
  572. {
  573. m_CacheEntriesList.AddProperty(key,
  574. "ON",
  575. value.m_HelpString.c_str(),
  576. CPropertyList::COMBO,"ON|OFF",
  577. reverseOrder
  578. );
  579. }
  580. else
  581. {
  582. m_CacheEntriesList.AddProperty(key,
  583. "OFF",
  584. value.m_HelpString.c_str(),
  585. CPropertyList::COMBO,"ON|OFF",
  586. reverseOrder
  587. );
  588. }
  589. break;
  590. case cmCacheManager::PATH:
  591. m_CacheEntriesList.AddProperty(key,
  592. value.m_Value.c_str(),
  593. value.m_HelpString.c_str(),
  594. CPropertyList::PATH,"",
  595. reverseOrder
  596. );
  597. break;
  598. case cmCacheManager::FILEPATH:
  599. m_CacheEntriesList.AddProperty(key,
  600. value.m_Value.c_str(),
  601. value.m_HelpString.c_str(),
  602. CPropertyList::FILE,"",
  603. reverseOrder
  604. );
  605. break;
  606. case cmCacheManager::STRING:
  607. m_CacheEntriesList.AddProperty(key,
  608. value.m_Value.c_str(),
  609. value.m_HelpString.c_str(),
  610. CPropertyList::EDIT,"",
  611. reverseOrder
  612. );
  613. break;
  614. case cmCacheManager::INTERNAL:
  615. m_CacheEntriesList.RemoveProperty(key);
  616. break;
  617. }
  618. }
  619. m_OKButton.EnableWindow(false);
  620. if(cache.size() > 0 && !cmSystemTools::GetErrorOccuredFlag())
  621. {
  622. bool enable = true;
  623. items = m_CacheEntriesList.GetItems();
  624. for(std::set<CPropertyItem*>::iterator i = items.begin();
  625. i != items.end(); ++i)
  626. {
  627. CPropertyItem* item = *i;
  628. if(item->m_NewValue)
  629. {
  630. // if one new value then disable to OK button
  631. enable = false;
  632. break;
  633. }
  634. }
  635. if(enable)
  636. {
  637. m_OKButton.EnableWindow(true);
  638. }
  639. }
  640. // redraw the list
  641. m_CacheEntriesList.SetTopIndex(0);
  642. m_CacheEntriesList.Invalidate();
  643. }
  644. // copy from the list box to the cache manager
  645. void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
  646. {
  647. cmCacheManager::GetInstance()->GetCacheMap();
  648. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  649. for(std::set<CPropertyItem*>::iterator i = items.begin();
  650. i != items.end(); ++i)
  651. {
  652. CPropertyItem* item = *i;
  653. cmCacheManager::CacheEntry *entry =
  654. cmCacheManager::GetInstance()->GetCacheEntry(
  655. (const char*)item->m_propName);
  656. if (entry)
  657. {
  658. // if value is enclosed in single quotes ('foo') then remove them
  659. // they were used to enforce the fact that it had 'invisible'
  660. // trailing stuff
  661. if (item->m_curValue.GetLength() >= 2 &&
  662. item->m_curValue[0] == '\'' &&
  663. item->m_curValue[item->m_curValue.GetLength() - 1] == '\'')
  664. {
  665. entry->m_Value = item->m_curValue.Mid(1,
  666. item->m_curValue.GetLength() - 2);
  667. }
  668. else
  669. {
  670. entry->m_Value = item->m_curValue;
  671. }
  672. }
  673. }
  674. }
  675. //! Load cache file from m_WhereBuild and display in GUI editor
  676. void CMakeSetupDialog::LoadCacheFromDiskToGUI()
  677. {
  678. if(m_WhereBuild != "")
  679. {
  680. cmCacheManager::GetInstance()->LoadCache(m_WhereBuild);
  681. this->FillCacheGUIFromCacheManager();
  682. if(cmCacheManager::GetInstance()->GetCacheEntry("CMAKE_GENERATOR"))
  683. {
  684. std::string curGen =
  685. cmCacheManager::GetInstance()->GetCacheEntry("CMAKE_GENERATOR")->m_Value;
  686. if(m_GeneratorChoiceString != curGen.c_str())
  687. {
  688. m_GeneratorChoiceString = curGen.c_str();
  689. this->UpdateData(FALSE);
  690. }
  691. }
  692. }
  693. }
  694. //! Save GUI values to cmCacheManager and then save to disk.
  695. void CMakeSetupDialog::SaveCacheFromGUI()
  696. {
  697. this->FillCacheManagerFromCacheGUI();
  698. if(m_WhereBuild != "")
  699. {
  700. cmCacheManager::GetInstance()->SaveCache(m_WhereBuild);
  701. }
  702. }
  703. void CMakeSetupDialog::OnSize(UINT nType, int cx, int cy)
  704. {
  705. if (nType == SIZE_MINIMIZED)
  706. {
  707. CDialog::OnSize(nType, cx, cy);
  708. return;
  709. }
  710. if (m_oldCX == -1)
  711. {
  712. m_oldCX = cx;
  713. m_oldCY = cy;
  714. }
  715. int deltax = cx - m_oldCX;
  716. int deltay = cy - m_oldCY;
  717. m_oldCX = cx;
  718. m_oldCY = cy;
  719. CDialog::OnSize(nType, cx, cy);
  720. if (deltax == 0 && deltay == 0)
  721. {
  722. return;
  723. }
  724. if(m_CacheEntriesList.m_hWnd)
  725. {
  726. // get the original sizes/positions
  727. CRect cRect;
  728. m_ListFrame.GetWindowRect(&cRect);
  729. m_ListFrame.SetWindowPos(&wndTop, cRect.left, cRect.top,
  730. cRect.Width() + deltax,
  731. cRect.Height() + deltay,
  732. SWP_NOMOVE | SWP_NOZORDER);
  733. m_CacheEntriesList.GetWindowRect(&cRect);
  734. m_CacheEntriesList.SetWindowPos(&wndTop, cRect.left, cRect.top,
  735. cRect.Width() + deltax,
  736. cRect.Height() + deltay,
  737. SWP_NOMOVE | SWP_NOZORDER);
  738. m_VersionDisplay.SetWindowPos(&wndTop, 5, cy-23, 0, 0,
  739. SWP_NOSIZE | SWP_NOZORDER);
  740. deltax = deltax + m_deltaXRemainder;
  741. m_deltaXRemainder = deltax%2;
  742. m_MouseHelp.GetWindowRect(&cRect);
  743. this->ScreenToClient(&cRect);
  744. m_MouseHelp.SetWindowPos(&wndTop, cRect.left + deltax/2,
  745. cRect.top + deltay,
  746. 0, 0,
  747. SWP_NOSIZE | SWP_NOZORDER);
  748. m_Configure.GetWindowRect(&cRect);
  749. this->ScreenToClient(&cRect);
  750. m_Configure.SetWindowPos(&wndTop, cRect.left + deltax/2,
  751. cRect.top + deltay,
  752. 0, 0,
  753. SWP_NOSIZE | SWP_NOZORDER);
  754. m_CancelButton.GetWindowRect(&cRect);
  755. this->ScreenToClient(&cRect);
  756. m_CancelButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  757. cRect.top + deltay,
  758. 0, 0,
  759. SWP_NOSIZE | SWP_NOZORDER);
  760. m_OKButton.GetWindowRect(&cRect);
  761. this->ScreenToClient(&cRect);
  762. m_OKButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  763. cRect.top + deltay,
  764. 0, 0,
  765. SWP_NOSIZE | SWP_NOZORDER);
  766. m_HelpButton.GetWindowRect(&cRect);
  767. this->ScreenToClient(&cRect);
  768. m_HelpButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  769. cRect.top + deltay,
  770. 0, 0,
  771. SWP_NOSIZE | SWP_NOZORDER);
  772. }
  773. }
  774. void CMakeSetupDialog::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
  775. {
  776. lpMMI->ptMinTrackSize.x = 550;
  777. lpMMI->ptMinTrackSize.y = 272;
  778. }
  779. void CMakeSetupDialog::OnCancel()
  780. {
  781. if(m_CacheEntriesList.IsDirty())
  782. {
  783. if(MessageBox("You have changed options but not rebuilt, "
  784. "are you sure you want to exit?", "Confirm Exit",
  785. MB_YESNO) == IDYES)
  786. {
  787. CDialog::OnOK();
  788. }
  789. }
  790. else
  791. {
  792. CDialog::OnOK();
  793. }
  794. }
  795. void CMakeSetupDialog::OnOk()
  796. {
  797. // enable error messages each time configure is pressed
  798. cmSystemTools::EnableMessages();
  799. m_CacheEntriesList.ClearDirty();
  800. this->RunCMake(true);
  801. cmMakefileGenerator::UnRegisterGenerators();
  802. if (!(::GetKeyState(VK_SHIFT) & 0x1000))
  803. {
  804. CDialog::OnOK();
  805. }
  806. }
  807. void CMakeSetupDialog::OnEditchangeGenerator()
  808. {
  809. // TODO: Add your control notification handler code here
  810. }
  811. // Create a shortcut on the desktop with the current Source/Build dir.
  812. int CMakeSetupDialog::CreateShortcut()
  813. {
  814. // m_WhereSource = cmdInfo.m_WhereSource;
  815. // m_WhereBuild = cmdInfo.m_WhereBuild;
  816. // Find the desktop folder and create the link name
  817. HKEY hKey;
  818. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  819. "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
  820. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  821. {
  822. AfxMessageBox ("Create shortcut: unable to find 'Shell Folders' key in registry!");
  823. return 1;
  824. }
  825. DWORD dwType, dwSize;
  826. #define MAXPATH 1024
  827. char link_name[MAXPATH];
  828. dwSize = MAXPATH;
  829. if(RegQueryValueEx(hKey,
  830. (LPCTSTR)"Desktop",
  831. NULL,
  832. &dwType,
  833. (BYTE *)link_name,
  834. &dwSize) != ERROR_SUCCESS)
  835. {
  836. AfxMessageBox ("Create shortcut: unable to find 'Desktop' registry value in 'Shell Folders' key!");
  837. return 1;
  838. }
  839. if(dwType != REG_SZ)
  840. {
  841. AfxMessageBox ("Create shortcut: 'Desktop' registry value in 'Shell Folders' key has wrong type!");
  842. return 1;
  843. }
  844. strcat(link_name, "\\CMake - ");
  845. std::string current_dir = cmSystemTools::GetFilenameName((LPCTSTR)m_WhereSource);
  846. strcat(link_name, current_dir.c_str());
  847. strcat(link_name, ".lnk");
  848. // Find the path to the current executable
  849. char path_to_current_exe[MAXPATH];
  850. ::GetModuleFileName(NULL, path_to_current_exe, MAXPATH);
  851. // Create the shortcut
  852. HRESULT hres;
  853. IShellLink *psl;
  854. // Initialize the COM library
  855. hres = CoInitialize(NULL);
  856. if (! SUCCEEDED (hres))
  857. {
  858. AfxMessageBox ("Create shortcut: unable to initialize the COM library!");
  859. return 1;
  860. }
  861. // Create an IShellLink object and get a pointer to the IShellLink
  862. // interface (returned from CoCreateInstance).
  863. hres = CoCreateInstance(CLSID_ShellLink,
  864. NULL,
  865. CLSCTX_INPROC_SERVER,
  866. IID_IShellLink,
  867. (void **)&psl);
  868. if (! SUCCEEDED (hres))
  869. {
  870. AfxMessageBox ("Create shortcut: unable to create IShellLink instance!");
  871. return 1;
  872. }
  873. IPersistFile *ppf;
  874. // Query IShellLink for the IPersistFile interface for
  875. // saving the shortcut in persistent storage.
  876. hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
  877. if (SUCCEEDED (hres))
  878. {
  879. // Set the path to the shortcut target.
  880. hres = psl->SetPath(path_to_current_exe);
  881. if (! SUCCEEDED (hres))
  882. {
  883. AfxMessageBox ("Create shortcut: SetPath failed!");
  884. }
  885. // Set the arguments of the shortcut.
  886. CString args = " /H=\"" + m_WhereSource + "\" /B=\"" + m_WhereBuild + "\" /G=\"" + m_GeneratorChoiceString + "\" /A=\"" + (m_AdvancedValues ? "TRUE" : "FALSE") + "\"";
  887. hres = psl->SetArguments(args);
  888. if (! SUCCEEDED (hres))
  889. {
  890. AfxMessageBox ("Create shortcut: SetArguments failed!");
  891. }
  892. // Set the description of the shortcut.
  893. hres = psl->SetDescription("Shortcut to CMakeSetup");
  894. if (! SUCCEEDED (hres))
  895. {
  896. AfxMessageBox ("Create shortcut: SetDescription failed!");
  897. }
  898. // Ensure that the string consists of ANSI characters.
  899. WORD wsz[MAX_PATH];
  900. MultiByteToWideChar(CP_ACP, 0, link_name, -1, wsz, MAX_PATH);
  901. // Save the shortcut via the IPersistFile::Save member function.
  902. hres = ppf->Save(wsz, TRUE);
  903. if (! SUCCEEDED (hres))
  904. {
  905. AfxMessageBox ("Create shortcut: Save failed!");
  906. }
  907. // Release the pointer to IPersistFile.
  908. ppf->Release ();
  909. }
  910. // Release the pointer to IShellLink.
  911. psl->Release ();
  912. return 0;
  913. }
  914. void CMakeSetupDialog::OnHelpButton()
  915. {
  916. CMakeHelp dialog;
  917. dialog.DoModal();
  918. }
  919. void CMakeSetupDialog::ShowAdvancedValues()
  920. {
  921. const cmCacheManager::CacheEntryMap &cache =
  922. cmCacheManager::GetInstance()->GetCacheMap();
  923. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  924. i != cache.end(); ++i)
  925. {
  926. const char* key = i->first.c_str();
  927. const cmCacheManager::CacheEntry& value = i->second;
  928. if(!cmCacheManager::GetInstance()->IsAdvanced(key))
  929. {
  930. continue;
  931. }
  932. switch(value.m_Type )
  933. {
  934. case cmCacheManager::BOOL:
  935. if(cmSystemTools::IsOn(value.m_Value.c_str()))
  936. {
  937. m_CacheEntriesList.AddProperty(key,
  938. "ON",
  939. value.m_HelpString.c_str(),
  940. CPropertyList::COMBO,"ON|OFF",
  941. true
  942. );
  943. }
  944. else
  945. {
  946. m_CacheEntriesList.AddProperty(key,
  947. "OFF",
  948. value.m_HelpString.c_str(),
  949. CPropertyList::COMBO,"ON|OFF",
  950. true
  951. );
  952. }
  953. break;
  954. case cmCacheManager::PATH:
  955. m_CacheEntriesList.AddProperty(key,
  956. value.m_Value.c_str(),
  957. value.m_HelpString.c_str(),
  958. CPropertyList::PATH,"",
  959. true
  960. );
  961. break;
  962. case cmCacheManager::FILEPATH:
  963. m_CacheEntriesList.AddProperty(key,
  964. value.m_Value.c_str(),
  965. value.m_HelpString.c_str(),
  966. CPropertyList::FILE,"",
  967. true
  968. );
  969. break;
  970. case cmCacheManager::STRING:
  971. m_CacheEntriesList.AddProperty(key,
  972. value.m_Value.c_str(),
  973. value.m_HelpString.c_str(),
  974. CPropertyList::EDIT,"",
  975. true
  976. );
  977. break;
  978. case cmCacheManager::INTERNAL:
  979. m_CacheEntriesList.RemoveProperty(key);
  980. break;
  981. }
  982. }
  983. }
  984. void CMakeSetupDialog::RemoveAdvancedValues()
  985. {
  986. const cmCacheManager::CacheEntryMap &cache =
  987. cmCacheManager::GetInstance()->GetCacheMap();
  988. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  989. i != cache.end(); ++i)
  990. {
  991. const char* key = i->first.c_str();
  992. const cmCacheManager::CacheEntry& value = i->second;
  993. if(cmCacheManager::GetInstance()->IsAdvanced(key))
  994. {
  995. m_CacheEntriesList.RemoveProperty(key);
  996. }
  997. }
  998. }
  999. void CMakeSetupDialog::OnAdvancedValues()
  1000. {
  1001. this->UpdateData();
  1002. if(m_AdvancedValues)
  1003. {
  1004. this->ShowAdvancedValues();
  1005. }
  1006. else
  1007. {
  1008. this->RemoveAdvancedValues();
  1009. }
  1010. }
  1011. void CMakeSetupDialog::OnDoubleclickedAdvancedValues()
  1012. {
  1013. this->OnAdvancedValues();
  1014. }