CMakeSetupDialog.cpp 33 KB

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