CMakeSetupDialog.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  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. if(cmCacheManager::GetInstance()->IsAdvanced(key))
  562. {
  563. m_CacheEntriesList.RemoveProperty(key);
  564. continue;
  565. }
  566. }
  567. switch(value.m_Type )
  568. {
  569. case cmCacheManager::BOOL:
  570. if(cmSystemTools::IsOn(value.m_Value.c_str()))
  571. {
  572. m_CacheEntriesList.AddProperty(key,
  573. "ON",
  574. value.m_HelpString.c_str(),
  575. CPropertyList::COMBO,"ON|OFF",
  576. reverseOrder
  577. );
  578. }
  579. else
  580. {
  581. m_CacheEntriesList.AddProperty(key,
  582. "OFF",
  583. value.m_HelpString.c_str(),
  584. CPropertyList::COMBO,"ON|OFF",
  585. reverseOrder
  586. );
  587. }
  588. break;
  589. case cmCacheManager::PATH:
  590. m_CacheEntriesList.AddProperty(key,
  591. value.m_Value.c_str(),
  592. value.m_HelpString.c_str(),
  593. CPropertyList::PATH,"",
  594. reverseOrder
  595. );
  596. break;
  597. case cmCacheManager::FILEPATH:
  598. m_CacheEntriesList.AddProperty(key,
  599. value.m_Value.c_str(),
  600. value.m_HelpString.c_str(),
  601. CPropertyList::FILE,"",
  602. reverseOrder
  603. );
  604. break;
  605. case cmCacheManager::STRING:
  606. m_CacheEntriesList.AddProperty(key,
  607. value.m_Value.c_str(),
  608. value.m_HelpString.c_str(),
  609. CPropertyList::EDIT,"",
  610. reverseOrder
  611. );
  612. break;
  613. case cmCacheManager::INTERNAL:
  614. m_CacheEntriesList.RemoveProperty(key);
  615. break;
  616. }
  617. }
  618. m_OKButton.EnableWindow(false);
  619. if(cache.size() > 0 && !cmSystemTools::GetErrorOccuredFlag())
  620. {
  621. bool enable = true;
  622. items = m_CacheEntriesList.GetItems();
  623. for(std::set<CPropertyItem*>::iterator i = items.begin();
  624. i != items.end(); ++i)
  625. {
  626. CPropertyItem* item = *i;
  627. if(item->m_NewValue)
  628. {
  629. // if one new value then disable to OK button
  630. enable = false;
  631. break;
  632. }
  633. }
  634. if(enable)
  635. {
  636. m_OKButton.EnableWindow(true);
  637. }
  638. }
  639. // redraw the list
  640. m_CacheEntriesList.SetTopIndex(0);
  641. m_CacheEntriesList.Invalidate();
  642. }
  643. // copy from the list box to the cache manager
  644. void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
  645. {
  646. cmCacheManager::GetInstance()->GetCacheMap();
  647. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  648. for(std::set<CPropertyItem*>::iterator i = items.begin();
  649. i != items.end(); ++i)
  650. {
  651. CPropertyItem* item = *i;
  652. cmCacheManager::CacheEntry *entry =
  653. cmCacheManager::GetInstance()->GetCacheEntry(
  654. (const char*)item->m_propName);
  655. if (entry)
  656. {
  657. // if value is enclosed in single quotes ('foo') then remove them
  658. // they were used to enforce the fact that it had 'invisible'
  659. // trailing stuff
  660. if (item->m_curValue.GetLength() >= 2 &&
  661. item->m_curValue[0] == '\'' &&
  662. item->m_curValue[item->m_curValue.GetLength() - 1] == '\'')
  663. {
  664. entry->m_Value = item->m_curValue.Mid(1,
  665. item->m_curValue.GetLength() - 2);
  666. }
  667. else
  668. {
  669. entry->m_Value = item->m_curValue;
  670. }
  671. }
  672. }
  673. }
  674. //! Load cache file from m_WhereBuild and display in GUI editor
  675. void CMakeSetupDialog::LoadCacheFromDiskToGUI()
  676. {
  677. if(m_WhereBuild != "")
  678. {
  679. cmCacheManager::GetInstance()->LoadCache(m_WhereBuild);
  680. this->FillCacheGUIFromCacheManager();
  681. if(cmCacheManager::GetInstance()->GetCacheEntry("CMAKE_GENERATOR"))
  682. {
  683. std::string curGen =
  684. cmCacheManager::GetInstance()->GetCacheEntry("CMAKE_GENERATOR")->m_Value;
  685. if(m_GeneratorChoiceString != curGen.c_str())
  686. {
  687. m_GeneratorChoiceString = curGen.c_str();
  688. this->UpdateData(FALSE);
  689. }
  690. }
  691. }
  692. }
  693. //! Save GUI values to cmCacheManager and then save to disk.
  694. void CMakeSetupDialog::SaveCacheFromGUI()
  695. {
  696. this->FillCacheManagerFromCacheGUI();
  697. if(m_WhereBuild != "")
  698. {
  699. cmCacheManager::GetInstance()->SaveCache(m_WhereBuild);
  700. }
  701. }
  702. void CMakeSetupDialog::OnSize(UINT nType, int cx, int cy)
  703. {
  704. if (nType == SIZE_MINIMIZED)
  705. {
  706. CDialog::OnSize(nType, cx, cy);
  707. return;
  708. }
  709. if (m_oldCX == -1)
  710. {
  711. m_oldCX = cx;
  712. m_oldCY = cy;
  713. }
  714. int deltax = cx - m_oldCX;
  715. int deltay = cy - m_oldCY;
  716. m_oldCX = cx;
  717. m_oldCY = cy;
  718. CDialog::OnSize(nType, cx, cy);
  719. if (deltax == 0 && deltay == 0)
  720. {
  721. return;
  722. }
  723. if(m_CacheEntriesList.m_hWnd)
  724. {
  725. // get the original sizes/positions
  726. CRect cRect;
  727. m_ListFrame.GetWindowRect(&cRect);
  728. m_ListFrame.SetWindowPos(&wndTop, cRect.left, cRect.top,
  729. cRect.Width() + deltax,
  730. cRect.Height() + deltay,
  731. SWP_NOMOVE | SWP_NOZORDER);
  732. m_CacheEntriesList.GetWindowRect(&cRect);
  733. m_CacheEntriesList.SetWindowPos(&wndTop, cRect.left, cRect.top,
  734. cRect.Width() + deltax,
  735. cRect.Height() + deltay,
  736. SWP_NOMOVE | SWP_NOZORDER);
  737. m_VersionDisplay.SetWindowPos(&wndTop, 5, cy-23, 0, 0,
  738. SWP_NOSIZE | SWP_NOZORDER);
  739. deltax = deltax + m_deltaXRemainder;
  740. m_deltaXRemainder = deltax%2;
  741. m_MouseHelp.GetWindowRect(&cRect);
  742. this->ScreenToClient(&cRect);
  743. m_MouseHelp.SetWindowPos(&wndTop, cRect.left + deltax/2,
  744. cRect.top + deltay,
  745. 0, 0,
  746. SWP_NOSIZE | SWP_NOZORDER);
  747. m_Configure.GetWindowRect(&cRect);
  748. this->ScreenToClient(&cRect);
  749. m_Configure.SetWindowPos(&wndTop, cRect.left + deltax/2,
  750. cRect.top + deltay,
  751. 0, 0,
  752. SWP_NOSIZE | SWP_NOZORDER);
  753. m_CancelButton.GetWindowRect(&cRect);
  754. this->ScreenToClient(&cRect);
  755. m_CancelButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  756. cRect.top + deltay,
  757. 0, 0,
  758. SWP_NOSIZE | SWP_NOZORDER);
  759. m_OKButton.GetWindowRect(&cRect);
  760. this->ScreenToClient(&cRect);
  761. m_OKButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  762. cRect.top + deltay,
  763. 0, 0,
  764. SWP_NOSIZE | SWP_NOZORDER);
  765. m_HelpButton.GetWindowRect(&cRect);
  766. this->ScreenToClient(&cRect);
  767. m_HelpButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  768. cRect.top + deltay,
  769. 0, 0,
  770. SWP_NOSIZE | SWP_NOZORDER);
  771. }
  772. }
  773. void CMakeSetupDialog::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
  774. {
  775. lpMMI->ptMinTrackSize.x = 550;
  776. lpMMI->ptMinTrackSize.y = 272;
  777. }
  778. void CMakeSetupDialog::OnCancel()
  779. {
  780. if(m_CacheEntriesList.IsDirty())
  781. {
  782. if(MessageBox("You have changed options but not rebuilt, "
  783. "are you sure you want to exit?", "Confirm Exit",
  784. MB_YESNO) == IDYES)
  785. {
  786. CDialog::OnOK();
  787. }
  788. }
  789. else
  790. {
  791. CDialog::OnOK();
  792. }
  793. }
  794. void CMakeSetupDialog::OnOk()
  795. {
  796. // enable error messages each time configure is pressed
  797. cmSystemTools::EnableMessages();
  798. m_CacheEntriesList.ClearDirty();
  799. this->RunCMake(true);
  800. cmMakefileGenerator::UnRegisterGenerators();
  801. if (!(::GetKeyState(VK_SHIFT) & 0x1000))
  802. {
  803. CDialog::OnOK();
  804. }
  805. }
  806. void CMakeSetupDialog::OnEditchangeGenerator()
  807. {
  808. // TODO: Add your control notification handler code here
  809. }
  810. // Create a shortcut on the desktop with the current Source/Build dir.
  811. int CMakeSetupDialog::CreateShortcut()
  812. {
  813. // m_WhereSource = cmdInfo.m_WhereSource;
  814. // m_WhereBuild = cmdInfo.m_WhereBuild;
  815. // Find the desktop folder and create the link name
  816. HKEY hKey;
  817. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  818. "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
  819. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  820. {
  821. AfxMessageBox ("Create shortcut: unable to find 'Shell Folders' key in registry!");
  822. return 1;
  823. }
  824. DWORD dwType, dwSize;
  825. #define MAXPATH 1024
  826. char link_name[MAXPATH];
  827. dwSize = MAXPATH;
  828. if(RegQueryValueEx(hKey,
  829. (LPCTSTR)"Desktop",
  830. NULL,
  831. &dwType,
  832. (BYTE *)link_name,
  833. &dwSize) != ERROR_SUCCESS)
  834. {
  835. AfxMessageBox ("Create shortcut: unable to find 'Desktop' registry value in 'Shell Folders' key!");
  836. return 1;
  837. }
  838. if(dwType != REG_SZ)
  839. {
  840. AfxMessageBox ("Create shortcut: 'Desktop' registry value in 'Shell Folders' key has wrong type!");
  841. return 1;
  842. }
  843. strcat(link_name, "\\CMake - ");
  844. std::string current_dir = cmSystemTools::GetFilenameName((LPCTSTR)m_WhereSource);
  845. strcat(link_name, current_dir.c_str());
  846. strcat(link_name, ".lnk");
  847. // Find the path to the current executable
  848. char path_to_current_exe[MAXPATH];
  849. ::GetModuleFileName(NULL, path_to_current_exe, MAXPATH);
  850. // Create the shortcut
  851. HRESULT hres;
  852. IShellLink *psl;
  853. // Initialize the COM library
  854. hres = CoInitialize(NULL);
  855. if (! SUCCEEDED (hres))
  856. {
  857. AfxMessageBox ("Create shortcut: unable to initialize the COM library!");
  858. return 1;
  859. }
  860. // Create an IShellLink object and get a pointer to the IShellLink
  861. // interface (returned from CoCreateInstance).
  862. hres = CoCreateInstance(CLSID_ShellLink,
  863. NULL,
  864. CLSCTX_INPROC_SERVER,
  865. IID_IShellLink,
  866. (void **)&psl);
  867. if (! SUCCEEDED (hres))
  868. {
  869. AfxMessageBox ("Create shortcut: unable to create IShellLink instance!");
  870. return 1;
  871. }
  872. IPersistFile *ppf;
  873. // Query IShellLink for the IPersistFile interface for
  874. // saving the shortcut in persistent storage.
  875. hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
  876. if (SUCCEEDED (hres))
  877. {
  878. // Set the path to the shortcut target.
  879. hres = psl->SetPath(path_to_current_exe);
  880. if (! SUCCEEDED (hres))
  881. {
  882. AfxMessageBox ("Create shortcut: SetPath failed!");
  883. }
  884. // Set the arguments of the shortcut.
  885. CString args = " /H=\"" + m_WhereSource + "\" /B=\"" + m_WhereBuild + "\" /G=\"" + m_GeneratorChoiceString + "\" /A=\"" + (m_AdvancedValues ? "TRUE" : "FALSE") + "\"";
  886. hres = psl->SetArguments(args);
  887. if (! SUCCEEDED (hres))
  888. {
  889. AfxMessageBox ("Create shortcut: SetArguments failed!");
  890. }
  891. // Set the description of the shortcut.
  892. hres = psl->SetDescription("Shortcut to CMakeSetup");
  893. if (! SUCCEEDED (hres))
  894. {
  895. AfxMessageBox ("Create shortcut: SetDescription failed!");
  896. }
  897. // Ensure that the string consists of ANSI characters.
  898. WORD wsz[MAX_PATH];
  899. MultiByteToWideChar(CP_ACP, 0, link_name, -1, wsz, MAX_PATH);
  900. // Save the shortcut via the IPersistFile::Save member function.
  901. hres = ppf->Save(wsz, TRUE);
  902. if (! SUCCEEDED (hres))
  903. {
  904. AfxMessageBox ("Create shortcut: Save failed!");
  905. }
  906. // Release the pointer to IPersistFile.
  907. ppf->Release ();
  908. }
  909. // Release the pointer to IShellLink.
  910. psl->Release ();
  911. return 0;
  912. }
  913. void CMakeSetupDialog::OnHelpButton()
  914. {
  915. CMakeHelp dialog;
  916. dialog.DoModal();
  917. }
  918. void CMakeSetupDialog::ShowAdvancedValues()
  919. {
  920. const cmCacheManager::CacheEntryMap &cache =
  921. cmCacheManager::GetInstance()->GetCacheMap();
  922. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  923. i != cache.end(); ++i)
  924. {
  925. const char* key = i->first.c_str();
  926. const cmCacheManager::CacheEntry& value = i->second;
  927. if(!cmCacheManager::GetInstance()->IsAdvanced(key))
  928. {
  929. continue;
  930. }
  931. switch(value.m_Type )
  932. {
  933. case cmCacheManager::BOOL:
  934. if(cmSystemTools::IsOn(value.m_Value.c_str()))
  935. {
  936. m_CacheEntriesList.AddProperty(key,
  937. "ON",
  938. value.m_HelpString.c_str(),
  939. CPropertyList::COMBO,"ON|OFF",
  940. true
  941. );
  942. }
  943. else
  944. {
  945. m_CacheEntriesList.AddProperty(key,
  946. "OFF",
  947. value.m_HelpString.c_str(),
  948. CPropertyList::COMBO,"ON|OFF",
  949. true
  950. );
  951. }
  952. break;
  953. case cmCacheManager::PATH:
  954. m_CacheEntriesList.AddProperty(key,
  955. value.m_Value.c_str(),
  956. value.m_HelpString.c_str(),
  957. CPropertyList::PATH,"",
  958. true
  959. );
  960. break;
  961. case cmCacheManager::FILEPATH:
  962. m_CacheEntriesList.AddProperty(key,
  963. value.m_Value.c_str(),
  964. value.m_HelpString.c_str(),
  965. CPropertyList::FILE,"",
  966. true
  967. );
  968. break;
  969. case cmCacheManager::STRING:
  970. m_CacheEntriesList.AddProperty(key,
  971. value.m_Value.c_str(),
  972. value.m_HelpString.c_str(),
  973. CPropertyList::EDIT,"",
  974. true
  975. );
  976. break;
  977. case cmCacheManager::INTERNAL:
  978. m_CacheEntriesList.RemoveProperty(key);
  979. break;
  980. }
  981. }
  982. }
  983. void CMakeSetupDialog::RemoveAdvancedValues()
  984. {
  985. const cmCacheManager::CacheEntryMap &cache =
  986. cmCacheManager::GetInstance()->GetCacheMap();
  987. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  988. i != cache.end(); ++i)
  989. {
  990. const char* key = i->first.c_str();
  991. const cmCacheManager::CacheEntry& value = i->second;
  992. if(cmCacheManager::GetInstance()->IsAdvanced(key))
  993. {
  994. m_CacheEntriesList.RemoveProperty(key);
  995. }
  996. }
  997. }
  998. void CMakeSetupDialog::OnAdvancedValues()
  999. {
  1000. this->UpdateData();
  1001. if(m_AdvancedValues)
  1002. {
  1003. this->ShowAdvancedValues();
  1004. }
  1005. else
  1006. {
  1007. this->RemoveAdvancedValues();
  1008. }
  1009. }
  1010. void CMakeSetupDialog::OnDoubleclickedAdvancedValues()
  1011. {
  1012. this->OnAdvancedValues();
  1013. }