cmFindBase.cxx 19 KB

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