QCMake.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "QCMake.h"
  4. #include <algorithm>
  5. #include <cm/memory>
  6. #include "QCMakeSizeType.h"
  7. #include <QCoreApplication>
  8. #include <QDir>
  9. #include <QString>
  10. #include <QVector>
  11. #include "cmExternalMakefileProjectGenerator.h"
  12. #include "cmGlobalGenerator.h"
  13. #include "cmMessageMetadata.h"
  14. #include "cmState.h"
  15. #include "cmStringAlgorithms.h"
  16. #include "cmSystemTools.h"
  17. #ifdef Q_OS_WIN
  18. # include "qt_windows.h" // For SetErrorMode
  19. #endif
  20. QCMake::QCMake(QObject* p)
  21. : QObject(p)
  22. , StartEnvironment(QProcessEnvironment::systemEnvironment())
  23. , Environment(QProcessEnvironment::systemEnvironment())
  24. {
  25. this->WarnUninitializedMode = false;
  26. qRegisterMetaType<QCMakeProperty>();
  27. qRegisterMetaType<QCMakePropertyList>();
  28. qRegisterMetaType<QProcessEnvironment>();
  29. qRegisterMetaType<QVector<QCMakePreset>>();
  30. cmSystemTools::DisableRunCommandOutput();
  31. cmSystemTools::SetRunCommandHideConsole(true);
  32. cmSystemTools::SetMessageCallback(
  33. [this](std::string const& msg, const cmMessageMetadata& md) {
  34. this->messageCallback(msg, md.title);
  35. });
  36. cmSystemTools::SetStdoutCallback(
  37. [this](std::string const& msg) { this->stdoutCallback(msg); });
  38. cmSystemTools::SetStderrCallback(
  39. [this](std::string const& msg) { this->stderrCallback(msg); });
  40. this->CMakeInstance =
  41. cm::make_unique<cmake>(cmake::RoleProject, cmState::Project);
  42. this->CMakeInstance->SetCMakeEditCommand(
  43. cmSystemTools::GetCMakeGUICommand());
  44. this->CMakeInstance->SetProgressCallback(
  45. [this](const std::string& msg, float percent) {
  46. this->progressCallback(msg, percent);
  47. });
  48. cmSystemTools::SetInterruptCallback(
  49. [this] { return this->interruptCallback(); });
  50. std::vector<cmake::GeneratorInfo> generators;
  51. this->CMakeInstance->GetRegisteredGenerators(
  52. generators, /*includeNamesWithPlatform=*/false);
  53. for (cmake::GeneratorInfo const& gen : generators) {
  54. this->AvailableGenerators.push_back(gen);
  55. }
  56. connect(&this->LoadPresetsTimer, &QTimer::timeout, this, [this]() {
  57. this->loadPresets();
  58. if (!this->PresetName.isEmpty() &&
  59. this->CMakePresetsGraph.ConfigurePresets.find(
  60. std::string(this->PresetName.toStdString())) ==
  61. this->CMakePresetsGraph.ConfigurePresets.end()) {
  62. this->setPreset(QString{});
  63. }
  64. });
  65. this->LoadPresetsTimer.start(1000);
  66. }
  67. QCMake::~QCMake() = default;
  68. void QCMake::loadCache(const QString& dir)
  69. {
  70. this->setBinaryDirectory(dir);
  71. }
  72. void QCMake::setSourceDirectory(const QString& _dir)
  73. {
  74. QString dir = QString::fromStdString(
  75. cmSystemTools::GetActualCaseForPath(_dir.toStdString()));
  76. if (this->SourceDirectory != dir) {
  77. this->SourceDirectory = QDir::fromNativeSeparators(dir);
  78. emit this->sourceDirChanged(this->SourceDirectory);
  79. this->loadPresets();
  80. this->setPreset(QString{});
  81. if (!cmSystemTools::FileIsFullPath(
  82. this->MaybeRelativeBinaryDirectory.toStdString())) {
  83. this->setBinaryDirectory(this->MaybeRelativeBinaryDirectory);
  84. }
  85. }
  86. }
  87. void QCMake::setBinaryDirectory(const QString& _dir)
  88. {
  89. QString dir = QString::fromStdString(
  90. cmSystemTools::GetActualCaseForPath(_dir.toStdString()));
  91. QString absDir = dir;
  92. if (!cmSystemTools::FileIsFullPath(absDir.toStdString())) {
  93. if (!this->SourceDirectory.isEmpty()) {
  94. if (!this->SourceDirectory.endsWith("/")) {
  95. absDir = "/" + absDir;
  96. }
  97. absDir = this->SourceDirectory + absDir;
  98. }
  99. }
  100. if (this->BinaryDirectory != absDir ||
  101. this->MaybeRelativeBinaryDirectory != dir) {
  102. this->MaybeRelativeBinaryDirectory = QDir::fromNativeSeparators(dir);
  103. this->BinaryDirectory = QDir::fromNativeSeparators(absDir);
  104. emit this->binaryDirChanged(this->MaybeRelativeBinaryDirectory);
  105. cmState* state = this->CMakeInstance->GetState();
  106. this->setGenerator(QString());
  107. this->setToolset(QString());
  108. this->setPlatform(QString());
  109. if (!this->CMakeInstance->LoadCache(this->BinaryDirectory.toStdString())) {
  110. QDir testDir(this->BinaryDirectory);
  111. if (testDir.exists("CMakeCache.txt")) {
  112. cmSystemTools::Error(
  113. "There is a CMakeCache.txt file for the current binary "
  114. "tree but cmake does not have permission to read it. "
  115. "Please check the permissions of the directory you are trying to "
  116. "run CMake on.");
  117. }
  118. }
  119. QCMakePropertyList props = this->properties();
  120. emit this->propertiesChanged(props);
  121. cmValue homeDir = state->GetCacheEntryValue("CMAKE_HOME_DIRECTORY");
  122. if (homeDir) {
  123. setSourceDirectory(QString(homeDir->c_str()));
  124. }
  125. cmValue gen = state->GetCacheEntryValue("CMAKE_GENERATOR");
  126. if (gen) {
  127. cmValue extraGen =
  128. state->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
  129. std::string curGen =
  130. cmExternalMakefileProjectGenerator::CreateFullGeneratorName(*gen,
  131. *extraGen);
  132. this->setGenerator(QString::fromStdString(curGen));
  133. }
  134. cmValue platform = state->GetCacheEntryValue("CMAKE_GENERATOR_PLATFORM");
  135. if (platform) {
  136. this->setPlatform(QString(platform->c_str()));
  137. }
  138. cmValue toolset = state->GetCacheEntryValue("CMAKE_GENERATOR_TOOLSET");
  139. if (toolset) {
  140. this->setToolset(QString(toolset->c_str()));
  141. }
  142. checkOpenPossible();
  143. }
  144. }
  145. void QCMake::setPreset(const QString& name, bool setBinary)
  146. {
  147. if (this->PresetName != name) {
  148. this->PresetName = name;
  149. emit this->presetChanged(this->PresetName);
  150. if (!name.isNull()) {
  151. std::string presetName(name.toStdString());
  152. auto const& expandedPreset =
  153. this->CMakePresetsGraph.ConfigurePresets[presetName].Expanded;
  154. if (expandedPreset) {
  155. if (setBinary && !expandedPreset->BinaryDir.empty()) {
  156. QString binaryDir =
  157. QString::fromStdString(expandedPreset->BinaryDir);
  158. this->setBinaryDirectory(binaryDir);
  159. }
  160. if (expandedPreset->WarnDev) {
  161. this->CMakeInstance->SetSuppressDevWarnings(
  162. !*expandedPreset->WarnDev);
  163. }
  164. if (expandedPreset->ErrorDev) {
  165. this->CMakeInstance->SetDevWarningsAsErrors(
  166. *expandedPreset->ErrorDev);
  167. }
  168. if (expandedPreset->WarnDeprecated) {
  169. this->CMakeInstance->SetSuppressDeprecatedWarnings(
  170. !*expandedPreset->WarnDeprecated);
  171. }
  172. if (expandedPreset->ErrorDeprecated) {
  173. this->CMakeInstance->SetDeprecatedWarningsAsErrors(
  174. *expandedPreset->ErrorDeprecated);
  175. }
  176. if (expandedPreset->WarnUninitialized) {
  177. this->WarnUninitializedMode = *expandedPreset->WarnUninitialized;
  178. emit this->warnUninitializedModeChanged(
  179. *expandedPreset->WarnUninitialized);
  180. }
  181. this->Environment = this->StartEnvironment;
  182. for (auto const& v : expandedPreset->Environment) {
  183. if (v.second) {
  184. this->Environment.insert(QString::fromStdString(v.first),
  185. QString::fromStdString(v.second.value()));
  186. }
  187. }
  188. }
  189. }
  190. emit this->propertiesChanged(this->properties());
  191. }
  192. }
  193. void QCMake::setGenerator(const QString& gen)
  194. {
  195. if (this->Generator != gen) {
  196. this->Generator = gen;
  197. emit this->generatorChanged(this->Generator);
  198. }
  199. }
  200. void QCMake::setPlatform(const QString& platform)
  201. {
  202. if (this->Platform != platform) {
  203. this->Platform = platform;
  204. emit this->platformChanged(this->Platform);
  205. }
  206. }
  207. void QCMake::setToolset(const QString& toolset)
  208. {
  209. if (this->Toolset != toolset) {
  210. this->Toolset = toolset;
  211. emit this->toolsetChanged(this->Toolset);
  212. }
  213. }
  214. void QCMake::setEnvironment(const QProcessEnvironment& environment)
  215. {
  216. this->Environment = environment;
  217. }
  218. void QCMake::configure()
  219. {
  220. int err;
  221. {
  222. cmSystemTools::SaveRestoreEnvironment restoreEnv;
  223. this->setUpEnvironment();
  224. #ifdef Q_OS_WIN
  225. UINT lastErrorMode = SetErrorMode(0);
  226. #endif
  227. // Apply the same transformations that the command-line invocation does
  228. auto sanitizePath = [](QString const& value) -> std::string {
  229. return cmSystemTools::ToNormalizedPathOnDisk(value.toStdString());
  230. };
  231. this->CMakeInstance->SetHomeDirectory(sanitizePath(this->SourceDirectory));
  232. this->CMakeInstance->SetHomeOutputDirectory(
  233. sanitizePath(this->BinaryDirectory));
  234. this->CMakeInstance->SetGlobalGenerator(
  235. this->CMakeInstance->CreateGlobalGenerator(
  236. this->Generator.toStdString()));
  237. this->CMakeInstance->SetGeneratorPlatform(this->Platform.toStdString());
  238. this->CMakeInstance->SetGeneratorToolset(this->Toolset.toStdString());
  239. this->CMakeInstance->LoadCache();
  240. this->CMakeInstance->SetWarnUninitialized(this->WarnUninitializedMode);
  241. this->CMakeInstance->PreLoadCMakeFiles();
  242. InterruptFlag = 0;
  243. cmSystemTools::ResetErrorOccurredFlag();
  244. err = this->CMakeInstance->Configure();
  245. #ifdef Q_OS_WIN
  246. SetErrorMode(lastErrorMode);
  247. #endif
  248. }
  249. emit this->propertiesChanged(this->properties());
  250. emit this->configureDone(err);
  251. }
  252. void QCMake::generate()
  253. {
  254. int err;
  255. {
  256. cmSystemTools::SaveRestoreEnvironment restoreEnv;
  257. this->setUpEnvironment();
  258. #ifdef Q_OS_WIN
  259. UINT lastErrorMode = SetErrorMode(0);
  260. #endif
  261. InterruptFlag = 0;
  262. cmSystemTools::ResetErrorOccurredFlag();
  263. err = this->CMakeInstance->Generate();
  264. #ifdef Q_OS_WIN
  265. SetErrorMode(lastErrorMode);
  266. #endif
  267. }
  268. emit this->generateDone(err);
  269. checkOpenPossible();
  270. }
  271. void QCMake::open()
  272. {
  273. #ifdef Q_OS_WIN
  274. UINT lastErrorMode = SetErrorMode(0);
  275. #endif
  276. InterruptFlag = 0;
  277. cmSystemTools::ResetErrorOccurredFlag();
  278. auto successful =
  279. this->CMakeInstance->Open(this->BinaryDirectory.toStdString(), false);
  280. #ifdef Q_OS_WIN
  281. SetErrorMode(lastErrorMode);
  282. #endif
  283. emit this->openDone(successful);
  284. }
  285. void QCMake::setProperties(const QCMakePropertyList& newProps)
  286. {
  287. QCMakePropertyList props = newProps;
  288. QStringList toremove;
  289. // set the value of properties
  290. cmState* state = this->CMakeInstance->GetState();
  291. std::vector<std::string> cacheKeys = state->GetCacheEntryKeys();
  292. for (std::string const& key : cacheKeys) {
  293. cmStateEnums::CacheEntryType t = state->GetCacheEntryType(key);
  294. if (t == cmStateEnums::INTERNAL || t == cmStateEnums::STATIC) {
  295. continue;
  296. }
  297. QCMakeProperty prop;
  298. prop.Key = QString::fromStdString(key);
  299. cm_qsizetype idx = props.indexOf(prop);
  300. if (idx == -1) {
  301. toremove.append(QString::fromStdString(key));
  302. } else {
  303. prop = props[idx];
  304. #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
  305. const bool isBool = prop.Value.type() == QVariant::Bool;
  306. #else
  307. const bool isBool = prop.Value.metaType() == QMetaType::fromType<bool>();
  308. #endif
  309. if (isBool) {
  310. state->SetCacheEntryValue(key, prop.Value.toBool() ? "ON" : "OFF");
  311. } else {
  312. state->SetCacheEntryValue(key, prop.Value.toString().toStdString());
  313. }
  314. props.removeAt(idx);
  315. }
  316. }
  317. // remove some properties
  318. foreach (QString const& s, toremove) {
  319. this->CMakeInstance->UnwatchUnusedCli(s.toStdString());
  320. state->RemoveCacheEntry(s.toStdString());
  321. }
  322. // add some new properties
  323. foreach (QCMakeProperty const& s, props) {
  324. this->CMakeInstance->WatchUnusedCli(s.Key.toStdString());
  325. if (s.Type == QCMakeProperty::BOOL) {
  326. this->CMakeInstance->AddCacheEntry(
  327. s.Key.toStdString(), s.Value.toBool() ? "ON" : "OFF",
  328. s.Help.toStdString(), cmStateEnums::BOOL);
  329. } else if (s.Type == QCMakeProperty::STRING) {
  330. this->CMakeInstance->AddCacheEntry(
  331. s.Key.toStdString(), s.Value.toString().toStdString(),
  332. s.Help.toStdString(), cmStateEnums::STRING);
  333. } else if (s.Type == QCMakeProperty::PATH) {
  334. this->CMakeInstance->AddCacheEntry(
  335. s.Key.toStdString(), s.Value.toString().toStdString(),
  336. s.Help.toStdString(), cmStateEnums::PATH);
  337. } else if (s.Type == QCMakeProperty::FILEPATH) {
  338. this->CMakeInstance->AddCacheEntry(
  339. s.Key.toStdString(), s.Value.toString().toStdString(),
  340. s.Help.toStdString(), cmStateEnums::FILEPATH);
  341. }
  342. }
  343. this->CMakeInstance->SaveCache(this->BinaryDirectory.toStdString());
  344. }
  345. namespace {
  346. template <typename T>
  347. QCMakeProperty cache_to_property(const T& v)
  348. {
  349. QCMakeProperty prop;
  350. prop.Key = QString::fromStdString(v.first);
  351. prop.Value = QString::fromStdString(v.second->Value);
  352. prop.Type = QCMakeProperty::STRING;
  353. if (!v.second->Type.empty()) {
  354. auto type = cmState::StringToCacheEntryType(v.second->Type);
  355. switch (type) {
  356. case cmStateEnums::BOOL:
  357. prop.Type = QCMakeProperty::BOOL;
  358. prop.Value = cmIsOn(v.second->Value);
  359. break;
  360. case cmStateEnums::PATH:
  361. prop.Type = QCMakeProperty::PATH;
  362. break;
  363. case cmStateEnums::FILEPATH:
  364. prop.Type = QCMakeProperty::FILEPATH;
  365. break;
  366. default:
  367. prop.Type = QCMakeProperty::STRING;
  368. break;
  369. }
  370. }
  371. return prop;
  372. }
  373. void add_to_property_list(QCMakePropertyList& list, QCMakeProperty&& prop)
  374. {
  375. // QCMakeCacheModel prefers variables earlier in the list rather than
  376. // later, so overwrite them if they already exist rather than simply
  377. // appending
  378. bool found = false;
  379. for (auto& orig : list) {
  380. if (orig.Key == prop.Key) {
  381. orig = prop;
  382. found = true;
  383. break;
  384. }
  385. }
  386. if (!found) {
  387. list.append(prop);
  388. }
  389. }
  390. }
  391. QCMakePropertyList QCMake::properties() const
  392. {
  393. QCMakePropertyList ret;
  394. cmState* state = this->CMakeInstance->GetState();
  395. std::vector<std::string> cacheKeys = state->GetCacheEntryKeys();
  396. for (std::string const& key : cacheKeys) {
  397. cmStateEnums::CacheEntryType t = state->GetCacheEntryType(key);
  398. if (t == cmStateEnums::INTERNAL || t == cmStateEnums::STATIC ||
  399. t == cmStateEnums::UNINITIALIZED) {
  400. continue;
  401. }
  402. cmValue cachedValue = state->GetCacheEntryValue(key);
  403. QCMakeProperty prop;
  404. prop.Key = QString::fromStdString(key);
  405. if (cmValue hs = state->GetCacheEntryProperty(key, "HELPSTRING")) {
  406. prop.Help = QString(hs->c_str());
  407. }
  408. prop.Value = QString(cachedValue->c_str());
  409. prop.Advanced = state->GetCacheEntryPropertyAsBool(key, "ADVANCED");
  410. if (t == cmStateEnums::BOOL) {
  411. prop.Type = QCMakeProperty::BOOL;
  412. prop.Value = cmIsOn(*cachedValue);
  413. } else if (t == cmStateEnums::PATH) {
  414. prop.Type = QCMakeProperty::PATH;
  415. } else if (t == cmStateEnums::FILEPATH) {
  416. prop.Type = QCMakeProperty::FILEPATH;
  417. } else if (t == cmStateEnums::STRING) {
  418. prop.Type = QCMakeProperty::STRING;
  419. cmValue stringsProperty = state->GetCacheEntryProperty(key, "STRINGS");
  420. if (stringsProperty) {
  421. prop.Strings = QString(stringsProperty->c_str()).split(";");
  422. }
  423. }
  424. ret.append(prop);
  425. }
  426. if (!this->PresetName.isNull()) {
  427. std::string presetName(this->PresetName.toStdString());
  428. auto const& p =
  429. this->CMakePresetsGraph.ConfigurePresets.at(presetName).Expanded;
  430. if (p) {
  431. if (!p->ToolchainFile.empty()) {
  432. using CacheVariable = cmCMakePresetsGraph::CacheVariable;
  433. CacheVariable var{ "FILEPATH", p->ToolchainFile };
  434. std::pair<std::string, cm::optional<CacheVariable>> value = {
  435. "CMAKE_TOOLCHAIN_FILE", var
  436. };
  437. auto prop = cache_to_property(value);
  438. add_to_property_list(ret, std::move(prop));
  439. }
  440. for (auto const& v : p->CacheVariables) {
  441. if (!v.second) {
  442. continue;
  443. }
  444. auto prop = cache_to_property(v);
  445. add_to_property_list(ret, std::move(prop));
  446. }
  447. }
  448. }
  449. return ret;
  450. }
  451. void QCMake::interrupt()
  452. {
  453. this->InterruptFlag.ref();
  454. }
  455. bool QCMake::interruptCallback()
  456. {
  457. #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
  458. return this->InterruptFlag.load();
  459. #else
  460. return this->InterruptFlag.loadRelaxed();
  461. #endif
  462. }
  463. void QCMake::progressCallback(const std::string& msg, float percent)
  464. {
  465. if (percent >= 0) {
  466. emit this->progressChanged(QString::fromStdString(msg), percent);
  467. } else {
  468. emit this->outputMessage(QString::fromStdString(msg));
  469. }
  470. QCoreApplication::processEvents();
  471. }
  472. void QCMake::messageCallback(std::string const& msg, const char* /*title*/)
  473. {
  474. emit this->errorMessage(QString::fromStdString(msg));
  475. QCoreApplication::processEvents();
  476. }
  477. void QCMake::stdoutCallback(std::string const& msg)
  478. {
  479. emit this->outputMessage(QString::fromStdString(msg));
  480. QCoreApplication::processEvents();
  481. }
  482. void QCMake::stderrCallback(std::string const& msg)
  483. {
  484. emit this->outputMessage(QString::fromStdString(msg));
  485. QCoreApplication::processEvents();
  486. }
  487. void QCMake::setUpEnvironment() const
  488. {
  489. auto env = QProcessEnvironment::systemEnvironment();
  490. for (auto const& key : env.keys()) {
  491. cmSystemTools::UnsetEnv(key.toStdString().c_str());
  492. }
  493. for (auto const& var : this->Environment.toStringList()) {
  494. cmSystemTools::PutEnv(var.toStdString());
  495. }
  496. }
  497. void QCMake::loadPresets()
  498. {
  499. auto result = this->CMakePresetsGraph.ReadProjectPresets(
  500. this->SourceDirectory.toStdString(), true);
  501. if (result != this->LastLoadPresetsResult && !result) {
  502. emit this->presetLoadError(
  503. this->SourceDirectory,
  504. QString::fromStdString(
  505. this->CMakePresetsGraph.parseState.GetErrorMessage(false)));
  506. }
  507. this->LastLoadPresetsResult = result;
  508. QVector<QCMakePreset> presets;
  509. for (auto const& name : this->CMakePresetsGraph.ConfigurePresetOrder) {
  510. auto const& it = this->CMakePresetsGraph.ConfigurePresets[name];
  511. auto const& p = it.Unexpanded;
  512. if (p.Hidden) {
  513. continue;
  514. }
  515. QCMakePreset preset;
  516. preset.name = QString::fromStdString(p.Name);
  517. preset.displayName = QString::fromStdString(p.DisplayName);
  518. preset.description = QString::fromStdString(p.Description);
  519. preset.generator = QString::fromStdString(p.Generator);
  520. preset.architecture = QString::fromStdString(p.Architecture);
  521. preset.setArchitecture = !p.ArchitectureStrategy ||
  522. p.ArchitectureStrategy == cmCMakePresetsGraph::ArchToolsetStrategy::Set;
  523. preset.toolset = QString::fromStdString(p.Toolset);
  524. preset.setToolset = !p.ToolsetStrategy ||
  525. p.ToolsetStrategy == cmCMakePresetsGraph::ArchToolsetStrategy::Set;
  526. preset.enabled = it.Expanded && it.Expanded->ConditionResult &&
  527. std::find_if(this->AvailableGenerators.begin(),
  528. this->AvailableGenerators.end(),
  529. [&p](const cmake::GeneratorInfo& g) {
  530. return g.name == p.Generator;
  531. }) != this->AvailableGenerators.end();
  532. presets.push_back(preset);
  533. }
  534. emit this->presetsChanged(presets);
  535. }
  536. QString QCMake::binaryDirectory() const
  537. {
  538. return this->BinaryDirectory;
  539. }
  540. QString QCMake::relativeBinaryDirectory() const
  541. {
  542. return this->MaybeRelativeBinaryDirectory;
  543. }
  544. QString QCMake::sourceDirectory() const
  545. {
  546. return this->SourceDirectory;
  547. }
  548. QString QCMake::generator() const
  549. {
  550. return this->Generator;
  551. }
  552. QProcessEnvironment QCMake::environment() const
  553. {
  554. return this->Environment;
  555. }
  556. std::vector<cmake::GeneratorInfo> const& QCMake::availableGenerators() const
  557. {
  558. return AvailableGenerators;
  559. }
  560. void QCMake::deleteCache()
  561. {
  562. // delete cache
  563. this->CMakeInstance->DeleteCache(this->BinaryDirectory.toStdString());
  564. // reload to make our cache empty
  565. this->CMakeInstance->LoadCache(this->BinaryDirectory.toStdString());
  566. // emit no generator and no properties
  567. this->setGenerator(QString());
  568. this->setToolset(QString());
  569. QCMakePropertyList props = this->properties();
  570. emit this->propertiesChanged(props);
  571. }
  572. void QCMake::reloadCache()
  573. {
  574. // emit that the cache was cleaned out
  575. QCMakePropertyList props;
  576. emit this->propertiesChanged(props);
  577. // reload
  578. this->CMakeInstance->LoadCache(this->BinaryDirectory.toStdString());
  579. // emit new cache properties
  580. props = this->properties();
  581. emit this->propertiesChanged(props);
  582. }
  583. void QCMake::setDebugOutput(bool flag)
  584. {
  585. if (flag != this->CMakeInstance->GetDebugOutput()) {
  586. this->CMakeInstance->SetDebugOutputOn(flag);
  587. emit this->debugOutputChanged(flag);
  588. }
  589. }
  590. bool QCMake::getDebugOutput() const
  591. {
  592. return this->CMakeInstance->GetDebugOutput();
  593. }
  594. bool QCMake::getSuppressDevWarnings()
  595. {
  596. return this->CMakeInstance->GetSuppressDevWarnings();
  597. }
  598. void QCMake::setSuppressDevWarnings(bool value)
  599. {
  600. this->CMakeInstance->SetSuppressDevWarnings(value);
  601. }
  602. bool QCMake::getSuppressDeprecatedWarnings()
  603. {
  604. return this->CMakeInstance->GetSuppressDeprecatedWarnings();
  605. }
  606. void QCMake::setSuppressDeprecatedWarnings(bool value)
  607. {
  608. this->CMakeInstance->SetSuppressDeprecatedWarnings(value);
  609. }
  610. bool QCMake::getDevWarningsAsErrors()
  611. {
  612. return this->CMakeInstance->GetDevWarningsAsErrors();
  613. }
  614. void QCMake::setDevWarningsAsErrors(bool value)
  615. {
  616. this->CMakeInstance->SetDevWarningsAsErrors(value);
  617. }
  618. bool QCMake::getDeprecatedWarningsAsErrors()
  619. {
  620. return this->CMakeInstance->GetDeprecatedWarningsAsErrors();
  621. }
  622. void QCMake::setDeprecatedWarningsAsErrors(bool value)
  623. {
  624. this->CMakeInstance->SetDeprecatedWarningsAsErrors(value);
  625. }
  626. void QCMake::setWarnUninitializedMode(bool value)
  627. {
  628. this->WarnUninitializedMode = value;
  629. }
  630. void QCMake::checkOpenPossible()
  631. {
  632. std::string data = this->BinaryDirectory.toStdString();
  633. auto possible = this->CMakeInstance->Open(data, true);
  634. emit openPossible(possible);
  635. }