FirstConfigure.cxx 18 KB

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