cmFindBase.cxx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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 "cmFindBase.h"
  4. #include <cstddef>
  5. #include <deque>
  6. #include <map>
  7. #include <utility>
  8. #include <cm/optional>
  9. #include <cmext/algorithm>
  10. #include "cmCMakePath.h"
  11. #include "cmMakefile.h"
  12. #include "cmMessageType.h"
  13. #include "cmPolicies.h"
  14. #include "cmRange.h"
  15. #include "cmSearchPath.h"
  16. #include "cmState.h"
  17. #include "cmStateTypes.h"
  18. #include "cmStringAlgorithms.h"
  19. #include "cmSystemTools.h"
  20. #include "cmValue.h"
  21. #include "cmWindowsRegistry.h"
  22. #include "cmake.h"
  23. class cmExecutionStatus;
  24. cmFindBase::cmFindBase(std::string findCommandName, cmExecutionStatus& status)
  25. : cmFindCommon(status)
  26. , FindCommandName(std::move(findCommandName))
  27. {
  28. }
  29. bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
  30. {
  31. if (argsIn.size() < 2) {
  32. this->SetError("called with incorrect number of arguments");
  33. return false;
  34. }
  35. // copy argsIn into args so it can be modified,
  36. // in the process extract the DOC "documentation"
  37. // and handle options NO_CACHE and ENV
  38. size_t size = argsIn.size();
  39. std::vector<std::string> args;
  40. bool foundDoc = false;
  41. for (unsigned int j = 0; j < size; ++j) {
  42. if (foundDoc || argsIn[j] != "DOC") {
  43. if (argsIn[j] == "NO_CACHE") {
  44. this->StoreResultInCache = false;
  45. } else if (argsIn[j] == "ENV") {
  46. if (j + 1 < size) {
  47. j++;
  48. cmSystemTools::GetPath(args, argsIn[j].c_str());
  49. }
  50. } else {
  51. args.push_back(argsIn[j]);
  52. }
  53. } else {
  54. if (j + 1 < size) {
  55. foundDoc = true;
  56. this->VariableDocumentation = argsIn[j + 1];
  57. j++;
  58. if (j >= size) {
  59. break;
  60. }
  61. }
  62. }
  63. }
  64. if (args.size() < 2) {
  65. this->SetError("called with incorrect number of arguments");
  66. return false;
  67. }
  68. this->VariableName = args[0];
  69. if (this->CheckForVariableDefined()) {
  70. this->AlreadyDefined = true;
  71. return true;
  72. }
  73. // Find what search path locations have been enabled/disable
  74. this->SelectDefaultSearchModes();
  75. // Find the current root path mode.
  76. this->SelectDefaultRootPathMode();
  77. // Find the current bundle/framework search policy.
  78. this->SelectDefaultMacMode();
  79. bool newStyle = false;
  80. enum Doing
  81. {
  82. DoingNone,
  83. DoingNames,
  84. DoingPaths,
  85. DoingPathSuffixes,
  86. DoingHints
  87. };
  88. Doing doing = DoingNames; // assume it starts with a name
  89. for (unsigned int j = 1; j < args.size(); ++j) {
  90. if (args[j] == "NAMES") {
  91. doing = DoingNames;
  92. newStyle = true;
  93. } else if (args[j] == "PATHS") {
  94. doing = DoingPaths;
  95. newStyle = true;
  96. } else if (args[j] == "HINTS") {
  97. doing = DoingHints;
  98. newStyle = true;
  99. } else if (args[j] == "PATH_SUFFIXES") {
  100. doing = DoingPathSuffixes;
  101. newStyle = true;
  102. } else if (args[j] == "NAMES_PER_DIR") {
  103. doing = DoingNone;
  104. if (this->NamesPerDirAllowed) {
  105. this->NamesPerDir = true;
  106. } else {
  107. this->SetError("does not support NAMES_PER_DIR");
  108. return false;
  109. }
  110. } else if (args[j] == "NO_SYSTEM_PATH") {
  111. doing = DoingNone;
  112. this->NoDefaultPath = true;
  113. } else if (args[j] == "REQUIRED") {
  114. doing = DoingNone;
  115. this->Required = true;
  116. newStyle = true;
  117. } else if (args[j] == "REGISTRY_VIEW") {
  118. if (++j == args.size()) {
  119. this->SetError("missing required argument for \"REGISTRY_VIEW\"");
  120. return false;
  121. }
  122. auto view = cmWindowsRegistry::ToView(args[j]);
  123. if (view) {
  124. this->RegistryView = *view;
  125. } else {
  126. this->SetError(
  127. cmStrCat("given invalid value for \"REGISTRY_VIEW\": ", args[j]));
  128. return false;
  129. }
  130. } else if (this->CheckCommonArgument(args[j])) {
  131. doing = DoingNone;
  132. } else {
  133. // Some common arguments were accidentally supported by CMake
  134. // 2.4 and 2.6.0 in the short-hand form of the command, so we
  135. // must support it even though it is not documented.
  136. if (doing == DoingNames) {
  137. this->Names.push_back(args[j]);
  138. } else if (doing == DoingPaths) {
  139. this->UserGuessArgs.push_back(args[j]);
  140. } else if (doing == DoingHints) {
  141. this->UserHintsArgs.push_back(args[j]);
  142. } else if (doing == DoingPathSuffixes) {
  143. this->AddPathSuffix(args[j]);
  144. }
  145. }
  146. }
  147. if (this->VariableDocumentation.empty()) {
  148. this->VariableDocumentation = "Where can ";
  149. if (this->Names.empty()) {
  150. this->VariableDocumentation += "the (unknown) library be found";
  151. } else if (this->Names.size() == 1) {
  152. this->VariableDocumentation +=
  153. "the " + this->Names.front() + " library be found";
  154. } else {
  155. this->VariableDocumentation += "one of the ";
  156. this->VariableDocumentation +=
  157. cmJoin(cmMakeRange(this->Names).retreat(1), ", ");
  158. this->VariableDocumentation +=
  159. " or " + this->Names.back() + " libraries be found";
  160. }
  161. }
  162. // look for old style
  163. // FIND_*(VAR name path1 path2 ...)
  164. if (!newStyle && !this->Names.empty()) {
  165. // All the short-hand arguments have been recorded as names.
  166. std::vector<std::string> shortArgs = this->Names;
  167. this->Names.clear(); // clear out any values in Names
  168. this->Names.push_back(shortArgs[0]);
  169. cm::append(this->UserGuessArgs, shortArgs.begin() + 1, shortArgs.end());
  170. }
  171. this->ExpandPaths();
  172. this->ComputeFinalPaths(IgnorePaths::Yes);
  173. return true;
  174. }
  175. void cmFindBase::ExpandPaths()
  176. {
  177. if (!this->NoDefaultPath) {
  178. if (!this->NoPackageRootPath) {
  179. this->FillPackageRootPath();
  180. }
  181. if (!this->NoCMakePath) {
  182. this->FillCMakeVariablePath();
  183. }
  184. if (!this->NoCMakeEnvironmentPath) {
  185. this->FillCMakeEnvironmentPath();
  186. }
  187. }
  188. this->FillUserHintsPath();
  189. if (!this->NoDefaultPath) {
  190. if (!this->NoSystemEnvironmentPath) {
  191. this->FillSystemEnvironmentPath();
  192. }
  193. if (!this->NoCMakeSystemPath) {
  194. this->FillCMakeSystemVariablePath();
  195. }
  196. }
  197. this->FillUserGuessPath();
  198. }
  199. void cmFindBase::FillCMakeEnvironmentPath()
  200. {
  201. cmSearchPath& paths = this->LabeledPaths[PathLabel::CMakeEnvironment];
  202. // Add CMAKE_*_PATH environment variables
  203. std::string var = cmStrCat("CMAKE_", this->CMakePathName, "_PATH");
  204. paths.AddEnvPrefixPath("CMAKE_PREFIX_PATH");
  205. paths.AddEnvPath(var);
  206. if (this->CMakePathName == "PROGRAM") {
  207. paths.AddEnvPath("CMAKE_APPBUNDLE_PATH");
  208. } else {
  209. paths.AddEnvPath("CMAKE_FRAMEWORK_PATH");
  210. }
  211. paths.AddSuffixes(this->SearchPathSuffixes);
  212. }
  213. void cmFindBase::FillPackageRootPath()
  214. {
  215. cmSearchPath& paths = this->LabeledPaths[PathLabel::PackageRoot];
  216. // Add the PACKAGE_ROOT_PATH from each enclosing find_package call.
  217. for (std::vector<std::string> const& pkgPaths :
  218. cmReverseRange(this->Makefile->FindPackageRootPathStack)) {
  219. paths.AddPrefixPaths(pkgPaths);
  220. }
  221. paths.AddSuffixes(this->SearchPathSuffixes);
  222. }
  223. void cmFindBase::FillCMakeVariablePath()
  224. {
  225. cmSearchPath& paths = this->LabeledPaths[PathLabel::CMake];
  226. // Add CMake variables of the same name as the previous environment
  227. // variables CMAKE_*_PATH to be used most of the time with -D
  228. // command line options
  229. std::string var = cmStrCat("CMAKE_", this->CMakePathName, "_PATH");
  230. paths.AddCMakePrefixPath("CMAKE_PREFIX_PATH");
  231. paths.AddCMakePath(var);
  232. if (this->CMakePathName == "PROGRAM") {
  233. paths.AddCMakePath("CMAKE_APPBUNDLE_PATH");
  234. } else {
  235. paths.AddCMakePath("CMAKE_FRAMEWORK_PATH");
  236. }
  237. paths.AddSuffixes(this->SearchPathSuffixes);
  238. }
  239. void cmFindBase::FillSystemEnvironmentPath()
  240. {
  241. cmSearchPath& paths = this->LabeledPaths[PathLabel::SystemEnvironment];
  242. // Add LIB or INCLUDE
  243. if (!this->EnvironmentPath.empty()) {
  244. paths.AddEnvPath(this->EnvironmentPath);
  245. #if defined(_WIN32) || defined(__CYGWIN__)
  246. paths.AddEnvPrefixPath("PATH", true);
  247. #endif
  248. }
  249. // Add PATH
  250. paths.AddEnvPath("PATH");
  251. paths.AddSuffixes(this->SearchPathSuffixes);
  252. }
  253. void cmFindBase::FillCMakeSystemVariablePath()
  254. {
  255. cmSearchPath& paths = this->LabeledPaths[PathLabel::CMakeSystem];
  256. const bool install_prefix_in_list =
  257. !this->Makefile->IsOn("CMAKE_FIND_NO_INSTALL_PREFIX");
  258. const bool remove_install_prefix = this->NoCMakeInstallPath;
  259. const bool add_install_prefix = !this->NoCMakeInstallPath &&
  260. this->Makefile->IsDefinitionSet("CMAKE_FIND_USE_INSTALL_PREFIX");
  261. // We have 3 possible states for `CMAKE_SYSTEM_PREFIX_PATH` and
  262. // `CMAKE_INSTALL_PREFIX`.
  263. // Either we need to remove `CMAKE_INSTALL_PREFIX`, add
  264. // `CMAKE_INSTALL_PREFIX`, or do nothing.
  265. //
  266. // When we need to remove `CMAKE_INSTALL_PREFIX` we remove the Nth occurrence
  267. // of `CMAKE_INSTALL_PREFIX` from `CMAKE_SYSTEM_PREFIX_PATH`, where `N` is
  268. // computed by `CMakeSystemSpecificInformation.cmake` while constructing
  269. // `CMAKE_SYSTEM_PREFIX_PATH`. This ensures that if projects / toolchains
  270. // have removed `CMAKE_INSTALL_PREFIX` from the list, we don't remove
  271. // some other entry by mistake
  272. long install_prefix_count = -1;
  273. std::string install_path_to_remove;
  274. if (cmValue to_skip = this->Makefile->GetDefinition(
  275. "_CMAKE_SYSTEM_PREFIX_PATH_INSTALL_PREFIX_COUNT")) {
  276. cmStrToLong(to_skip, &install_prefix_count);
  277. }
  278. if (cmValue install_value = this->Makefile->GetDefinition(
  279. "_CMAKE_SYSTEM_PREFIX_PATH_INSTALL_PREFIX_VALUE")) {
  280. install_path_to_remove = *install_value;
  281. }
  282. if (remove_install_prefix && install_prefix_in_list &&
  283. install_prefix_count > 0 && !install_path_to_remove.empty()) {
  284. cmValue prefix_paths =
  285. this->Makefile->GetDefinition("CMAKE_SYSTEM_PREFIX_PATH");
  286. // remove entry from CMAKE_SYSTEM_PREFIX_PATH
  287. std::vector<std::string> expanded = cmExpandedList(*prefix_paths);
  288. long index_to_remove = 0;
  289. for (const auto& path : expanded) {
  290. if (path == install_path_to_remove && --install_prefix_count == 0) {
  291. break;
  292. }
  293. ++index_to_remove;
  294. }
  295. expanded.erase(expanded.begin() + index_to_remove);
  296. paths.AddPrefixPaths(expanded,
  297. this->Makefile->GetCurrentSourceDirectory().c_str());
  298. } else if (add_install_prefix && !install_prefix_in_list) {
  299. paths.AddCMakePrefixPath("CMAKE_INSTALL_PREFIX");
  300. paths.AddCMakePrefixPath("CMAKE_SYSTEM_PREFIX_PATH");
  301. } else {
  302. // Otherwise the current setup of `CMAKE_SYSTEM_PREFIX_PATH` is correct
  303. paths.AddCMakePrefixPath("CMAKE_SYSTEM_PREFIX_PATH");
  304. }
  305. std::string var = cmStrCat("CMAKE_SYSTEM_", this->CMakePathName, "_PATH");
  306. paths.AddCMakePath(var);
  307. if (this->CMakePathName == "PROGRAM") {
  308. paths.AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
  309. } else {
  310. paths.AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
  311. }
  312. paths.AddSuffixes(this->SearchPathSuffixes);
  313. }
  314. void cmFindBase::FillUserHintsPath()
  315. {
  316. cmSearchPath& paths = this->LabeledPaths[PathLabel::Hints];
  317. for (std::string const& p : this->UserHintsArgs) {
  318. paths.AddUserPath(p);
  319. }
  320. paths.AddSuffixes(this->SearchPathSuffixes);
  321. }
  322. void cmFindBase::FillUserGuessPath()
  323. {
  324. cmSearchPath& paths = this->LabeledPaths[PathLabel::Guess];
  325. for (std::string const& p : this->UserGuessArgs) {
  326. paths.AddUserPath(p);
  327. }
  328. paths.AddSuffixes(this->SearchPathSuffixes);
  329. }
  330. bool cmFindBase::CheckForVariableDefined()
  331. {
  332. if (cmValue value = this->Makefile->GetDefinition(this->VariableName)) {
  333. cmState* state = this->Makefile->GetState();
  334. cmValue cacheEntry = state->GetCacheEntryValue(this->VariableName);
  335. bool found = !cmIsNOTFOUND(*value);
  336. bool cached = cacheEntry != nullptr;
  337. auto cacheType = cached ? state->GetCacheEntryType(this->VariableName)
  338. : cmStateEnums::UNINITIALIZED;
  339. if (cached && cacheType != cmStateEnums::UNINITIALIZED) {
  340. this->VariableType = cacheType;
  341. if (const auto& hs =
  342. state->GetCacheEntryProperty(this->VariableName, "HELPSTRING")) {
  343. this->VariableDocumentation = *hs;
  344. }
  345. }
  346. if (found) {
  347. // If the user specifies the entry on the command line without a
  348. // type we should add the type and docstring but keep the
  349. // original value. Tell the subclass implementations to do
  350. // this.
  351. if (cached && cacheType == cmStateEnums::UNINITIALIZED) {
  352. this->AlreadyInCacheWithoutMetaInfo = true;
  353. }
  354. return true;
  355. }
  356. }
  357. return false;
  358. }
  359. void cmFindBase::NormalizeFindResult()
  360. {
  361. if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0125) ==
  362. cmPolicies::NEW) {
  363. // ensure the path returned by find_* command is absolute
  364. const auto& existingValue =
  365. this->Makefile->GetDefinition(this->VariableName);
  366. std::string value;
  367. if (!existingValue->empty()) {
  368. value =
  369. cmCMakePath(*existingValue, cmCMakePath::auto_format)
  370. .Absolute(cmCMakePath(
  371. this->Makefile->GetCMakeInstance()->GetCMakeWorkingDirectory()))
  372. .Normal()
  373. .GenericString();
  374. // value = cmSystemTools::CollapseFullPath(*existingValue);
  375. if (!cmSystemTools::FileExists(value, false)) {
  376. value = *existingValue;
  377. }
  378. }
  379. if (this->StoreResultInCache) {
  380. // If the user specifies the entry on the command line without a
  381. // type we should add the type and docstring but keep the original
  382. // value.
  383. if (value != *existingValue || this->AlreadyInCacheWithoutMetaInfo) {
  384. this->Makefile->GetCMakeInstance()->AddCacheEntry(
  385. this->VariableName, value, this->VariableDocumentation.c_str(),
  386. this->VariableType);
  387. if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) ==
  388. cmPolicies::NEW) {
  389. if (this->Makefile->IsNormalDefinitionSet(this->VariableName)) {
  390. this->Makefile->AddDefinition(this->VariableName, value);
  391. }
  392. } else {
  393. // if there was a definition then remove it
  394. // This is required to ensure same behavior as
  395. // cmMakefile::AddCacheDefinition.
  396. this->Makefile->RemoveDefinition(this->VariableName);
  397. }
  398. }
  399. } else {
  400. // ensure a normal variable is defined.
  401. this->Makefile->AddDefinition(this->VariableName, value);
  402. }
  403. } else {
  404. // If the user specifies the entry on the command line without a
  405. // type we should add the type and docstring but keep the original
  406. // value.
  407. if (this->StoreResultInCache) {
  408. if (this->AlreadyInCacheWithoutMetaInfo) {
  409. this->Makefile->AddCacheDefinition(this->VariableName, "",
  410. this->VariableDocumentation.c_str(),
  411. this->VariableType);
  412. if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) ==
  413. cmPolicies::NEW &&
  414. this->Makefile->IsNormalDefinitionSet(this->VariableName)) {
  415. this->Makefile->AddDefinition(
  416. this->VariableName,
  417. *this->Makefile->GetCMakeInstance()->GetCacheDefinition(
  418. this->VariableName));
  419. }
  420. }
  421. } else {
  422. // ensure a normal variable is defined.
  423. this->Makefile->AddDefinition(
  424. this->VariableName,
  425. this->Makefile->GetSafeDefinition(this->VariableName));
  426. }
  427. }
  428. }
  429. void cmFindBase::StoreFindResult(const std::string& value)
  430. {
  431. bool force =
  432. this->Makefile->GetPolicyStatus(cmPolicies::CMP0125) == cmPolicies::NEW;
  433. bool updateNormalVariable =
  434. this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) == cmPolicies::NEW;
  435. if (!value.empty()) {
  436. if (this->StoreResultInCache) {
  437. this->Makefile->AddCacheDefinition(this->VariableName, value,
  438. this->VariableDocumentation.c_str(),
  439. this->VariableType, force);
  440. if (updateNormalVariable &&
  441. this->Makefile->IsNormalDefinitionSet(this->VariableName)) {
  442. this->Makefile->AddDefinition(this->VariableName, value);
  443. }
  444. } else {
  445. this->Makefile->AddDefinition(this->VariableName, value);
  446. }
  447. return;
  448. }
  449. auto notFound = cmStrCat(this->VariableName, "-NOTFOUND");
  450. if (this->StoreResultInCache) {
  451. this->Makefile->AddCacheDefinition(this->VariableName, notFound,
  452. this->VariableDocumentation.c_str(),
  453. this->VariableType, force);
  454. if (updateNormalVariable &&
  455. this->Makefile->IsNormalDefinitionSet(this->VariableName)) {
  456. this->Makefile->AddDefinition(this->VariableName, notFound);
  457. }
  458. } else {
  459. this->Makefile->AddDefinition(this->VariableName, notFound);
  460. }
  461. if (this->Required) {
  462. this->Makefile->IssueMessage(
  463. MessageType::FATAL_ERROR,
  464. cmStrCat("Could not find ", this->VariableName, " using the following ",
  465. (this->FindCommandName == "find_file" ||
  466. this->FindCommandName == "find_path"
  467. ? "files"
  468. : "names"),
  469. ": ", cmJoin(this->Names, ", ")));
  470. cmSystemTools::SetFatalErrorOccured();
  471. }
  472. }
  473. cmFindBaseDebugState::cmFindBaseDebugState(std::string commandName,
  474. cmFindBase const* findBase)
  475. : FindCommand(findBase)
  476. , CommandName(std::move(commandName))
  477. {
  478. }
  479. cmFindBaseDebugState::~cmFindBaseDebugState()
  480. {
  481. if (this->FindCommand->DebugMode) {
  482. std::string buffer =
  483. cmStrCat(this->CommandName, " called with the following settings:\n");
  484. buffer += cmStrCat(" VAR: ", this->FindCommand->VariableName, "\n");
  485. buffer += cmStrCat(
  486. " NAMES: ", cmWrap("\"", this->FindCommand->Names, "\"", "\n "),
  487. "\n");
  488. buffer += cmStrCat(
  489. " Documentation: ", this->FindCommand->VariableDocumentation, "\n");
  490. buffer += " Framework\n";
  491. buffer += cmStrCat(" Only Search Frameworks: ",
  492. this->FindCommand->SearchFrameworkOnly, "\n");
  493. buffer += cmStrCat(" Search Frameworks Last: ",
  494. this->FindCommand->SearchFrameworkLast, "\n");
  495. buffer += cmStrCat(" Search Frameworks First: ",
  496. this->FindCommand->SearchFrameworkFirst, "\n");
  497. buffer += " AppBundle\n";
  498. buffer += cmStrCat(" Only Search AppBundle: ",
  499. this->FindCommand->SearchAppBundleOnly, "\n");
  500. buffer += cmStrCat(" Search AppBundle Last: ",
  501. this->FindCommand->SearchAppBundleLast, "\n");
  502. buffer += cmStrCat(" Search AppBundle First: ",
  503. this->FindCommand->SearchAppBundleFirst, "\n");
  504. if (this->FindCommand->NoDefaultPath) {
  505. buffer += " NO_DEFAULT_PATH Enabled\n";
  506. } else {
  507. buffer += cmStrCat(
  508. " CMAKE_FIND_USE_CMAKE_PATH: ", !this->FindCommand->NoCMakePath, "\n",
  509. " CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: ",
  510. !this->FindCommand->NoCMakeEnvironmentPath, "\n",
  511. " CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: ",
  512. !this->FindCommand->NoSystemEnvironmentPath, "\n",
  513. " CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: ",
  514. !this->FindCommand->NoCMakeSystemPath, "\n",
  515. " CMAKE_FIND_USE_INSTALL_PREFIX: ",
  516. !this->FindCommand->NoCMakeInstallPath, "\n");
  517. }
  518. buffer +=
  519. cmStrCat(this->CommandName, " considered the following locations:\n");
  520. for (auto const& state : this->FailedSearchLocations) {
  521. std::string path = cmStrCat(" ", state.path);
  522. if (!state.regexName.empty()) {
  523. path = cmStrCat(path, "/", state.regexName);
  524. }
  525. buffer += cmStrCat(path, "\n");
  526. }
  527. if (!this->FoundSearchLocation.path.empty()) {
  528. buffer += cmStrCat("The item was found at\n ",
  529. this->FoundSearchLocation.path, "\n");
  530. } else {
  531. buffer += "The item was not found.\n";
  532. }
  533. this->FindCommand->DebugMessage(buffer);
  534. }
  535. }
  536. void cmFindBaseDebugState::FoundAt(std::string const& path,
  537. std::string regexName)
  538. {
  539. if (this->FindCommand->DebugMode) {
  540. this->FoundSearchLocation = DebugLibState{ std::move(regexName), path };
  541. }
  542. }
  543. void cmFindBaseDebugState::FailedAt(std::string const& path,
  544. std::string regexName)
  545. {
  546. if (this->FindCommand->DebugMode) {
  547. this->FailedSearchLocations.emplace_back(std::move(regexName), path);
  548. }
  549. }