FirstConfigure.cxx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. #include "FirstConfigure.h"
  2. #include "Compilers.h"
  3. #include <QComboBox>
  4. #include <QRadioButton>
  5. #include <QSettings>
  6. #include <QVBoxLayout>
  7. StartCompilerSetup::StartCompilerSetup(QWidget* p)
  8. : QWizardPage(p)
  9. {
  10. QVBoxLayout* l = new QVBoxLayout(this);
  11. l->addWidget(new QLabel(tr("Specify the generator for this project")));
  12. this->GeneratorOptions = new QComboBox(this);
  13. l->addWidget(this->GeneratorOptions);
  14. // Add the ability to specify toolset (-T parameter)
  15. ToolsetFrame = CreateToolsetWidgets();
  16. l->addWidget(ToolsetFrame);
  17. l->addSpacing(6);
  18. this->CompilerSetupOptions[0] =
  19. new QRadioButton(tr("Use default native compilers"), this);
  20. this->CompilerSetupOptions[1] =
  21. new QRadioButton(tr("Specify native compilers"), this);
  22. this->CompilerSetupOptions[2] =
  23. new QRadioButton(tr("Specify toolchain file for cross-compiling"), this);
  24. this->CompilerSetupOptions[3] =
  25. new QRadioButton(tr("Specify options for cross-compiling"), this);
  26. l->addWidget(this->CompilerSetupOptions[0]);
  27. l->addWidget(this->CompilerSetupOptions[1]);
  28. l->addWidget(this->CompilerSetupOptions[2]);
  29. l->addWidget(this->CompilerSetupOptions[3]);
  30. this->CompilerSetupOptions[0]->setChecked(true);
  31. QObject::connect(this->CompilerSetupOptions[0], SIGNAL(toggled(bool)), this,
  32. SLOT(onSelectionChanged(bool)));
  33. QObject::connect(this->CompilerSetupOptions[1], SIGNAL(toggled(bool)), this,
  34. SLOT(onSelectionChanged(bool)));
  35. QObject::connect(this->CompilerSetupOptions[2], SIGNAL(toggled(bool)), this,
  36. SLOT(onSelectionChanged(bool)));
  37. QObject::connect(this->CompilerSetupOptions[3], SIGNAL(toggled(bool)), this,
  38. SLOT(onSelectionChanged(bool)));
  39. QObject::connect(GeneratorOptions,
  40. SIGNAL(currentIndexChanged(QString const&)), this,
  41. SLOT(onGeneratorChanged(QString const&)));
  42. }
  43. QFrame* StartCompilerSetup::CreateToolsetWidgets()
  44. {
  45. QFrame* frame = new QFrame(this);
  46. QVBoxLayout* l = new QVBoxLayout(frame);
  47. l->setContentsMargins(0, 0, 0, 0);
  48. ToolsetLabel = new QLabel(tr("Optional toolset to use (argument to -T)"));
  49. l->addWidget(ToolsetLabel);
  50. Toolset = new QLineEdit(frame);
  51. l->addWidget(Toolset);
  52. return frame;
  53. }
  54. StartCompilerSetup::~StartCompilerSetup()
  55. {
  56. }
  57. void StartCompilerSetup::setGenerators(
  58. std::vector<cmake::GeneratorInfo> const& gens)
  59. {
  60. this->GeneratorOptions->clear();
  61. QStringList generator_list;
  62. std::vector<cmake::GeneratorInfo>::const_iterator it;
  63. for (it = gens.begin(); it != gens.end(); ++it) {
  64. generator_list.append(QString::fromLocal8Bit(it->name.c_str()));
  65. if (it->supportsToolset) {
  66. this->GeneratorsSupportingToolset.append(
  67. QString::fromLocal8Bit(it->name.c_str()));
  68. }
  69. }
  70. this->GeneratorOptions->addItems(generator_list);
  71. }
  72. void StartCompilerSetup::setCurrentGenerator(const QString& gen)
  73. {
  74. int idx = this->GeneratorOptions->findText(gen);
  75. if (idx != -1) {
  76. this->GeneratorOptions->setCurrentIndex(idx);
  77. }
  78. }
  79. QString StartCompilerSetup::getGenerator() const
  80. {
  81. return this->GeneratorOptions->currentText();
  82. };
  83. QString StartCompilerSetup::getToolset() const
  84. {
  85. return this->Toolset->text();
  86. };
  87. bool StartCompilerSetup::defaultSetup() const
  88. {
  89. return this->CompilerSetupOptions[0]->isChecked();
  90. }
  91. bool StartCompilerSetup::compilerSetup() const
  92. {
  93. return this->CompilerSetupOptions[1]->isChecked();
  94. }
  95. bool StartCompilerSetup::crossCompilerToolChainFile() const
  96. {
  97. return this->CompilerSetupOptions[2]->isChecked();
  98. }
  99. bool StartCompilerSetup::crossCompilerSetup() const
  100. {
  101. return this->CompilerSetupOptions[3]->isChecked();
  102. }
  103. void StartCompilerSetup::onSelectionChanged(bool on)
  104. {
  105. if (on) {
  106. emit selectionChanged();
  107. }
  108. }
  109. void StartCompilerSetup::onGeneratorChanged(QString const& name)
  110. {
  111. if (GeneratorsSupportingToolset.contains(name)) {
  112. ToolsetFrame->show();
  113. } else {
  114. ToolsetFrame->hide();
  115. }
  116. }
  117. int StartCompilerSetup::nextId() const
  118. {
  119. if (compilerSetup()) {
  120. return NativeSetup;
  121. }
  122. if (crossCompilerSetup()) {
  123. return CrossSetup;
  124. }
  125. if (crossCompilerToolChainFile()) {
  126. return ToolchainSetup;
  127. }
  128. return -1;
  129. }
  130. NativeCompilerSetup::NativeCompilerSetup(QWidget* p)
  131. : QWizardPage(p)
  132. {
  133. QVBoxLayout* l = new QVBoxLayout(this);
  134. QWidget* c = new QWidget(this);
  135. l->addWidget(c);
  136. this->setupUi(c);
  137. }
  138. NativeCompilerSetup::~NativeCompilerSetup()
  139. {
  140. }
  141. QString NativeCompilerSetup::getCCompiler() const
  142. {
  143. return this->CCompiler->text();
  144. }
  145. void NativeCompilerSetup::setCCompiler(const QString& s)
  146. {
  147. this->CCompiler->setText(s);
  148. }
  149. QString NativeCompilerSetup::getCXXCompiler() const
  150. {
  151. return this->CXXCompiler->text();
  152. }
  153. void NativeCompilerSetup::setCXXCompiler(const QString& s)
  154. {
  155. this->CXXCompiler->setText(s);
  156. }
  157. QString NativeCompilerSetup::getFortranCompiler() const
  158. {
  159. return this->FortranCompiler->text();
  160. }
  161. void NativeCompilerSetup::setFortranCompiler(const QString& s)
  162. {
  163. this->FortranCompiler->setText(s);
  164. }
  165. CrossCompilerSetup::CrossCompilerSetup(QWidget* p)
  166. : QWizardPage(p)
  167. {
  168. this->setupUi(this);
  169. QWidget::setTabOrder(systemName, systemVersion);
  170. QWidget::setTabOrder(systemVersion, systemProcessor);
  171. QWidget::setTabOrder(systemProcessor, CrossCompilers->CCompiler);
  172. QWidget::setTabOrder(CrossCompilers->CCompiler, CrossCompilers->CXXCompiler);
  173. QWidget::setTabOrder(CrossCompilers->CXXCompiler,
  174. CrossCompilers->FortranCompiler);
  175. QWidget::setTabOrder(CrossCompilers->FortranCompiler, crossFindRoot);
  176. QWidget::setTabOrder(crossFindRoot, crossProgramMode);
  177. QWidget::setTabOrder(crossProgramMode, crossLibraryMode);
  178. QWidget::setTabOrder(crossLibraryMode, crossIncludeMode);
  179. // fill in combo boxes
  180. QStringList modes;
  181. modes << tr("Search in Target Root, then native system");
  182. modes << tr("Search only in Target Root");
  183. modes << tr("Search only in native system");
  184. crossProgramMode->addItems(modes);
  185. crossLibraryMode->addItems(modes);
  186. crossIncludeMode->addItems(modes);
  187. crossProgramMode->setCurrentIndex(2);
  188. crossLibraryMode->setCurrentIndex(1);
  189. crossIncludeMode->setCurrentIndex(1);
  190. this->registerField("systemName*", this->systemName);
  191. }
  192. CrossCompilerSetup::~CrossCompilerSetup()
  193. {
  194. }
  195. QString CrossCompilerSetup::getCCompiler() const
  196. {
  197. return this->CrossCompilers->CCompiler->text();
  198. }
  199. void CrossCompilerSetup::setCCompiler(const QString& s)
  200. {
  201. this->CrossCompilers->CCompiler->setText(s);
  202. }
  203. QString CrossCompilerSetup::getCXXCompiler() const
  204. {
  205. return this->CrossCompilers->CXXCompiler->text();
  206. }
  207. void CrossCompilerSetup::setCXXCompiler(const QString& s)
  208. {
  209. this->CrossCompilers->CXXCompiler->setText(s);
  210. }
  211. QString CrossCompilerSetup::getFortranCompiler() const
  212. {
  213. return this->CrossCompilers->FortranCompiler->text();
  214. }
  215. void CrossCompilerSetup::setFortranCompiler(const QString& s)
  216. {
  217. this->CrossCompilers->FortranCompiler->setText(s);
  218. }
  219. QString CrossCompilerSetup::getSystem() const
  220. {
  221. return this->systemName->text();
  222. }
  223. void CrossCompilerSetup::setSystem(const QString& t)
  224. {
  225. this->systemName->setText(t);
  226. }
  227. QString CrossCompilerSetup::getVersion() const
  228. {
  229. return this->systemVersion->text();
  230. }
  231. void CrossCompilerSetup::setVersion(const QString& t)
  232. {
  233. this->systemVersion->setText(t);
  234. }
  235. QString CrossCompilerSetup::getProcessor() const
  236. {
  237. return this->systemProcessor->text();
  238. }
  239. void CrossCompilerSetup::setProcessor(const QString& t)
  240. {
  241. this->systemProcessor->setText(t);
  242. }
  243. QString CrossCompilerSetup::getFindRoot() const
  244. {
  245. return this->crossFindRoot->text();
  246. }
  247. void CrossCompilerSetup::setFindRoot(const QString& t)
  248. {
  249. this->crossFindRoot->setText(t);
  250. }
  251. int CrossCompilerSetup::getProgramMode() const
  252. {
  253. return this->crossProgramMode->currentIndex();
  254. }
  255. int CrossCompilerSetup::getLibraryMode() const
  256. {
  257. return this->crossLibraryMode->currentIndex();
  258. }
  259. int CrossCompilerSetup::getIncludeMode() const
  260. {
  261. return this->crossIncludeMode->currentIndex();
  262. }
  263. void CrossCompilerSetup::setProgramMode(int m)
  264. {
  265. this->crossProgramMode->setCurrentIndex(m);
  266. }
  267. void CrossCompilerSetup::setLibraryMode(int m)
  268. {
  269. this->crossLibraryMode->setCurrentIndex(m);
  270. }
  271. void CrossCompilerSetup::setIncludeMode(int m)
  272. {
  273. this->crossIncludeMode->setCurrentIndex(m);
  274. }
  275. ToolchainCompilerSetup::ToolchainCompilerSetup(QWidget* p)
  276. : QWizardPage(p)
  277. {
  278. QVBoxLayout* l = new QVBoxLayout(this);
  279. l->addWidget(new QLabel(tr("Specify the Toolchain file")));
  280. this->ToolchainFile = new QCMakeFilePathEditor(this);
  281. l->addWidget(this->ToolchainFile);
  282. }
  283. ToolchainCompilerSetup::~ToolchainCompilerSetup()
  284. {
  285. }
  286. QString ToolchainCompilerSetup::toolchainFile() const
  287. {
  288. return this->ToolchainFile->text();
  289. }
  290. void ToolchainCompilerSetup::setToolchainFile(const QString& t)
  291. {
  292. this->ToolchainFile->setText(t);
  293. }
  294. FirstConfigure::FirstConfigure()
  295. {
  296. // this->setOption(QWizard::HaveFinishButtonOnEarlyPages, true);
  297. this->mStartCompilerSetupPage = new StartCompilerSetup(this);
  298. this->setPage(Start, this->mStartCompilerSetupPage);
  299. QObject::connect(this->mStartCompilerSetupPage, SIGNAL(selectionChanged()),
  300. this, SLOT(restart()));
  301. this->mNativeCompilerSetupPage = new NativeCompilerSetup(this);
  302. this->setPage(NativeSetup, this->mNativeCompilerSetupPage);
  303. this->mCrossCompilerSetupPage = new CrossCompilerSetup(this);
  304. this->setPage(CrossSetup, this->mCrossCompilerSetupPage);
  305. this->mToolchainCompilerSetupPage = new ToolchainCompilerSetup(this);
  306. this->setPage(ToolchainSetup, this->mToolchainCompilerSetupPage);
  307. }
  308. FirstConfigure::~FirstConfigure()
  309. {
  310. }
  311. void FirstConfigure::setGenerators(
  312. std::vector<cmake::GeneratorInfo> const& gens)
  313. {
  314. this->mStartCompilerSetupPage->setGenerators(gens);
  315. }
  316. QString FirstConfigure::getGenerator() const
  317. {
  318. return this->mStartCompilerSetupPage->getGenerator();
  319. }
  320. QString FirstConfigure::getToolset() const
  321. {
  322. return this->mStartCompilerSetupPage->getToolset();
  323. }
  324. void FirstConfigure::loadFromSettings()
  325. {
  326. QSettings settings;
  327. // restore generator
  328. settings.beginGroup("Settings/StartPath");
  329. QString lastGen = settings.value("LastGenerator").toString();
  330. this->mStartCompilerSetupPage->setCurrentGenerator(lastGen);
  331. settings.endGroup();
  332. // restore compiler setup
  333. settings.beginGroup("Settings/Compiler");
  334. this->mNativeCompilerSetupPage->setCCompiler(
  335. settings.value("CCompiler").toString());
  336. this->mNativeCompilerSetupPage->setCXXCompiler(
  337. settings.value("CXXCompiler").toString());
  338. this->mNativeCompilerSetupPage->setFortranCompiler(
  339. settings.value("FortranCompiler").toString());
  340. settings.endGroup();
  341. // restore cross compiler setup
  342. settings.beginGroup("Settings/CrossCompiler");
  343. this->mCrossCompilerSetupPage->setCCompiler(
  344. settings.value("CCompiler").toString());
  345. this->mCrossCompilerSetupPage->setCXXCompiler(
  346. settings.value("CXXCompiler").toString());
  347. this->mCrossCompilerSetupPage->setFortranCompiler(
  348. settings.value("FortranCompiler").toString());
  349. this->mToolchainCompilerSetupPage->setToolchainFile(
  350. settings.value("ToolChainFile").toString());
  351. this->mCrossCompilerSetupPage->setSystem(
  352. settings.value("SystemName").toString());
  353. this->mCrossCompilerSetupPage->setVersion(
  354. settings.value("SystemVersion").toString());
  355. this->mCrossCompilerSetupPage->setProcessor(
  356. settings.value("SystemProcessor").toString());
  357. this->mCrossCompilerSetupPage->setFindRoot(
  358. settings.value("FindRoot").toString());
  359. this->mCrossCompilerSetupPage->setProgramMode(
  360. settings.value("ProgramMode", 0).toInt());
  361. this->mCrossCompilerSetupPage->setLibraryMode(
  362. settings.value("LibraryMode", 0).toInt());
  363. this->mCrossCompilerSetupPage->setIncludeMode(
  364. settings.value("IncludeMode", 0).toInt());
  365. settings.endGroup();
  366. }
  367. void FirstConfigure::saveToSettings()
  368. {
  369. QSettings settings;
  370. // save generator
  371. settings.beginGroup("Settings/StartPath");
  372. QString lastGen = this->mStartCompilerSetupPage->getGenerator();
  373. settings.setValue("LastGenerator", lastGen);
  374. settings.endGroup();
  375. // save compiler setup
  376. settings.beginGroup("Settings/Compiler");
  377. settings.setValue("CCompiler",
  378. this->mNativeCompilerSetupPage->getCCompiler());
  379. settings.setValue("CXXCompiler",
  380. this->mNativeCompilerSetupPage->getCXXCompiler());
  381. settings.setValue("FortranCompiler",
  382. this->mNativeCompilerSetupPage->getFortranCompiler());
  383. settings.endGroup();
  384. // save cross compiler setup
  385. settings.beginGroup("Settings/CrossCompiler");
  386. settings.setValue("CCompiler",
  387. this->mCrossCompilerSetupPage->getCCompiler());
  388. settings.setValue("CXXCompiler",
  389. this->mCrossCompilerSetupPage->getCXXCompiler());
  390. settings.setValue("FortranCompiler",
  391. this->mCrossCompilerSetupPage->getFortranCompiler());
  392. settings.setValue("ToolChainFile", this->getCrossCompilerToolChainFile());
  393. settings.setValue("SystemName", this->mCrossCompilerSetupPage->getSystem());
  394. settings.setValue("SystemVersion",
  395. this->mCrossCompilerSetupPage->getVersion());
  396. settings.setValue("SystemProcessor",
  397. this->mCrossCompilerSetupPage->getProcessor());
  398. settings.setValue("FindRoot", this->mCrossCompilerSetupPage->getFindRoot());
  399. settings.setValue("ProgramMode",
  400. this->mCrossCompilerSetupPage->getProgramMode());
  401. settings.setValue("LibraryMode",
  402. this->mCrossCompilerSetupPage->getLibraryMode());
  403. settings.setValue("IncludeMode",
  404. this->mCrossCompilerSetupPage->getIncludeMode());
  405. settings.endGroup();
  406. }
  407. bool FirstConfigure::defaultSetup() const
  408. {
  409. return this->mStartCompilerSetupPage->defaultSetup();
  410. }
  411. bool FirstConfigure::compilerSetup() const
  412. {
  413. return this->mStartCompilerSetupPage->compilerSetup();
  414. }
  415. bool FirstConfigure::crossCompilerSetup() const
  416. {
  417. return this->mStartCompilerSetupPage->crossCompilerSetup();
  418. }
  419. bool FirstConfigure::crossCompilerToolChainFile() const
  420. {
  421. return this->mStartCompilerSetupPage->crossCompilerToolChainFile();
  422. }
  423. QString FirstConfigure::getCrossCompilerToolChainFile() const
  424. {
  425. return this->mToolchainCompilerSetupPage->toolchainFile();
  426. }
  427. QString FirstConfigure::getSystemName() const
  428. {
  429. return this->mCrossCompilerSetupPage->getSystem();
  430. }
  431. QString FirstConfigure::getCCompiler() const
  432. {
  433. if (this->compilerSetup()) {
  434. return this->mNativeCompilerSetupPage->getCCompiler();
  435. }
  436. if (this->crossCompilerSetup()) {
  437. return this->mCrossCompilerSetupPage->getCCompiler();
  438. }
  439. return QString();
  440. }
  441. QString FirstConfigure::getCXXCompiler() const
  442. {
  443. if (this->compilerSetup()) {
  444. return this->mNativeCompilerSetupPage->getCXXCompiler();
  445. }
  446. if (this->crossCompilerSetup()) {
  447. return this->mCrossCompilerSetupPage->getCXXCompiler();
  448. }
  449. return QString();
  450. }
  451. QString FirstConfigure::getFortranCompiler() const
  452. {
  453. if (this->compilerSetup()) {
  454. return this->mNativeCompilerSetupPage->getFortranCompiler();
  455. }
  456. if (this->crossCompilerSetup()) {
  457. return this->mCrossCompilerSetupPage->getFortranCompiler();
  458. }
  459. return QString();
  460. }
  461. QString FirstConfigure::getSystemVersion() const
  462. {
  463. return this->mCrossCompilerSetupPage->getVersion();
  464. }
  465. QString FirstConfigure::getSystemProcessor() const
  466. {
  467. return this->mCrossCompilerSetupPage->getProcessor();
  468. }
  469. QString FirstConfigure::getCrossRoot() const
  470. {
  471. return this->mCrossCompilerSetupPage->getFindRoot();
  472. }
  473. const QString CrossModes[] = { "BOTH", "ONLY", "NEVER" };
  474. QString FirstConfigure::getCrossProgramMode() const
  475. {
  476. return CrossModes[this->mCrossCompilerSetupPage->getProgramMode()];
  477. }
  478. QString FirstConfigure::getCrossLibraryMode() const
  479. {
  480. return CrossModes[this->mCrossCompilerSetupPage->getLibraryMode()];
  481. }
  482. QString FirstConfigure::getCrossIncludeMode() const
  483. {
  484. return CrossModes[this->mCrossCompilerSetupPage->getIncludeMode()];
  485. }