CMakeSetupDialog.cpp 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550
  1. // pcbuilderdialogDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "shellapi.h"
  5. // a fun undef for DOT NET
  6. #undef DEBUG
  7. #include "CMakeSetup.h"
  8. #include "MakeHelp.h"
  9. #include "cmVersion.h"
  10. #include "PathDialog.h"
  11. #include "CMakeSetupDialog.h"
  12. #include "CMakeCommandLineInfo.h"
  13. #include "../cmExternalMakefileProjectGenerator.h"
  14. #include "../cmListFileCache.h"
  15. #include "../cmCacheManager.h"
  16. #include "../cmake.h"
  17. #include "../cmGlobalGenerator.h"
  18. #include "../cmDynamicLoader.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CAboutDlg dialog used for App About
  26. class CAboutDlg : public CDialog
  27. {
  28. public:
  29. CAboutDlg();
  30. // Dialog Data
  31. //{{AFX_DATA(CAboutDlg)
  32. enum { IDD = IDD_ABOUTBOX };
  33. //}}AFX_DATA
  34. // ClassWizard generated virtual function overrides
  35. //{{AFX_VIRTUAL(CAboutDlg)
  36. protected:
  37. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  38. //}}AFX_VIRTUAL
  39. // Implementation
  40. protected:
  41. //{{AFX_MSG(CAboutDlg)
  42. //}}AFX_MSG
  43. DECLARE_MESSAGE_MAP()
  44. };
  45. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  46. {
  47. //{{AFX_DATA_INIT(CAboutDlg)
  48. //}}AFX_DATA_INIT
  49. }
  50. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  51. {
  52. CDialog::DoDataExchange(pDX);
  53. //{{AFX_DATA_MAP(CAboutDlg)
  54. //}}AFX_DATA_MAP
  55. }
  56. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  57. //{{AFX_MSG_MAP(CAboutDlg)
  58. // No message handlers
  59. //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP();
  61. void MFCMessageCallback(const char* m, const char* title, bool& nomore, void*)
  62. {
  63. std::string message = m;
  64. message += "\n\n(Press Cancel to suppress any further messages.)";
  65. if(::MessageBox(0, message.c_str(), title,
  66. MB_OKCANCEL|MB_TASKMODAL) == IDCANCEL)
  67. {
  68. nomore = true;
  69. }
  70. }
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CMakeSetupDialog dialog
  73. void updateProgress(const char *msg, float prog, void *cd)
  74. {
  75. char* tmp = new char[strlen(msg) + 40];
  76. if (prog >= 0)
  77. {
  78. sprintf(tmp,"%s %i%%",msg,(int)(100*prog));
  79. }
  80. else
  81. {
  82. sprintf(tmp,"%s",msg);
  83. }
  84. CMakeSetupDialog *self = (CMakeSetupDialog *)cd;
  85. self->SetDlgItemText(IDC_PROGRESS, tmp);
  86. CWnd* cancel = self->GetDlgItem(IDCANCEL);
  87. //
  88. // Retrieve and dispatch any waiting messages.
  89. //
  90. MSG wmsg;
  91. while (::PeekMessage (&wmsg, NULL, 0, 0, PM_REMOVE))
  92. {
  93. switch(wmsg.message)
  94. {
  95. case WM_LBUTTONDOWN:
  96. case WM_LBUTTONUP:
  97. case WM_LBUTTONDBLCLK:
  98. {
  99. if(wmsg.hwnd == cancel->m_hWnd)
  100. {
  101. ::DispatchMessage(&wmsg);
  102. }
  103. }
  104. break;
  105. case WM_COMMAND:
  106. case WM_SETCURSOR:
  107. case WM_PAINT:
  108. ::DispatchMessage(&wmsg);
  109. break;
  110. }
  111. }
  112. delete [] tmp;
  113. }
  114. // Convert to Win32 path (slashes). This calls the system tools one and then
  115. // removes the spaces. It is not in system tools because we don't want any
  116. // generators accidentally use it
  117. std::string ConvertToWindowsPath(const char* path)
  118. {
  119. // Convert to output path.
  120. // Remove the "" around it (if any) since it's an output path for
  121. // the shell. If another shell-oriented feature is not designed
  122. // for a GUI use, then we are in trouble.
  123. // save the value of the force to unix path option
  124. bool saveForce = cmSystemTools::GetForceUnixPaths();
  125. // make sure we get windows paths no matter what for the GUI
  126. cmSystemTools::SetForceUnixPaths(false);
  127. std::string s = cmSystemTools::ConvertToOutputPath(path);
  128. // now restore the force unix path to its previous value
  129. cmSystemTools::SetForceUnixPaths(saveForce);
  130. if (s.size())
  131. {
  132. std::string::iterator i = s.begin();
  133. if (*i == '\"')
  134. {
  135. s.erase(i, i + 1);
  136. }
  137. i = s.begin() + s.length() - 1;
  138. if (*i == '\"')
  139. {
  140. s.erase(i, i + 1);
  141. }
  142. }
  143. return s;
  144. }
  145. CMakeSetupDialog::CMakeSetupDialog(const CMakeCommandLineInfo& cmdInfo,
  146. CWnd* pParent /*=NULL*/)
  147. : CDialog(CMakeSetupDialog::IDD, pParent)
  148. {
  149. m_GeneratorPicked = false;
  150. m_Cursor = LoadCursor(NULL, IDC_ARROW);
  151. m_RunningConfigure = false;
  152. cmSystemTools::SetRunCommandHideConsole(true);
  153. cmSystemTools::SetErrorCallback(MFCMessageCallback);
  154. m_RegistryKey = "Software\\Kitware\\CMakeSetup\\Settings\\StartPath";
  155. m_CacheEntriesList.m_CMakeSetupDialog = this;
  156. m_CMakeInstance = new cmake;
  157. m_CMakeInstance->SetCMakeEditCommand("CMakeSetup");
  158. m_CMakeInstance->SetProgressCallback(updateProgress, (void *)this);
  159. //{{AFX_DATA_INIT(CMakeSetupDialog)
  160. //}}AFX_DATA_INIT
  161. // Get the parameters from the command line info
  162. // If an unknown parameter is found, try to interpret it too, since it
  163. // is likely to be a file dropped on the shortcut :)
  164. if (cmdInfo.m_LastUnknownParameter.IsEmpty())
  165. {
  166. this->m_WhereSource = cmdInfo.m_WhereSource;
  167. this->m_WhereBuild = cmdInfo.m_WhereBuild;
  168. this->m_GeneratorDialog.m_GeneratorChoiceString =
  169. cmdInfo.m_GeneratorChoiceString;
  170. this->m_AdvancedValues = cmdInfo.m_AdvancedValues;
  171. }
  172. else
  173. {
  174. this->m_WhereSource = _T("");
  175. this->m_WhereBuild = _T("");
  176. this->m_AdvancedValues = FALSE;
  177. this->m_GeneratorDialog.m_GeneratorChoiceString =
  178. cmdInfo.m_GeneratorChoiceString;
  179. this->ChangeDirectoriesFromFile((LPCTSTR)cmdInfo.m_LastUnknownParameter);
  180. }
  181. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  182. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  183. m_BuildPathChanged = false;
  184. // Find the path to the cmake.exe executable
  185. char fname[1024];
  186. ::GetModuleFileName(NULL,fname,1023);
  187. // extract just the path part
  188. m_PathToExecutable = cmSystemTools::GetProgramPath(fname).c_str();
  189. // add the cmake.exe to the path
  190. m_PathToExecutable += "/cmake.exe";
  191. m_oldCX = -1;
  192. m_deltaXRemainder = 0;
  193. }
  194. CMakeSetupDialog::~CMakeSetupDialog()
  195. {
  196. delete m_CMakeInstance;
  197. // clean up globals
  198. cmDynamicLoader::FlushCache();
  199. }
  200. void CMakeSetupDialog::DoDataExchange(CDataExchange* pDX)
  201. {
  202. CDialog::DoDataExchange(pDX);
  203. //{{AFX_DATA_MAP(CMakeSetupDialog)
  204. DDX_Control(pDX, IDC_AdvancedValues, m_AdvancedValuesControl);
  205. DDX_Control(pDX, IDC_SUPPRESS_DEV_WARNINGS, m_SuppressDevWarningsControl);
  206. DDX_Check(pDX, IDC_SUPPRESS_DEV_WARNINGS, m_SuppressDevValue);
  207. DDX_Control(pDX, IDC_BROWSE_SOURCE, m_BrowseSource);
  208. DDX_Control(pDX, IDC_BROWSE_BUILD, m_BrowseBuild);
  209. DDX_Control(pDX, IDC_DELETE_BUTTON, m_DeleteButton);
  210. DDX_Control(pDX, IDC_HELP_BUTTON, m_HelpButton);
  211. DDX_Control(pDX, IDC_OK, m_OKButton);
  212. DDX_Control(pDX, IDCANCEL, m_CancelButton);
  213. DDX_CBStringExact(pDX, IDC_WhereSource, m_WhereSource);
  214. DDX_CBStringExact(pDX, IDC_WhereBuild, m_WhereBuild);
  215. DDX_Control(pDX, IDC_FRAME, m_ListFrame);
  216. DDX_Control(pDX, IDC_WhereSource, m_WhereSourceControl);
  217. DDX_Control(pDX, IDC_WhereBuild, m_WhereBuildControl);
  218. DDX_Control(pDX, IDC_LIST2, m_CacheEntriesList);
  219. DDX_Control(pDX, IDC_MouseHelpCaption, m_MouseHelp);
  220. DDX_Control(pDX, IDC_PROGRESS, m_StatusDisplay);
  221. DDX_Control(pDX, IDC_BuildProjects, m_Configure);
  222. DDX_Check(pDX, IDC_AdvancedValues, m_AdvancedValues);
  223. //}}AFX_DATA_MAP
  224. }
  225. BEGIN_MESSAGE_MAP(CMakeSetupDialog, CDialog)
  226. //{{AFX_MSG_MAP(CMakeSetupDialog)
  227. ON_WM_SYSCOMMAND()
  228. ON_WM_PAINT()
  229. ON_WM_QUERYDRAGICON()
  230. ON_BN_CLICKED(IDC_BUTTON2, OnBrowseWhereSource)
  231. ON_BN_CLICKED(IDC_BuildProjects, OnConfigure)
  232. ON_BN_CLICKED(IDC_BUTTON3, OnBrowseWhereBuild)
  233. ON_CBN_EDITCHANGE(IDC_WhereBuild, OnChangeWhereBuild)
  234. ON_CBN_SELCHANGE(IDC_WhereBuild, OnSelendokWhereBuild)
  235. ON_CBN_EDITCHANGE(IDC_WhereSource, OnChangeWhereSource)
  236. ON_CBN_SELENDOK(IDC_WhereSource, OnSelendokWhereSource)
  237. ON_WM_SIZE()
  238. ON_WM_GETMINMAXINFO()
  239. ON_BN_CLICKED(IDC_OK, OnOk)
  240. ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton)
  241. ON_BN_CLICKED(IDC_HELP_BUTTON, OnHelpButton)
  242. ON_BN_CLICKED(IDC_AdvancedValues, OnAdvancedValues)
  243. ON_BN_CLICKED(IDC_SUPPRESS_DEV_WARNINGS, OnSuppressDevValue)
  244. ON_BN_DOUBLECLICKED(IDC_SUPPRESS_DEV_WARNINGS, OnDoubleclickedSuppressDevValue)
  245. ON_BN_DOUBLECLICKED(IDC_AdvancedValues, OnDoubleclickedAdvancedValues)
  246. ON_WM_DROPFILES()
  247. ON_BN_CLICKED(IDCANCEL, OnCancel)
  248. ON_WM_SETCURSOR()
  249. //}}AFX_MSG_MAP
  250. END_MESSAGE_MAP()
  251. /////////////////////////////////////////////////////////////////////////////
  252. // CMakeSetupDialog message handlers
  253. BOOL CMakeSetupDialog::OnInitDialog()
  254. {
  255. CDialog::OnInitDialog();
  256. this->DragAcceptFiles(true);
  257. // Add "Create shortcut" menu item to system menu.
  258. // IDM_CREATESHORTCUT must be in the system command range.
  259. ASSERT((IDM_CREATESHORTCUT & 0xFFF0) == IDM_CREATESHORTCUT);
  260. ASSERT(IDM_CREATESHORTCUT < 0xF000);
  261. // Add "About..." menu item to system menu.
  262. // IDM_ABOUTBOX must be in the system command range.
  263. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  264. ASSERT(IDM_ABOUTBOX < 0xF000);
  265. CMenu* pSysMenu = GetSystemMenu(FALSE);
  266. if (pSysMenu != NULL)
  267. {
  268. CString strCreateShortcutMenu;
  269. strCreateShortcutMenu.LoadString(IDS_CREATESHORTCUT);
  270. if (!strCreateShortcutMenu.IsEmpty())
  271. {
  272. pSysMenu->AppendMenu(MF_SEPARATOR);
  273. pSysMenu->AppendMenu(MF_STRING,
  274. IDM_CREATESHORTCUT,
  275. strCreateShortcutMenu);
  276. }
  277. CString strAboutMenu;
  278. strAboutMenu.LoadString(IDS_ABOUTBOX);
  279. if (!strAboutMenu.IsEmpty())
  280. {
  281. pSysMenu->AppendMenu(MF_SEPARATOR);
  282. pSysMenu->AppendMenu(MF_STRING,
  283. IDM_ABOUTBOX,
  284. strAboutMenu);
  285. }
  286. }
  287. // Set the icon for this dialog. The framework does this automatically
  288. // when the application's main window is not a dialog
  289. SetIcon(m_hIcon, TRUE); // Set big icon
  290. SetIcon(m_hIcon, FALSE); // Set small icon
  291. // Load source and build dirs from registry
  292. this->LoadFromRegistry();
  293. // try to load the cmake cache from disk
  294. this->LoadCacheFromDiskToGUI();
  295. m_WhereBuildControl.LimitText(2048);
  296. m_WhereSourceControl.LimitText(2048);
  297. // Set the version number
  298. char tmp[1024];
  299. sprintf(tmp,"CMake %s", cmVersion::GetCMakeVersion());
  300. SetDlgItemText(IDC_PROGRESS, "");
  301. this->SetWindowText(tmp);
  302. this->UpdateData(FALSE);
  303. return TRUE; // return TRUE unless you set the focus to a control
  304. }
  305. // About dialog invoke
  306. void CMakeSetupDialog::OnSysCommand(UINT nID, LPARAM lParam)
  307. {
  308. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  309. {
  310. CAboutDlg dlgAbout;
  311. dlgAbout.DoModal();
  312. }
  313. else if ((nID & 0xFFF0) == IDM_CREATESHORTCUT)
  314. {
  315. CreateShortcut();
  316. }
  317. else
  318. {
  319. CDialog::OnSysCommand(nID, lParam);
  320. }
  321. }
  322. // If you add a minimize button to your dialog, you will need the code below
  323. // to draw the icon. For MFC applications using the document/view model,
  324. // this is automatically done for you by the framework.
  325. void CMakeSetupDialog::OnPaint()
  326. {
  327. if (IsIconic())
  328. {
  329. CPaintDC dc(this); // device context for painting
  330. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  331. // Center icon in client rectangle
  332. int cxIcon = GetSystemMetrics(SM_CXICON);
  333. int cyIcon = GetSystemMetrics(SM_CYICON);
  334. CRect rect;
  335. GetClientRect(&rect);
  336. int x = (rect.Width() - cxIcon + 1) / 2;
  337. int y = (rect.Height() - cyIcon + 1) / 2;
  338. // Draw the icon
  339. dc.DrawIcon(x, y, m_hIcon);
  340. }
  341. else
  342. {
  343. CDialog::OnPaint();
  344. }
  345. }
  346. // The system calls this to obtain the cursor to display while the user drags
  347. // the minimized window.
  348. HCURSOR CMakeSetupDialog::OnQueryDragIcon()
  349. {
  350. return (HCURSOR) m_hIcon;
  351. }
  352. // Browse button
  353. bool CMakeSetupDialog::Browse(CString &result, const char *title)
  354. {
  355. CString initialDir = result;
  356. initialDir.Replace("/", "\\");
  357. CPathDialog dlg("Select Path", title, initialDir);
  358. if(dlg.DoModal()==IDOK)
  359. {
  360. result = dlg.GetPathName();
  361. return true;
  362. }
  363. else
  364. {
  365. return false;
  366. }
  367. }
  368. void CMakeSetupDialog::SaveToRegistry()
  369. {
  370. HKEY hKey;
  371. DWORD dwDummy;
  372. if(RegCreateKeyEx(HKEY_CURRENT_USER,
  373. m_RegistryKey,
  374. 0, "", REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE,
  375. NULL, &hKey, &dwDummy) != ERROR_SUCCESS)
  376. {
  377. return;
  378. }
  379. else
  380. {
  381. // save some values
  382. CString regvalue;
  383. // write the size of the dialog
  384. CRect size;
  385. this->GetWindowRect(&size);
  386. unsigned long width = size.Width();
  387. unsigned long height = size.Height();
  388. RegSetValueEx(hKey, _T("Width"), 0, REG_DWORD,
  389. (CONST BYTE *)(&width),4);
  390. RegSetValueEx(hKey, _T("Height"), 0, REG_DWORD,
  391. (CONST BYTE *)(&height),4);
  392. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource1","C:\\");
  393. int shiftEnd = 9;
  394. if(m_WhereSource != regvalue)
  395. {
  396. char keyName[1024];
  397. char keyName2[1024];
  398. int i;
  399. for (i = 2; i < 10; ++i)
  400. {
  401. regvalue = "";
  402. sprintf(keyName,"WhereSource%i",i);
  403. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  404. // check for short circuit, if the new value is already in
  405. // the list then we stop
  406. if (m_WhereSource == regvalue)
  407. {
  408. shiftEnd = i - 1;
  409. }
  410. }
  411. for (i = shiftEnd; i; --i)
  412. {
  413. regvalue = "";
  414. sprintf(keyName,"WhereSource%i",i);
  415. sprintf(keyName2,"WhereSource%i",i+1);
  416. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  417. if (strlen(regvalue))
  418. {
  419. RegSetValueEx(hKey, _T(keyName2), 0, REG_SZ,
  420. (CONST BYTE *)(const char *)regvalue,
  421. regvalue.GetLength());
  422. }
  423. }
  424. RegSetValueEx(hKey, _T("WhereSource1"), 0, REG_SZ,
  425. (CONST BYTE *)(const char *)m_WhereSource,
  426. m_WhereSource.GetLength());
  427. }
  428. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild1","C:\\");
  429. if(m_WhereBuild != regvalue)
  430. {
  431. int i;
  432. char keyName[1024];
  433. char keyName2[1024];
  434. for (i = 2; i < 10; ++i)
  435. {
  436. regvalue = "";
  437. sprintf(keyName,"WhereBuild%i",i);
  438. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  439. // check for short circuit, if the new value is already in
  440. // the list then we stop
  441. if (m_WhereBuild == regvalue)
  442. {
  443. shiftEnd = i - 1;
  444. }
  445. }
  446. for (i = shiftEnd; i; --i)
  447. {
  448. regvalue = "";
  449. sprintf(keyName,"WhereBuild%i",i);
  450. sprintf(keyName2,"WhereBuild%i",i+1);
  451. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  452. if (strlen(regvalue))
  453. {
  454. RegSetValueEx(hKey, _T(keyName2), 0, REG_SZ,
  455. (CONST BYTE *)(const char *)regvalue,
  456. regvalue.GetLength());
  457. }
  458. }
  459. RegSetValueEx(hKey, _T("WhereBuild1"), 0, REG_SZ,
  460. (CONST BYTE *)(const char *)m_WhereBuild,
  461. m_WhereBuild.GetLength());
  462. }
  463. }
  464. RegCloseKey(hKey);
  465. }
  466. void CMakeSetupDialog::ReadRegistryValue(HKEY hKey,
  467. CString *val,
  468. const char *key,
  469. const char *adefault)
  470. {
  471. DWORD dwType, dwSize;
  472. char *pb;
  473. dwType = REG_SZ;
  474. pb = val->GetBuffer(MAX_PATH);
  475. dwSize = MAX_PATH;
  476. if(RegQueryValueEx(hKey,_T(key), NULL, &dwType,
  477. (BYTE *)pb, &dwSize) != ERROR_SUCCESS)
  478. {
  479. val->ReleaseBuffer();
  480. *val = _T(adefault);
  481. }
  482. else
  483. {
  484. val->ReleaseBuffer();
  485. }
  486. }
  487. void CMakeSetupDialog::LoadFromRegistry()
  488. {
  489. HKEY hKey;
  490. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  491. m_RegistryKey,
  492. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  493. {
  494. return;
  495. }
  496. else
  497. {
  498. // load some values
  499. DWORD dwSize = 4;
  500. DWORD width, height;
  501. if (RegQueryValueEx(hKey,_T("Width"), NULL, NULL,
  502. (BYTE *)&width, &dwSize) == ERROR_SUCCESS &&
  503. RegQueryValueEx(hKey,_T("Height"), NULL, NULL,
  504. (BYTE *)&height, &dwSize) == ERROR_SUCCESS)
  505. {
  506. this->SetWindowPos(0,0,0,width,height,SWP_NOZORDER | SWP_NOMOVE);
  507. }
  508. if (m_WhereSource.IsEmpty())
  509. {
  510. this->ReadRegistryValue(hKey, &(m_WhereSource),"WhereSource1","C:\\");
  511. }
  512. if (m_WhereBuild.IsEmpty())
  513. {
  514. this->ReadRegistryValue(hKey, &(m_WhereBuild),"WhereBuild1","C:\\");
  515. }
  516. m_WhereSourceControl.AddString(m_WhereSource);
  517. m_WhereBuildControl.AddString(m_WhereBuild);
  518. char keyname[1024];
  519. CString regvalue;
  520. int i;
  521. for (i = 2; i <= 10; ++i)
  522. {
  523. sprintf(keyname,"WhereSource%i",i);
  524. regvalue = "";
  525. this->ReadRegistryValue(hKey, &(regvalue),keyname,"C:\\");
  526. if (strcmp("C:\\",regvalue))
  527. {
  528. m_WhereSourceControl.AddString(regvalue);
  529. }
  530. sprintf(keyname,"WhereBuild%i",i);
  531. regvalue = "";
  532. this->ReadRegistryValue(hKey, &(regvalue),keyname,"C:\\");
  533. if (strcmp("C:\\",regvalue))
  534. {
  535. m_WhereBuildControl.AddString(regvalue);
  536. }
  537. }
  538. }
  539. RegCloseKey(hKey);
  540. }
  541. // Callback for browse source button
  542. void CMakeSetupDialog::OnBrowseWhereSource()
  543. {
  544. this->UpdateData();
  545. Browse(m_WhereSource, "Enter Path to Source");
  546. this->UpdateData(false);
  547. this->OnChangeWhereSource();
  548. }
  549. // Callback for browser build button
  550. void CMakeSetupDialog::OnBrowseWhereBuild()
  551. {
  552. this->UpdateData();
  553. Browse(m_WhereBuild, "Enter Path to Build");
  554. this->UpdateData(false);
  555. this->OnChangeWhereBuild();
  556. }
  557. void CMakeSetupDialog::RunCMake(bool generateProjectFiles)
  558. {
  559. if(!cmSystemTools::FileExists(m_WhereBuild))
  560. {
  561. std::string message =
  562. "Build directory does not exist, should I create it?\n\n"
  563. "Directory: ";
  564. message += (const char*)m_WhereBuild;
  565. if(MessageBox(message.c_str(), "Create Directory", MB_OKCANCEL) == IDOK)
  566. {
  567. cmSystemTools::MakeDirectory(m_WhereBuild);
  568. }
  569. else
  570. {
  571. MessageBox("Build Project aborted, nothing done.");
  572. return;
  573. }
  574. }
  575. // set the wait cursor
  576. m_Cursor = LoadCursor(NULL, IDC_WAIT);
  577. ::SetCursor(m_Cursor);
  578. m_RunningConfigure = true;
  579. // get all the info from the dialog
  580. this->UpdateData();
  581. // always save the current gui values to disk
  582. this->SaveCacheFromGUI();
  583. // Make sure we are working from the cache on disk
  584. this->LoadCacheFromDiskToGUI();
  585. m_OKButton.EnableWindow(false);
  586. // setup the cmake instance
  587. if (generateProjectFiles)
  588. {
  589. if(m_CMakeInstance->Generate() != 0)
  590. {
  591. cmSystemTools::Error(
  592. "Error in generation process, project files may be invalid");
  593. }
  594. }
  595. else
  596. {
  597. m_CMakeInstance->SetHomeDirectory(m_WhereSource);
  598. m_CMakeInstance->SetStartDirectory(m_WhereSource);
  599. m_CMakeInstance->SetHomeOutputDirectory(m_WhereBuild);
  600. m_CMakeInstance->SetStartOutputDirectory(m_WhereBuild);
  601. m_CMakeInstance->SetGlobalGenerator(
  602. m_CMakeInstance->CreateGlobalGenerator(m_GeneratorDialog.m_GeneratorChoiceString));
  603. m_CMakeInstance->SetCMakeCommand(m_PathToExecutable);
  604. m_CMakeInstance->LoadCache();
  605. if(m_SuppressDevValue)
  606. {
  607. m_CMakeInstance->SetSuppressDevWarnings(true);
  608. }
  609. else
  610. {
  611. m_CMakeInstance->SetSuppressDevWarnings(false);
  612. }
  613. if(m_CMakeInstance->Configure() != 0)
  614. {
  615. cmSystemTools::Error(
  616. "Error in configuration process, project files may be invalid");
  617. }
  618. // update the GUI with any new values in the caused by the
  619. // generation process
  620. this->LoadCacheFromDiskToGUI();
  621. }
  622. // save source and build paths to registry
  623. this->SaveToRegistry();
  624. // path is up-to-date now
  625. m_BuildPathChanged = false;
  626. // put the cursor back
  627. m_Cursor = LoadCursor(NULL, IDC_ARROW);
  628. ::SetCursor(m_Cursor);
  629. m_RunningConfigure = false;
  630. cmSystemTools::ResetErrorOccuredFlag();
  631. }
  632. // Callback for build projects button
  633. void CMakeSetupDialog::OnConfigure()
  634. {
  635. if(!m_GeneratorPicked)
  636. {
  637. m_GeneratorDialog.m_CMakeInstance = this->m_CMakeInstance;
  638. if(m_GeneratorDialog.DoModal() != IDOK)
  639. {
  640. return;
  641. }
  642. // save the generator choice in the registry
  643. HKEY hKey;
  644. DWORD dwDummy;
  645. if(RegCreateKeyEx(HKEY_CURRENT_USER,
  646. m_RegistryKey,
  647. 0, "", REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE,
  648. NULL, &hKey, &dwDummy) == ERROR_SUCCESS)
  649. {
  650. // save some values
  651. RegSetValueEx(hKey, _T("LastGenerator"), 0, REG_SZ,
  652. (CONST BYTE *)(const char *)m_GeneratorDialog.m_GeneratorChoiceString,
  653. m_GeneratorDialog.m_GeneratorChoiceString.GetLength());
  654. }
  655. }
  656. // enable error messages each time configure is pressed
  657. cmSystemTools::EnableMessages();
  658. this->RunCMake(false);
  659. }
  660. // callback for combo box menu where build selection
  661. void CMakeSetupDialog::OnSelendokWhereBuild()
  662. {
  663. m_WhereBuildControl.GetLBText(m_WhereBuildControl.GetCurSel(),
  664. m_WhereBuild);
  665. m_WhereBuildControl.SetWindowText( m_WhereBuild);
  666. this->UpdateData(FALSE);
  667. this->OnChangeWhereBuild();
  668. }
  669. // callback for combo box menu where source selection
  670. void CMakeSetupDialog::OnSelendokWhereSource()
  671. {
  672. m_WhereSourceControl.GetLBText(m_WhereSourceControl.GetCurSel(),
  673. m_WhereSource);
  674. this->UpdateData(FALSE);
  675. this->OnChangeWhereSource();
  676. }
  677. // callback for chaing source directory
  678. void CMakeSetupDialog::OnChangeWhereSource()
  679. {
  680. }
  681. // callback for changing the build directory
  682. void CMakeSetupDialog::OnChangeWhereBuild()
  683. {
  684. this->UpdateData();
  685. // The build dir has changed, check if there is a cache, and
  686. // grab the source dir from it
  687. std::string path = this->m_WhereBuild;
  688. cmSystemTools::ConvertToUnixSlashes(path);
  689. // adjust the cmake instance
  690. m_CMakeInstance->SetHomeOutputDirectory(m_WhereBuild);
  691. m_CMakeInstance->SetStartOutputDirectory(m_WhereBuild);
  692. std::string cache_file = path;
  693. cache_file += "/CMakeCache.txt";
  694. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  695. cmCacheManager::CacheIterator it = cachem->NewIterator();
  696. m_GeneratorPicked = false;
  697. // make sure we have a normal cache file, specifically if one exists make
  698. // sure it can be read
  699. if (cmSystemTools::FileExists(cache_file.c_str()))
  700. {
  701. if (cachem->LoadCache(path.c_str()))
  702. {
  703. if (it.Find("CMAKE_HOME_DIRECTORY"))
  704. {
  705. path = ConvertToWindowsPath(it.GetValue());
  706. this->m_WhereSource = path.c_str();
  707. this->m_WhereSourceControl.SetWindowText(this->m_WhereSource);
  708. this->OnChangeWhereSource();
  709. m_GeneratorPicked = true;
  710. }
  711. }
  712. else
  713. {
  714. //file exists but cqnnot be read
  715. cmSystemTools::Error("There is a CMakeCache.txt file for the current binary tree but cmake does not have permission to read it. Please check the permissions of the directory you are trying to run CMake on.");
  716. return;
  717. }
  718. }
  719. m_CacheEntriesList.RemoveAll();
  720. m_CacheEntriesList.ShowWindow(SW_SHOW);
  721. this->LoadCacheFromDiskToGUI();
  722. m_BuildPathChanged = true;
  723. }
  724. // copy from the cache manager to the cache edit list box
  725. void CMakeSetupDialog::FillCacheGUIFromCacheManager()
  726. {
  727. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  728. cmCacheManager::CacheIterator it = cachem->NewIterator();
  729. // if there are already entries in the cache, then
  730. // put the new ones in the top, so they show up first
  731. bool reverseOrder = false;
  732. // all the current values are not new any more
  733. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  734. for(std::set<CPropertyItem*>::iterator i = items.begin();
  735. i != items.end(); ++i)
  736. {
  737. // first check to see if it is still in the cache
  738. CPropertyItem* item = *i;
  739. if ( !it.Find((const char*)item->m_propName) )
  740. {
  741. m_CacheEntriesList.RemoveProperty((const char*)item->m_propName);
  742. }
  743. else
  744. {
  745. // if it is still in the cache then it is no longer new
  746. item->m_NewValue = false;
  747. }
  748. }
  749. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  750. !i.IsAtEnd(); i.Next())
  751. {
  752. const char* key = i.GetName();
  753. // if value has trailing space or tab, enclose it in single quotes
  754. // to enforce the fact that it has 'invisible' trailing stuff
  755. std::string value = i.GetValue();
  756. if (value.size() &&
  757. (value[value.size() - 1] == ' ' ||
  758. value[value.size() - 1] == '\t'))
  759. {
  760. value = '\'' + value + '\'';
  761. }
  762. bool advanced = i.GetPropertyAsBool("ADVANCED");
  763. switch(i.GetType() )
  764. {
  765. case cmCacheManager::BOOL:
  766. if(cmSystemTools::IsOn(value.c_str()))
  767. {
  768. m_CacheEntriesList.AddProperty(key,
  769. "ON",
  770. i.GetProperty("HELPSTRING"),
  771. CPropertyList::COMBO,"ON|OFF",
  772. reverseOrder,
  773. advanced
  774. );
  775. }
  776. else
  777. {
  778. m_CacheEntriesList.AddProperty(key,
  779. "OFF",
  780. i.GetProperty("HELPSTRING"),
  781. CPropertyList::COMBO,"ON|OFF",
  782. reverseOrder, advanced
  783. );
  784. }
  785. break;
  786. case cmCacheManager::PATH:
  787. m_CacheEntriesList.AddProperty(key,
  788. value.c_str(),
  789. i.GetProperty("HELPSTRING"),
  790. CPropertyList::PATH,"",
  791. reverseOrder, advanced
  792. );
  793. break;
  794. case cmCacheManager::FILEPATH:
  795. m_CacheEntriesList.AddProperty(key,
  796. value.c_str(),
  797. i.GetProperty("HELPSTRING"),
  798. CPropertyList::FILE,"",
  799. reverseOrder, advanced
  800. );
  801. break;
  802. case cmCacheManager::STRING:
  803. m_CacheEntriesList.AddProperty(key,
  804. value.c_str(),
  805. i.GetProperty("HELPSTRING"),
  806. CPropertyList::EDIT,"",
  807. reverseOrder, advanced
  808. );
  809. break;
  810. case cmCacheManager::INTERNAL:
  811. m_CacheEntriesList.RemoveProperty(key);
  812. break;
  813. }
  814. }
  815. if(m_CacheEntriesList.GetShowAdvanced())
  816. {
  817. m_CacheEntriesList.ShowAdvanced();
  818. }
  819. else
  820. {
  821. m_CacheEntriesList.HideAdvanced();
  822. }
  823. m_OKButton.EnableWindow(false);
  824. if(cachem->GetSize() > 0 && !cmSystemTools::GetErrorOccuredFlag())
  825. {
  826. bool enable = true;
  827. items = m_CacheEntriesList.GetItems();
  828. for(std::set<CPropertyItem*>::iterator i = items.begin();
  829. i != items.end(); ++i)
  830. {
  831. CPropertyItem* item = *i;
  832. if(item->m_Advanced )
  833. {
  834. if(item->m_NewValue && m_CacheEntriesList.GetShowAdvanced())
  835. {
  836. enable = false;
  837. break;
  838. }
  839. }
  840. else
  841. {
  842. if(item->m_NewValue)
  843. {
  844. // if one new value then disable to OK button
  845. enable = false;
  846. break;
  847. }
  848. }
  849. }
  850. if(enable)
  851. {
  852. m_OKButton.EnableWindow(true);
  853. }
  854. }
  855. // redraw the list
  856. m_CacheEntriesList.SetTopIndex(0);
  857. m_CacheEntriesList.Invalidate();
  858. }
  859. // copy from the list box to the cache manager
  860. void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
  861. {
  862. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  863. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  864. cmCacheManager::CacheIterator it = cachem->NewIterator();
  865. for(std::set<CPropertyItem*>::iterator i = items.begin();
  866. i != items.end(); ++i)
  867. {
  868. CPropertyItem* item = *i;
  869. if ( it.Find((const char*)item->m_propName) )
  870. {
  871. // if value is enclosed in single quotes ('foo') then remove them
  872. // they were used to enforce the fact that it had 'invisible'
  873. // trailing stuff
  874. if (item->m_curValue.GetLength() >= 2 &&
  875. item->m_curValue[0] == '\'' &&
  876. item->m_curValue[item->m_curValue.GetLength() - 1] == '\'')
  877. {
  878. it.SetValue(item->m_curValue.Mid(
  879. 1, item->m_curValue.GetLength() - 2));
  880. }
  881. else
  882. {
  883. it.SetValue(item->m_curValue);
  884. }
  885. }
  886. }
  887. }
  888. //! Load cache file from m_WhereBuild and display in GUI editor
  889. void CMakeSetupDialog::LoadCacheFromDiskToGUI()
  890. {
  891. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  892. if(m_WhereBuild != "")
  893. {
  894. if (!cachem->LoadCache(m_WhereBuild))
  895. {
  896. // if it does exist, but isn;t readable then warn the user
  897. std::string cacheFile = m_WhereBuild;
  898. cacheFile += "/CMakeCache.txt";
  899. if(cmSystemTools::FileExists(cacheFile.c_str()))
  900. {
  901. cmSystemTools::Error("There is a CMakeCache.txt file for the current binary tree but cmake does not have permission to read it. Please check the permissions of the directory you are trying to run CMake on.");
  902. return;
  903. }
  904. }
  905. cmCacheManager::CacheIterator itm = cachem->NewIterator();
  906. if ( itm.Find("CMAKE_HOME_DIRECTORY"))
  907. {
  908. std::string path = ConvertToWindowsPath(itm.GetValue());
  909. this->m_WhereSource = path.c_str();
  910. this->m_WhereSourceControl.SetWindowText(this->m_WhereSource);
  911. this->OnChangeWhereSource();
  912. }
  913. m_CMakeInstance->SetHomeDirectory(m_WhereSource);
  914. m_CMakeInstance->SetStartDirectory(m_WhereSource);
  915. m_CMakeInstance->SetHomeOutputDirectory(m_WhereBuild);
  916. m_CMakeInstance->SetStartOutputDirectory(m_WhereBuild);
  917. m_CMakeInstance->PreLoadCMakeFiles();
  918. this->FillCacheGUIFromCacheManager();
  919. cmCacheManager::CacheIterator it =
  920. cachem->GetCacheIterator("CMAKE_GENERATOR");
  921. if(!it.IsAtEnd())
  922. {
  923. m_GeneratorPicked = true;
  924. const char* extraGen = cachem->GetCacheValue("CMAKE_EXTRA_GENERATOR");
  925. std::string curGen = cmExternalMakefileProjectGenerator::
  926. CreateFullGeneratorName(it.GetValue(), extraGen);
  927. if(m_GeneratorDialog.m_GeneratorChoiceString != curGen.c_str())
  928. {
  929. m_GeneratorDialog.m_GeneratorChoiceString = curGen.c_str();
  930. this->UpdateData(FALSE);
  931. }
  932. }
  933. }
  934. }
  935. //! Save GUI values to cmCacheManager and then save to disk.
  936. void CMakeSetupDialog::SaveCacheFromGUI()
  937. {
  938. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  939. this->FillCacheManagerFromCacheGUI();
  940. if(m_WhereBuild != "")
  941. {
  942. cachem->SaveCache(m_WhereBuild);
  943. }
  944. }
  945. void CMakeSetupDialog::OnSize(UINT nType, int cx, int cy)
  946. {
  947. if (nType == SIZE_MINIMIZED)
  948. {
  949. CDialog::OnSize(nType, cx, cy);
  950. return;
  951. }
  952. if (m_oldCX == -1)
  953. {
  954. m_oldCX = cx;
  955. m_oldCY = cy;
  956. }
  957. int deltax = cx - m_oldCX;
  958. int deltay = cy - m_oldCY;
  959. m_oldCX = cx;
  960. m_oldCY = cy;
  961. CDialog::OnSize(nType, cx, cy);
  962. if (deltax == 0 && deltay == 0)
  963. {
  964. return;
  965. }
  966. if(m_CacheEntriesList.m_hWnd)
  967. {
  968. // get the original sizes/positions
  969. CRect cRect;
  970. m_AdvancedValuesControl.GetWindowRect(&cRect);
  971. this->ScreenToClient(&cRect);
  972. m_AdvancedValuesControl.SetWindowPos(&wndTop, cRect.left + deltax,
  973. cRect.top,
  974. 0, 0,
  975. SWP_NOCOPYBITS |
  976. SWP_NOSIZE | SWP_NOZORDER);
  977. m_SuppressDevWarningsControl.GetWindowRect(&cRect);
  978. this->ScreenToClient(&cRect);
  979. m_SuppressDevWarningsControl.SetWindowPos(&wndTop, cRect.left + deltax,
  980. cRect.top,
  981. 0, 0,
  982. SWP_NOCOPYBITS |
  983. SWP_NOSIZE | SWP_NOZORDER);
  984. m_BrowseSource.GetWindowRect(&cRect);
  985. this->ScreenToClient(&cRect);
  986. m_BrowseSource.SetWindowPos(&wndTop, cRect.left + deltax,
  987. cRect.top,
  988. 0, 0,
  989. SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER);
  990. m_BrowseBuild.GetWindowRect(&cRect);
  991. this->ScreenToClient(&cRect);
  992. m_BrowseBuild.SetWindowPos(&wndTop, cRect.left + deltax,
  993. cRect.top,
  994. 0, 0,
  995. SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER);
  996. m_WhereSourceControl.GetWindowRect(&cRect);
  997. m_WhereSourceControl.SetWindowPos(&wndTop, cRect.left, cRect.top,
  998. cRect.Width() + deltax,
  999. cRect.Height(),
  1000. SWP_NOCOPYBITS |
  1001. SWP_NOMOVE | SWP_NOZORDER);
  1002. m_WhereBuildControl.GetWindowRect(&cRect);
  1003. m_WhereBuildControl.SetWindowPos(&wndTop, cRect.left, cRect.top,
  1004. cRect.Width() + deltax,
  1005. cRect.Height(),
  1006. SWP_NOCOPYBITS |
  1007. SWP_NOMOVE | SWP_NOZORDER);
  1008. m_ListFrame.GetWindowRect(&cRect);
  1009. m_ListFrame.SetWindowPos(&wndTop, cRect.left, cRect.top,
  1010. cRect.Width() + deltax,
  1011. cRect.Height() + deltay,
  1012. SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER);
  1013. m_CacheEntriesList.GetWindowRect(&cRect);
  1014. m_CacheEntriesList.SetWindowPos(&wndTop, cRect.left, cRect.top,
  1015. cRect.Width() + deltax,
  1016. cRect.Height() + deltay,
  1017. SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER);
  1018. m_StatusDisplay.GetWindowRect(&cRect);
  1019. this->ScreenToClient(&cRect);
  1020. m_StatusDisplay.SetWindowPos(&wndBottom, cRect.left,
  1021. cRect.top + deltay,
  1022. cRect.Width() + deltax, cRect.Height(),
  1023. SWP_NOCOPYBITS);
  1024. m_MouseHelp.GetWindowRect(&cRect);
  1025. this->ScreenToClient(&cRect);
  1026. m_MouseHelp.SetWindowPos(&wndTop, cRect.left ,
  1027. cRect.top + deltay,
  1028. cRect.Width() + deltax, cRect.Height(),
  1029. SWP_NOCOPYBITS | SWP_NOZORDER);
  1030. deltax = int(deltax + m_deltaXRemainder);
  1031. m_deltaXRemainder = float(deltax%2);
  1032. m_Configure.GetWindowRect(&cRect);
  1033. this->ScreenToClient(&cRect);
  1034. m_Configure.SetWindowPos(&wndTop, cRect.left + deltax/2,
  1035. cRect.top + deltay,
  1036. 0, 0,
  1037. SWP_NOCOPYBITS | SWP_NOSIZE);
  1038. m_CancelButton.GetWindowRect(&cRect);
  1039. this->ScreenToClient(&cRect);
  1040. m_CancelButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  1041. cRect.top + deltay,
  1042. 0, 0,
  1043. SWP_NOCOPYBITS | SWP_NOSIZE);
  1044. m_OKButton.GetWindowRect(&cRect);
  1045. this->ScreenToClient(&cRect);
  1046. m_OKButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  1047. cRect.top + deltay,
  1048. 0, 0,
  1049. SWP_NOCOPYBITS | SWP_NOSIZE);
  1050. m_DeleteButton.GetWindowRect(&cRect);
  1051. this->ScreenToClient(&cRect);
  1052. m_DeleteButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  1053. cRect.top + deltay,
  1054. 0, 0,
  1055. SWP_NOCOPYBITS | SWP_NOSIZE);
  1056. m_HelpButton.GetWindowRect(&cRect);
  1057. this->ScreenToClient(&cRect);
  1058. m_HelpButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  1059. cRect.top + deltay,
  1060. 0, 0,
  1061. SWP_NOCOPYBITS | SWP_NOSIZE);
  1062. }
  1063. }
  1064. void CMakeSetupDialog::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
  1065. {
  1066. lpMMI->ptMinTrackSize.x = 550;
  1067. lpMMI->ptMinTrackSize.y = 272;
  1068. }
  1069. void CMakeSetupDialog::OnCancel()
  1070. {
  1071. if(m_RunningConfigure)
  1072. {
  1073. if(MessageBox("You are in the middle of a Configure.\n"
  1074. "If you Cancel now the configure information will be lost.\n"
  1075. "Are you sure you want to Cancel?", "Confirm Exit",
  1076. MB_YESNO) == IDYES)
  1077. {
  1078. cmSystemTools::SetFatalErrorOccured();
  1079. }
  1080. return;
  1081. }
  1082. if(m_CacheEntriesList.IsDirty())
  1083. {
  1084. if(MessageBox("You have changed options but not rebuilt, "
  1085. "are you sure you want to exit?", "Confirm Exit",
  1086. MB_YESNO) == IDYES)
  1087. {
  1088. CDialog::OnOK();
  1089. }
  1090. }
  1091. else
  1092. {
  1093. CDialog::OnOK();
  1094. }
  1095. }
  1096. void CMakeSetupDialog::OnOk()
  1097. {
  1098. // enable error messages each time configure is pressed
  1099. cmSystemTools::EnableMessages();
  1100. m_CacheEntriesList.ClearDirty();
  1101. this->RunCMake(true);
  1102. // save the size of the dialog
  1103. if (!(::GetKeyState(VK_SHIFT) & 0x1000))
  1104. {
  1105. CDialog::OnOK();
  1106. }
  1107. }
  1108. // Create a shortcut on the desktop with the current Source/Build dir.
  1109. int CMakeSetupDialog::CreateShortcut()
  1110. {
  1111. // Find the desktop folder and create the link name
  1112. HKEY hKey;
  1113. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  1114. "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
  1115. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  1116. {
  1117. AfxMessageBox ("Create shortcut: unable to find 'Shell Folders' key in registry!");
  1118. return 1;
  1119. }
  1120. DWORD dwType, dwSize;
  1121. #define MAXPATH 1024
  1122. char link_name[MAXPATH];
  1123. dwSize = MAXPATH;
  1124. if(RegQueryValueEx(hKey,
  1125. (LPCTSTR)"Desktop",
  1126. NULL,
  1127. &dwType,
  1128. (BYTE *)link_name,
  1129. &dwSize) != ERROR_SUCCESS)
  1130. {
  1131. AfxMessageBox ("Create shortcut: unable to find 'Desktop' registry value in 'Shell Folders' key!");
  1132. return 1;
  1133. }
  1134. if(dwType != REG_SZ)
  1135. {
  1136. AfxMessageBox ("Create shortcut: 'Desktop' registry value in 'Shell Folders' key has wrong type!");
  1137. return 1;
  1138. }
  1139. strcat(link_name, "\\CMake - ");
  1140. std::string current_dir = cmSystemTools::GetFilenameName((LPCTSTR)m_WhereSource);
  1141. strcat(link_name, current_dir.c_str());
  1142. strcat(link_name, ".lnk");
  1143. // Find the path to the current executable
  1144. char path_to_current_exe[MAXPATH];
  1145. ::GetModuleFileName(NULL, path_to_current_exe, MAXPATH);
  1146. // Create the shortcut
  1147. HRESULT hres;
  1148. IShellLink *psl;
  1149. // Initialize the COM library
  1150. hres = CoInitialize(NULL);
  1151. if (! SUCCEEDED (hres))
  1152. {
  1153. AfxMessageBox ("Create shortcut: unable to initialize the COM library!");
  1154. return 1;
  1155. }
  1156. // Create an IShellLink object and get a pointer to the IShellLink
  1157. // interface (returned from CoCreateInstance).
  1158. hres = CoCreateInstance(CLSID_ShellLink,
  1159. NULL,
  1160. CLSCTX_INPROC_SERVER,
  1161. IID_IShellLink,
  1162. (void **)&psl);
  1163. if (! SUCCEEDED (hres))
  1164. {
  1165. AfxMessageBox ("Create shortcut: unable to create IShellLink instance!");
  1166. return 1;
  1167. }
  1168. IPersistFile *ppf;
  1169. // Query IShellLink for the IPersistFile interface for
  1170. // saving the shortcut in persistent storage.
  1171. hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
  1172. if (SUCCEEDED (hres))
  1173. {
  1174. // Set the path to the shortcut target.
  1175. hres = psl->SetPath(path_to_current_exe);
  1176. if (! SUCCEEDED (hres))
  1177. {
  1178. AfxMessageBox ("Create shortcut: SetPath failed!");
  1179. }
  1180. // Set the arguments of the shortcut.
  1181. CString args = " /H=\"" + m_WhereSource + "\" /B=\"" + m_WhereBuild + "\" /G=\"" + m_GeneratorDialog.m_GeneratorChoiceString + "\" /A=\"" + (m_AdvancedValues ? "TRUE" : "FALSE") + "\"";
  1182. hres = psl->SetArguments(args);
  1183. if (! SUCCEEDED (hres))
  1184. {
  1185. AfxMessageBox ("Create shortcut: SetArguments failed!");
  1186. }
  1187. // Set the description of the shortcut.
  1188. hres = psl->SetDescription("Shortcut to CMakeSetup");
  1189. if (! SUCCEEDED (hres))
  1190. {
  1191. AfxMessageBox ("Create shortcut: SetDescription failed!");
  1192. }
  1193. // Ensure that the string consists of ANSI characters.
  1194. WORD wszAr[MAX_PATH];
  1195. LPWSTR wsz = (LPWSTR)wszAr;
  1196. MultiByteToWideChar(CP_ACP, 0, link_name, -1, (LPWSTR)(wsz), MAX_PATH);
  1197. // Save the shortcut via the IPersistFile::Save member function.
  1198. hres = ppf->Save(wsz, TRUE);
  1199. if (! SUCCEEDED (hres))
  1200. {
  1201. AfxMessageBox ("Create shortcut: Save failed!");
  1202. }
  1203. // Release the pointer to IPersistFile.
  1204. ppf->Release ();
  1205. }
  1206. // Release the pointer to IShellLink.
  1207. psl->Release ();
  1208. return 0;
  1209. }
  1210. void CMakeSetupDialog::OnHelpButton()
  1211. {
  1212. CMakeHelp dialog;
  1213. dialog.DoModal();
  1214. }
  1215. void CMakeSetupDialog::OnDeleteButton()
  1216. {
  1217. std::string message = "Are you sure you want to delete the CMakeCache.txt file for:\n";
  1218. message += m_WhereBuild;
  1219. if(::MessageBox(0, message.c_str(), "Delete Cache?",
  1220. MB_YESNO|MB_TASKMODAL) == IDNO)
  1221. {
  1222. return;
  1223. }
  1224. m_GeneratorPicked = false;
  1225. if(m_WhereBuild != "" && this->m_CMakeInstance)
  1226. {
  1227. this->m_CMakeInstance->GetCacheManager()->DeleteCache(m_WhereBuild);
  1228. }
  1229. // Make sure we are working from the cache on disk
  1230. this->LoadCacheFromDiskToGUI();
  1231. m_OKButton.EnableWindow(false);
  1232. }
  1233. void CMakeSetupDialog::ShowAdvancedValues()
  1234. {
  1235. m_CacheEntriesList.ShowAdvanced();
  1236. }
  1237. void CMakeSetupDialog::RemoveAdvancedValues()
  1238. {
  1239. m_CacheEntriesList.HideAdvanced();
  1240. }
  1241. void CMakeSetupDialog::OnSuppressDevValue()
  1242. {
  1243. }
  1244. void CMakeSetupDialog::OnDoubleclickedSuppressDevValue()
  1245. {
  1246. this->OnSuppressDevValue();
  1247. }
  1248. void CMakeSetupDialog::OnAdvancedValues()
  1249. {
  1250. this->UpdateData();
  1251. if(m_AdvancedValues)
  1252. {
  1253. this->ShowAdvancedValues();
  1254. }
  1255. else
  1256. {
  1257. this->RemoveAdvancedValues();
  1258. }
  1259. }
  1260. void CMakeSetupDialog::OnDoubleclickedAdvancedValues()
  1261. {
  1262. this->OnAdvancedValues();
  1263. }
  1264. // Handle param or single dropped file.
  1265. void CMakeSetupDialog::ChangeDirectoriesFromFile(const char* arg)
  1266. {
  1267. // Check if the argument refers to a CMakeCache.txt or
  1268. // CMakeLists.txt file.
  1269. std::string listPath;
  1270. std::string cachePath;
  1271. bool argIsFile = false;
  1272. if(cmSystemTools::FileIsDirectory(arg))
  1273. {
  1274. std::string path = cmSystemTools::CollapseFullPath(arg);
  1275. cmSystemTools::ConvertToUnixSlashes(path);
  1276. std::string cacheFile = path;
  1277. cacheFile += "/CMakeCache.txt";
  1278. std::string listFile = path;
  1279. listFile += "/CMakeLists.txt";
  1280. if(cmSystemTools::FileExists(cacheFile.c_str()))
  1281. {
  1282. cachePath = path;
  1283. }
  1284. if(cmSystemTools::FileExists(listFile.c_str()))
  1285. {
  1286. listPath = path;
  1287. }
  1288. }
  1289. else if(cmSystemTools::FileExists(arg))
  1290. {
  1291. argIsFile = true;
  1292. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  1293. std::string name = cmSystemTools::GetFilenameName(fullPath.c_str());
  1294. name = cmSystemTools::LowerCase(name);
  1295. if(name == "cmakecache.txt")
  1296. {
  1297. cachePath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  1298. }
  1299. else if(name == "cmakelists.txt")
  1300. {
  1301. listPath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  1302. }
  1303. }
  1304. // If there is a CMakeCache.txt file, use its settings.
  1305. if(cachePath.length() > 0)
  1306. {
  1307. cmCacheManager* cachem = m_CMakeInstance->GetCacheManager();
  1308. cmCacheManager::CacheIterator it = cachem->NewIterator();
  1309. if(cachem->LoadCache(cachePath.c_str()) && it.Find("CMAKE_HOME_DIRECTORY"))
  1310. {
  1311. std::string path = ConvertToWindowsPath(cachePath.c_str());
  1312. m_WhereBuild = path.c_str();
  1313. path = ConvertToWindowsPath(it.GetValue());
  1314. m_WhereSource = path.c_str();
  1315. m_GeneratorDialog.m_GeneratorChoiceString = _T("");
  1316. return;
  1317. }
  1318. }
  1319. // If there is a CMakeLists.txt file, use it as the source tree.
  1320. if(listPath.length() > 0)
  1321. {
  1322. std::string path = ConvertToWindowsPath(listPath.c_str());
  1323. m_WhereSource = path.c_str();
  1324. if(argIsFile)
  1325. {
  1326. // Source CMakeLists.txt file given. It was probably dropped
  1327. // onto the window or executable. Default to an in-source
  1328. // build.
  1329. m_WhereBuild = path.c_str();
  1330. }
  1331. else
  1332. {
  1333. // Source directory given on command line. Use current working
  1334. // directory as build tree.
  1335. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1336. path = ConvertToWindowsPath(cwd.c_str());
  1337. m_WhereBuild = path.c_str();
  1338. }
  1339. }
  1340. }
  1341. // The framework calls this member function when the user releases the
  1342. // left mouse button over a window that has registered itself as the
  1343. // recipient of dropped files.
  1344. void CMakeSetupDialog::OnDropFiles(HDROP hDropInfo)
  1345. {
  1346. UINT nb_files = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0);
  1347. if (nb_files > 0)
  1348. {
  1349. UINT buffer_size = DragQueryFile(hDropInfo, 0, NULL, 0);
  1350. char *buffer = new char [buffer_size + 1];
  1351. DragQueryFile(hDropInfo, 0, buffer, buffer_size + 1);
  1352. this->ChangeDirectoriesFromFile(buffer);
  1353. delete [] buffer;
  1354. this->m_WhereSourceControl.SetWindowText(this->m_WhereSource);
  1355. this->m_WhereBuildControl.SetWindowText(this->m_WhereBuild);
  1356. this->UpdateData(FALSE);
  1357. this->OnChangeWhereSource();
  1358. this->OnChangeWhereBuild();
  1359. }
  1360. DragFinish(hDropInfo);
  1361. }
  1362. BOOL CMakeSetupDialog::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  1363. {
  1364. CDialog::OnSetCursor(pWnd, nHitTest, message);
  1365. if(m_Cursor == LoadCursor(NULL, IDC_WAIT))
  1366. {
  1367. ::SetCursor(m_Cursor);
  1368. }
  1369. return true;
  1370. }