FirstConfigure.cxx 18 KB

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