cmDebuggerVariablesHelper.cxx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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 "cmDebuggerVariablesHelper.h"
  4. #include <algorithm>
  5. #include <cstddef>
  6. #include <functional>
  7. #include <iomanip>
  8. #include <map>
  9. #include <sstream>
  10. #include "cm_codecvt.hxx"
  11. #include "cmDebuggerStackFrame.h"
  12. #include "cmDebuggerVariables.h"
  13. #include "cmFileSet.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmList.h"
  16. #include "cmListFileCache.h"
  17. #include "cmMakefile.h"
  18. #include "cmPropertyMap.h"
  19. #include "cmState.h"
  20. #include "cmStateSnapshot.h"
  21. #include "cmTarget.h"
  22. #include "cmTest.h"
  23. #include "cmValue.h"
  24. #include "cmake.h"
  25. namespace cmDebugger {
  26. std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::Create(
  27. std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager,
  28. std::string const& name, bool supportsVariableType,
  29. cmPolicies::PolicyMap const& policyMap)
  30. {
  31. static std::map<cmPolicies::PolicyStatus, std::string> policyStatusString = {
  32. { cmPolicies::PolicyStatus::OLD, "OLD" },
  33. { cmPolicies::PolicyStatus::WARN, "WARN" },
  34. { cmPolicies::PolicyStatus::NEW, "NEW" },
  35. { cmPolicies::PolicyStatus::REQUIRED_IF_USED, "REQUIRED_IF_USED" },
  36. { cmPolicies::PolicyStatus::REQUIRED_ALWAYS, "REQUIRED_ALWAYS" }
  37. };
  38. return std::make_shared<cmDebuggerVariables>(
  39. variablesManager, name, supportsVariableType, [=]() {
  40. std::vector<cmDebuggerVariableEntry> ret;
  41. ret.reserve(cmPolicies::CMPCOUNT);
  42. for (int i = 0; i < cmPolicies::CMPCOUNT; ++i) {
  43. if (policyMap.IsDefined(static_cast<cmPolicies::PolicyID>(i))) {
  44. auto status = policyMap.Get(static_cast<cmPolicies::PolicyID>(i));
  45. std::ostringstream ss;
  46. ss << "CMP" << std::setfill('0') << std::setw(4) << i;
  47. ret.emplace_back(ss.str(), policyStatusString[status]);
  48. }
  49. }
  50. return ret;
  51. });
  52. }
  53. std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny(
  54. std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager,
  55. std::string const& name, bool supportsVariableType,
  56. std::vector<std::pair<std::string, std::string>> const& list)
  57. {
  58. if (list.empty()) {
  59. return {};
  60. }
  61. auto listVariables = std::make_shared<cmDebuggerVariables>(
  62. variablesManager, name, supportsVariableType, [=]() {
  63. std::vector<cmDebuggerVariableEntry> ret;
  64. ret.reserve(list.size());
  65. for (auto const& kv : list) {
  66. ret.emplace_back(kv.first, kv.second);
  67. }
  68. return ret;
  69. });
  70. listVariables->SetValue(std::to_string(list.size()));
  71. return listVariables;
  72. }
  73. std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny(
  74. std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager,
  75. std::string const& name, bool supportsVariableType,
  76. cmBTStringRange const& entries)
  77. {
  78. if (entries.empty()) {
  79. return {};
  80. }
  81. auto sourceEntries = std::make_shared<cmDebuggerVariables>(
  82. variablesManager, name, supportsVariableType);
  83. for (auto const& entry : entries) {
  84. auto arrayVariables = std::make_shared<cmDebuggerVariables>(
  85. variablesManager, entry.Value, supportsVariableType, [=]() {
  86. cmList items{ entry.Value };
  87. std::vector<cmDebuggerVariableEntry> ret;
  88. ret.reserve(items.size());
  89. int i = 0;
  90. for (std::string const& item : items) {
  91. ret.emplace_back("[" + std::to_string(i++) + "]", item);
  92. }
  93. return ret;
  94. });
  95. arrayVariables->SetEnableSorting(false);
  96. sourceEntries->AddSubVariables(arrayVariables);
  97. }
  98. sourceEntries->SetValue(std::to_string(entries.size()));
  99. return sourceEntries;
  100. }
  101. std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny(
  102. std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager,
  103. std::string const& name, bool supportsVariableType,
  104. std::set<std::string> const& values)
  105. {
  106. if (values.empty()) {
  107. return {};
  108. }
  109. auto arrayVariables = std::make_shared<cmDebuggerVariables>(
  110. variablesManager, name, supportsVariableType, [=]() {
  111. std::vector<cmDebuggerVariableEntry> ret;
  112. ret.reserve(values.size());
  113. int i = 0;
  114. for (std::string const& value : values) {
  115. ret.emplace_back("[" + std::to_string(i++) + "]", value);
  116. }
  117. return ret;
  118. });
  119. arrayVariables->SetValue(std::to_string(values.size()));
  120. arrayVariables->SetEnableSorting(false);
  121. return arrayVariables;
  122. }
  123. std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny(
  124. std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager,
  125. std::string const& name, bool supportsVariableType,
  126. std::vector<std::string> const& values)
  127. {
  128. if (values.empty()) {
  129. return {};
  130. }
  131. auto arrayVariables = std::make_shared<cmDebuggerVariables>(
  132. variablesManager, name, supportsVariableType, [=]() {
  133. std::vector<cmDebuggerVariableEntry> ret;
  134. ret.reserve(values.size());
  135. int i = 0;
  136. for (std::string const& value : values) {
  137. ret.emplace_back("[" + std::to_string(i++) + "]", value);
  138. }
  139. return ret;
  140. });
  141. arrayVariables->SetValue(std::to_string(values.size()));
  142. arrayVariables->SetEnableSorting(false);
  143. return arrayVariables;
  144. }
  145. std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny(
  146. std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager,
  147. std::string const& name, bool supportsVariableType,
  148. std::vector<BT<std::string>> const& list)
  149. {
  150. if (list.empty()) {
  151. return {};
  152. }
  153. auto variables = std::make_shared<cmDebuggerVariables>(
  154. variablesManager, name, supportsVariableType, [=]() {
  155. std::vector<cmDebuggerVariableEntry> ret;
  156. ret.reserve(list.size());
  157. int i = 0;
  158. for (auto const& item : list) {
  159. ret.emplace_back("[" + std::to_string(i++) + "]", item.Value);
  160. }
  161. return ret;
  162. });
  163. variables->SetValue(std::to_string(list.size()));
  164. variables->SetEnableSorting(false);
  165. return variables;
  166. }
  167. std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny(
  168. std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager,
  169. std::string const& name, bool supportsVariableType, cmFileSet* fileSet)
  170. {
  171. if (fileSet == nullptr) {
  172. return {};
  173. }
  174. static auto visibilityString = [](cmFileSetVisibility visibility) {
  175. switch (visibility) {
  176. case cmFileSetVisibility::Private:
  177. return "Private";
  178. case cmFileSetVisibility::Public:
  179. return "Public";
  180. case cmFileSetVisibility::Interface:
  181. return "Interface";
  182. default:
  183. return "Unknown";
  184. }
  185. };
  186. auto variables = std::make_shared<cmDebuggerVariables>(
  187. variablesManager, name, supportsVariableType, [=]() {
  188. std::vector<cmDebuggerVariableEntry> ret{
  189. { "Name", fileSet->GetName() },
  190. { "Type", fileSet->GetType() },
  191. { "Visibility", visibilityString(fileSet->GetVisibility()) },
  192. };
  193. return ret;
  194. });
  195. variables->AddSubVariables(CreateIfAny(variablesManager, "Directories",
  196. supportsVariableType,
  197. fileSet->GetDirectoryEntries()));
  198. variables->AddSubVariables(CreateIfAny(variablesManager, "Files",
  199. supportsVariableType,
  200. fileSet->GetFileEntries()));
  201. return variables;
  202. }
  203. std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny(
  204. std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager,
  205. std::string const& name, bool supportsVariableType,
  206. std::vector<cmFileSet*> const& fileSets)
  207. {
  208. if (fileSets.empty()) {
  209. return {};
  210. }
  211. auto fileSetsVariables = std::make_shared<cmDebuggerVariables>(
  212. variablesManager, name, supportsVariableType);
  213. for (auto const& fileSet : fileSets) {
  214. fileSetsVariables->AddSubVariables(CreateIfAny(
  215. variablesManager, fileSet->GetName(), supportsVariableType, fileSet));
  216. }
  217. return fileSetsVariables;
  218. }
  219. std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny(
  220. std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager,
  221. std::string const& name, bool supportsVariableType,
  222. std::vector<cmTarget*> const& targets)
  223. {
  224. if (targets.empty()) {
  225. return {};
  226. }
  227. auto targetsVariables = std::make_shared<cmDebuggerVariables>(
  228. variablesManager, name, supportsVariableType);
  229. for (auto const& target : targets) {
  230. auto targetVariables = std::make_shared<cmDebuggerVariables>(
  231. variablesManager, target->GetName(), supportsVariableType, [=]() {
  232. std::vector<cmDebuggerVariableEntry> ret = {
  233. { "InstallPath", target->GetInstallPath() },
  234. { "IsAIX", target->IsAIX() },
  235. { "IsAndroidGuiExecutable", target->IsAndroidGuiExecutable() },
  236. { "IsAppBundleOnApple", target->IsAppBundleOnApple() },
  237. { "IsDLLPlatform", target->IsDLLPlatform() },
  238. { "IsExecutableWithExports", target->IsExecutableWithExports() },
  239. { "IsFrameworkOnApple", target->IsFrameworkOnApple() },
  240. { "IsImported", target->IsImported() },
  241. { "IsImportedGloballyVisible", target->IsImportedGloballyVisible() },
  242. { "IsPerConfig", target->IsPerConfig() },
  243. { "Name", target->GetName() },
  244. { "RuntimeInstallPath", target->GetRuntimeInstallPath() },
  245. { "Type", cmState::GetTargetTypeName(target->GetType()) },
  246. };
  247. return ret;
  248. });
  249. targetVariables->SetValue(cmState::GetTargetTypeName(target->GetType()));
  250. targetVariables->AddSubVariables(Create(variablesManager, "PolicyMap",
  251. supportsVariableType,
  252. target->GetPolicyMap()));
  253. targetVariables->AddSubVariables(
  254. CreateIfAny(variablesManager, "Properties", supportsVariableType,
  255. target->GetProperties().GetList()));
  256. targetVariables->AddSubVariables(
  257. CreateIfAny(variablesManager, "IncludeDirectories", supportsVariableType,
  258. target->GetIncludeDirectoriesEntries()));
  259. targetVariables->AddSubVariables(CreateIfAny(variablesManager, "Sources",
  260. supportsVariableType,
  261. target->GetSourceEntries()));
  262. targetVariables->AddSubVariables(
  263. CreateIfAny(variablesManager, "CompileDefinitions", supportsVariableType,
  264. target->GetCompileDefinitionsEntries()));
  265. targetVariables->AddSubVariables(
  266. CreateIfAny(variablesManager, "CompileFeatures", supportsVariableType,
  267. target->GetCompileFeaturesEntries()));
  268. targetVariables->AddSubVariables(
  269. CreateIfAny(variablesManager, "CompileOptions", supportsVariableType,
  270. target->GetCompileOptionsEntries()));
  271. targetVariables->AddSubVariables(CreateIfAny(
  272. variablesManager, "CxxModuleHeaderSets", supportsVariableType,
  273. target->GetCxxModuleHeaderSetsEntries()));
  274. targetVariables->AddSubVariables(
  275. CreateIfAny(variablesManager, "CxxModuleSets", supportsVariableType,
  276. target->GetCxxModuleSetsEntries()));
  277. targetVariables->AddSubVariables(
  278. CreateIfAny(variablesManager, "HeaderSets", supportsVariableType,
  279. target->GetHeaderSetsEntries()));
  280. targetVariables->AddSubVariables(CreateIfAny(
  281. variablesManager, "InterfaceCxxModuleHeaderSets", supportsVariableType,
  282. target->GetInterfaceCxxModuleHeaderSetsEntries()));
  283. targetVariables->AddSubVariables(CreateIfAny(
  284. variablesManager, "InterfaceHeaderSets", supportsVariableType,
  285. target->GetInterfaceHeaderSetsEntries()));
  286. targetVariables->AddSubVariables(
  287. CreateIfAny(variablesManager, "LinkDirectories", supportsVariableType,
  288. target->GetLinkDirectoriesEntries()));
  289. targetVariables->AddSubVariables(CreateIfAny(
  290. variablesManager, "LinkImplementations", supportsVariableType,
  291. target->GetLinkImplementationEntries()));
  292. targetVariables->AddSubVariables(CreateIfAny(
  293. variablesManager, "LinkInterfaceDirects", supportsVariableType,
  294. target->GetLinkInterfaceDirectEntries()));
  295. targetVariables->AddSubVariables(CreateIfAny(
  296. variablesManager, "LinkInterfaceDirectExcludes", supportsVariableType,
  297. target->GetLinkInterfaceDirectExcludeEntries()));
  298. targetVariables->AddSubVariables(
  299. CreateIfAny(variablesManager, "LinkInterfaces", supportsVariableType,
  300. target->GetLinkInterfaceEntries()));
  301. targetVariables->AddSubVariables(
  302. CreateIfAny(variablesManager, "LinkOptions", supportsVariableType,
  303. target->GetLinkOptionsEntries()));
  304. targetVariables->AddSubVariables(CreateIfAny(
  305. variablesManager, "SystemIncludeDirectories", supportsVariableType,
  306. target->GetSystemIncludeDirectories()));
  307. targetVariables->AddSubVariables(CreateIfAny(variablesManager, "Makefile",
  308. supportsVariableType,
  309. target->GetMakefile()));
  310. targetVariables->AddSubVariables(
  311. CreateIfAny(variablesManager, "GlobalGenerator", supportsVariableType,
  312. target->GetGlobalGenerator()));
  313. std::vector<cmFileSet*> allFileSets;
  314. auto allFileSetNames = target->GetAllFileSetNames();
  315. allFileSets.reserve(allFileSetNames.size());
  316. for (auto const& fileSetName : allFileSetNames) {
  317. allFileSets.emplace_back(target->GetFileSet(fileSetName));
  318. }
  319. targetVariables->AddSubVariables(CreateIfAny(
  320. variablesManager, "AllFileSets", supportsVariableType, allFileSets));
  321. std::vector<cmFileSet*> allInterfaceFileSets;
  322. auto allInterfaceFileSetNames = target->GetAllInterfaceFileSets();
  323. allInterfaceFileSets.reserve(allInterfaceFileSetNames.size());
  324. for (auto const& interfaceFileSetName : allInterfaceFileSetNames) {
  325. allInterfaceFileSets.emplace_back(
  326. target->GetFileSet(interfaceFileSetName));
  327. }
  328. targetVariables->AddSubVariables(
  329. CreateIfAny(variablesManager, "AllInterfaceFileSets",
  330. supportsVariableType, allInterfaceFileSets));
  331. targetVariables->SetIgnoreEmptyStringEntries(true);
  332. targetsVariables->AddSubVariables(targetVariables);
  333. }
  334. targetsVariables->SetValue(std::to_string(targets.size()));
  335. return targetsVariables;
  336. }
  337. std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::Create(
  338. std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager,
  339. std::string const& name, bool supportsVariableType,
  340. std::shared_ptr<cmDebuggerStackFrame> const& frame)
  341. {
  342. auto variables = std::make_shared<cmDebuggerVariables>(
  343. variablesManager, name, supportsVariableType, [=]() {
  344. return std::vector<cmDebuggerVariableEntry>{ { "CurrentLine",
  345. frame->GetLine() } };
  346. });
  347. auto closureKeys = frame->GetMakefile()->GetStateSnapshot().ClosureKeys();
  348. auto locals = std::make_shared<cmDebuggerVariables>(
  349. variablesManager, "Locals", supportsVariableType, [=]() {
  350. std::vector<cmDebuggerVariableEntry> ret;
  351. ret.reserve(closureKeys.size());
  352. for (auto const& key : closureKeys) {
  353. ret.emplace_back(
  354. key, frame->GetMakefile()->GetStateSnapshot().GetDefinition(key));
  355. }
  356. return ret;
  357. });
  358. locals->SetValue(std::to_string(closureKeys.size()));
  359. variables->AddSubVariables(locals);
  360. std::function<bool(std::string const&)> isDirectory =
  361. [](std::string const& key) {
  362. size_t pos1 = key.rfind("_DIR");
  363. size_t pos2 = key.rfind("_DIRECTORY");
  364. return !((pos1 == std::string::npos || pos1 != key.size() - 4) &&
  365. (pos2 == std::string::npos || pos2 != key.size() - 10));
  366. };
  367. auto directorySize =
  368. std::count_if(closureKeys.begin(), closureKeys.end(), isDirectory);
  369. auto directories = std::make_shared<cmDebuggerVariables>(
  370. variablesManager, "Directories", supportsVariableType, [=]() {
  371. std::vector<cmDebuggerVariableEntry> ret;
  372. ret.reserve(directorySize);
  373. for (auto const& key : closureKeys) {
  374. if (isDirectory(key)) {
  375. ret.emplace_back(
  376. key, frame->GetMakefile()->GetStateSnapshot().GetDefinition(key));
  377. }
  378. }
  379. return ret;
  380. });
  381. directories->SetValue(std::to_string(directorySize));
  382. variables->AddSubVariables(directories);
  383. auto cacheVariables = std::make_shared<cmDebuggerVariables>(
  384. variablesManager, "CacheVariables", supportsVariableType);
  385. auto* state = frame->GetMakefile()->GetCMakeInstance()->GetState();
  386. auto keys = state->GetCacheEntryKeys();
  387. for (auto const& key : keys) {
  388. auto entry = std::make_shared<cmDebuggerVariables>(
  389. variablesManager,
  390. key + ":" +
  391. cmState::CacheEntryTypeToString(state->GetCacheEntryType(key)),
  392. supportsVariableType, [=]() {
  393. std::vector<cmDebuggerVariableEntry> ret;
  394. auto properties = state->GetCacheEntryPropertyList(key);
  395. ret.reserve(properties.size() + 2);
  396. for (auto const& propertyName : properties) {
  397. ret.emplace_back(propertyName,
  398. state->GetCacheEntryProperty(key, propertyName));
  399. }
  400. ret.emplace_back(
  401. "TYPE",
  402. cmState::CacheEntryTypeToString(state->GetCacheEntryType(key)));
  403. ret.emplace_back("VALUE", state->GetCacheEntryValue(key));
  404. return ret;
  405. });
  406. entry->SetValue(state->GetCacheEntryValue(key));
  407. cacheVariables->AddSubVariables(entry);
  408. }
  409. cacheVariables->SetValue(std::to_string(keys.size()));
  410. variables->AddSubVariables(cacheVariables);
  411. auto targetVariables =
  412. CreateIfAny(variablesManager, "Targets", supportsVariableType,
  413. frame->GetMakefile()->GetOrderedTargets());
  414. variables->AddSubVariables(targetVariables);
  415. std::vector<cmTest*> tests;
  416. frame->GetMakefile()->GetTests(
  417. frame->GetMakefile()->GetDefaultConfiguration(), tests);
  418. variables->AddSubVariables(
  419. CreateIfAny(variablesManager, "Tests", supportsVariableType, tests));
  420. return variables;
  421. }
  422. std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny(
  423. std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager,
  424. std::string const& name, bool supportsVariableType, cmTest* test)
  425. {
  426. if (test == nullptr) {
  427. return {};
  428. }
  429. auto variables = std::make_shared<cmDebuggerVariables>(
  430. variablesManager, name, supportsVariableType, [=]() {
  431. std::vector<cmDebuggerVariableEntry> ret{
  432. { "CommandExpandLists", test->GetCommandExpandLists() },
  433. { "Name", test->GetName() },
  434. { "OldStyle", test->GetOldStyle() },
  435. };
  436. return ret;
  437. });
  438. variables->AddSubVariables(CreateIfAny(
  439. variablesManager, "Command", supportsVariableType, test->GetCommand()));
  440. variables->AddSubVariables(CreateIfAny(variablesManager, "Properties",
  441. supportsVariableType,
  442. test->GetProperties().GetList()));
  443. return variables;
  444. }
  445. std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny(
  446. std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager,
  447. std::string const& name, bool supportsVariableType,
  448. std::vector<cmTest*> const& tests)
  449. {
  450. if (tests.empty()) {
  451. return {};
  452. }
  453. auto variables = std::make_shared<cmDebuggerVariables>(
  454. variablesManager, name, supportsVariableType);
  455. for (auto const& test : tests) {
  456. variables->AddSubVariables(CreateIfAny(variablesManager, test->GetName(),
  457. supportsVariableType, test));
  458. }
  459. variables->SetValue(std::to_string(tests.size()));
  460. return variables;
  461. }
  462. std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny(
  463. std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager,
  464. std::string const& name, bool supportsVariableType, cmMakefile* mf)
  465. {
  466. if (mf == nullptr) {
  467. return {};
  468. }
  469. auto AppleSDKTypeString = [&](cmMakefile::AppleSDK sdk) {
  470. switch (sdk) {
  471. case cmMakefile::AppleSDK::MacOS:
  472. return "MacOS";
  473. case cmMakefile::AppleSDK::IPhoneOS:
  474. return "IPhoneOS";
  475. case cmMakefile::AppleSDK::IPhoneSimulator:
  476. return "IPhoneSimulator";
  477. case cmMakefile::AppleSDK::AppleTVOS:
  478. return "AppleTVOS";
  479. case cmMakefile::AppleSDK::AppleTVSimulator:
  480. return "AppleTVSimulator";
  481. default:
  482. return "Unknown";
  483. }
  484. };
  485. auto variables = std::make_shared<cmDebuggerVariables>(
  486. variablesManager, name, supportsVariableType, [=]() {
  487. std::vector<cmDebuggerVariableEntry> ret = {
  488. { "DefineFlags", mf->GetDefineFlags() },
  489. { "DirectoryId", mf->GetDirectoryId().String },
  490. { "IsRootMakefile", mf->IsRootMakefile() },
  491. { "HomeDirectory", mf->GetHomeDirectory() },
  492. { "HomeOutputDirectory", mf->GetHomeOutputDirectory() },
  493. { "CurrentSourceDirectory", mf->GetCurrentSourceDirectory() },
  494. { "CurrentBinaryDirectory", mf->GetCurrentBinaryDirectory() },
  495. { "PlatformIs32Bit", mf->PlatformIs32Bit() },
  496. { "PlatformIs64Bit", mf->PlatformIs64Bit() },
  497. { "PlatformIsx32", mf->PlatformIsx32() },
  498. { "AppleSDKType", AppleSDKTypeString(mf->GetAppleSDKType()) },
  499. { "PlatformIsAppleEmbedded", mf->PlatformIsAppleEmbedded() }
  500. };
  501. return ret;
  502. });
  503. variables->AddSubVariables(CreateIfAny(
  504. variablesManager, "ListFiles", supportsVariableType, mf->GetListFiles()));
  505. variables->AddSubVariables(CreateIfAny(variablesManager, "OutputFiles",
  506. supportsVariableType,
  507. mf->GetOutputFiles()));
  508. variables->SetIgnoreEmptyStringEntries(true);
  509. variables->SetValue(mf->GetDirectoryId().String);
  510. return variables;
  511. }
  512. std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny(
  513. std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager,
  514. std::string const& name, bool supportsVariableType, cmGlobalGenerator* gen)
  515. {
  516. if (gen == nullptr) {
  517. return {};
  518. }
  519. auto makeFileEncodingString = [](codecvt::Encoding encoding) {
  520. switch (encoding) {
  521. case codecvt::Encoding::None:
  522. return "None";
  523. case codecvt::Encoding::UTF8:
  524. return "UTF8";
  525. case codecvt::Encoding::UTF8_WITH_BOM:
  526. return "UTF8_WITH_BOM";
  527. case codecvt::Encoding::ANSI:
  528. return "ANSI";
  529. case codecvt::Encoding::ConsoleOutput:
  530. return "ConsoleOutput";
  531. default:
  532. return "Unknown";
  533. }
  534. };
  535. auto variables = std::make_shared<cmDebuggerVariables>(
  536. variablesManager, name, supportsVariableType, [=]() {
  537. std::vector<cmDebuggerVariableEntry> ret = {
  538. { "AllTargetName", gen->GetAllTargetName() },
  539. { "CleanTargetName", gen->GetCleanTargetName() },
  540. { "EditCacheCommand", gen->GetEditCacheCommand() },
  541. { "EditCacheTargetName", gen->GetEditCacheTargetName() },
  542. { "ExtraGeneratorName", gen->GetExtraGeneratorName() },
  543. { "ForceUnixPaths", gen->GetForceUnixPaths() },
  544. { "InstallLocalTargetName", gen->GetInstallLocalTargetName() },
  545. { "InstallStripTargetName", gen->GetInstallStripTargetName() },
  546. { "InstallTargetName", gen->GetInstallTargetName() },
  547. { "IsMultiConfig", gen->IsMultiConfig() },
  548. { "Name", gen->GetName() },
  549. { "MakefileEncoding",
  550. makeFileEncodingString(gen->GetMakefileEncoding()) },
  551. { "PackageSourceTargetName", gen->GetPackageSourceTargetName() },
  552. { "PackageTargetName", gen->GetPackageTargetName() },
  553. { "PreinstallTargetName", gen->GetPreinstallTargetName() },
  554. { "NeedSymbolicMark", gen->GetNeedSymbolicMark() },
  555. { "RebuildCacheTargetName", gen->GetRebuildCacheTargetName() },
  556. { "TestTargetName", gen->GetTestTargetName() },
  557. { "UseLinkScript", gen->GetUseLinkScript() },
  558. };
  559. return ret;
  560. });
  561. if (gen->GetInstallComponents() != nullptr) {
  562. variables->AddSubVariables(
  563. CreateIfAny(variablesManager, "InstallComponents", supportsVariableType,
  564. *gen->GetInstallComponents()));
  565. }
  566. variables->SetIgnoreEmptyStringEntries(true);
  567. variables->SetValue(gen->GetName());
  568. return variables;
  569. }
  570. } // namespace cmDebugger