1
0

cmFindBase.cxx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmFindBase.h"
  14. cmFindBase::cmFindBase()
  15. {
  16. this->AlreadyInCache = false;
  17. this->AlreadyInCacheWithoutMetaInfo = false;
  18. this->NoDefaultPath = false;
  19. this->NoCMakePath = false;
  20. this->NoCMakeEnvironmentPath = false;
  21. this->NoSystemEnvironmentPath = false;
  22. this->NoCMakeSystemPath = false;
  23. // default is to search frameworks first on apple
  24. #if defined(__APPLE__)
  25. this->SearchFrameworkFirst = true;
  26. this->SearchAppBundleFirst = true;
  27. #else
  28. this->SearchFrameworkFirst = false;
  29. this->SearchAppBundleFirst = false;
  30. #endif
  31. this->SearchFrameworkOnly = false;
  32. this->SearchFrameworkLast = false;
  33. this->SearchAppBundleOnly = false;
  34. this->SearchAppBundleLast = false;
  35. this->GenericDocumentation =
  36. " FIND_XXX(<VAR> name1 path1 path2 ...)\n"
  37. "This is the short-hand signature for the command that "
  38. "is sufficient in many cases. It is the same "
  39. "as FIND_XXX(<VAR> name1 PATHS path2 path2 ...)\n"
  40. " FIND_XXX(\n"
  41. " <VAR> \n"
  42. " name | NAMES name1 [name2 ...]\n"
  43. " PATHS path1 [path2 ... ENV var]\n"
  44. " [PATH_SUFFIXES suffix1 [suffix2 ...]]\n"
  45. " [DOC \"cache documentation string\"]\n"
  46. " [NO_DEFAULT_PATH]\n"
  47. " [NO_CMAKE_ENVIRONMENT_PATH]\n"
  48. " [NO_CMAKE_PATH]\n"
  49. " [NO_SYSTEM_ENVIRONMENT_PATH]\n"
  50. " [NO_CMAKE_SYSTEM_PATH]\n"
  51. " )\n"
  52. ""
  53. "This command is used to find a SEARCH_XXX_DESC. "
  54. "A cache entry named by <VAR> is created to store the result "
  55. "of this command. "
  56. "If the SEARCH_XXX is found the result is stored in the variable "
  57. "and the search will not be repeated unless the variable is cleared. "
  58. "If nothing is found, the result will be "
  59. "<VAR>-NOTFOUND, and the search will be attempted again the "
  60. "next time FIND_XXX is invoked with the same variable. "
  61. "The name of the SEARCH_XXX that "
  62. "is searched for is specified by the names listed "
  63. "after the NAMES argument. Additional search locations "
  64. "can be specified after the PATHS argument. If ENV var is "
  65. "found in the PATHS section the environment variable var "
  66. "will be read and converted from a system environment variable to "
  67. "a cmake style list of paths. For example ENV PATH would be a way "
  68. "to list the system path variable. The argument "
  69. "after DOC will be used for the documentation string in "
  70. "the cache. PATH_SUFFIXES can be used to give sub directories "
  71. "that will be appended to the search paths.\n"
  72. "If NO_DEFAULT_PATH is specified, then no additional paths are "
  73. "added to the search. "
  74. "If NO_DEFAULT_PATH is not specified, the search process is as follows:\n"
  75. "1. Search cmake specific environment variables. This "
  76. "can be skipped if NO_CMAKE_ENVIRONMENT_PATH is passed.\n"
  77. ""
  78. " CMAKE_FRAMEWORK_PATH\n"
  79. " CMAKE_APPBUNDLE_PATH\n"
  80. " CMAKE_XXX_PATH\n"
  81. "2. Search cmake variables with the same names as "
  82. "the cmake specific environment variables. These "
  83. "are intended to be used on the command line with a "
  84. "-DVAR=value. This can be skipped if NO_CMAKE_PATH "
  85. "is passed.\n"
  86. ""
  87. " CMAKE_FRAMEWORK_PATH\n"
  88. " CMAKE_APPBUNDLE_PATH\n"
  89. " CMAKE_XXX_PATH\n"
  90. "3. Search the standard system environment variables. "
  91. "This can be skipped if NO_SYSTEM_ENVIRONMENT_PATH is an argument.\n"
  92. " PATH\n"
  93. " XXX_SYSTEM\n" // replace with "", LIB, or INCLUDE
  94. "4. Search cmake variables defined in the Platform files "
  95. "for the current system. This can be skipped if NO_CMAKE_SYSTEM_PATH "
  96. "is passed.\n"
  97. " CMAKE_SYSTEM_FRAMEWORK_PATH\n"
  98. " CMAKE_SYSTEM_APPBUNDLE_PATH\n"
  99. " CMAKE_SYSTEM_XXX_PATH\n"
  100. "5. Search the paths specified after PATHS or in the short-hand version "
  101. "of the command.\n"
  102. "On Darwin or systems supporting OSX Frameworks, the cmake variable"
  103. " CMAKE_FIND_FRAMEWORK can be set to empty or one of the following:\n"
  104. " \"FIRST\" - Try to find frameworks before standard\n"
  105. " libraries or headers. This is the default on Darwin.\n"
  106. " \"LAST\" - Try to find frameworks after standard\n"
  107. " libraries or headers.\n"
  108. " \"ONLY\" - Only try to find frameworks.\n"
  109. " \"NEVER\". - Never try to find frameworks.\n"
  110. "On Darwin or systems supporting OSX Application Bundles, the cmake "
  111. "variable CMAKE_FIND_APPBUNDLE can be set to empty or one of the "
  112. "following:\n"
  113. " \"FIRST\" - Try to find application bundles before standard\n"
  114. " programs. This is the default on Darwin.\n"
  115. " \"LAST\" - Try to find application bundles after standard\n"
  116. " programs.\n"
  117. " \"ONLY\" - Only try to find application bundles.\n"
  118. " \"NEVER\". - Never try to find application bundles.\n"
  119. "The reason the paths listed in the call to the command are searched "
  120. "last is that most users of CMake would expect things to be found "
  121. "first in the locations specified by their environment. Projects may "
  122. "override this behavior by simply calling the command twice:\n"
  123. " FIND_XXX(<VAR> NAMES name PATHS paths NO_DEFAULT_PATH)\n"
  124. " FIND_XXX(<VAR> NAMES name)\n"
  125. "Once one of these calls succeeds the result variable will be set "
  126. "and stored in the cache so that neither call will search again.";
  127. }
  128. bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
  129. {
  130. if(argsIn.size() < 2 )
  131. {
  132. this->SetError("called with incorrect number of arguments");
  133. return false;
  134. }
  135. std::string ff = this->Makefile->GetSafeDefinition("CMAKE_FIND_FRAMEWORK");
  136. if(ff == "NEVER")
  137. {
  138. this->SearchFrameworkLast = false;
  139. this->SearchFrameworkFirst = false;
  140. this->SearchFrameworkOnly = false;
  141. }
  142. else if (ff == "ONLY")
  143. {
  144. this->SearchFrameworkLast = false;
  145. this->SearchFrameworkFirst = false;
  146. this->SearchFrameworkOnly = true;
  147. }
  148. else if (ff == "FIRST")
  149. {
  150. this->SearchFrameworkLast = false;
  151. this->SearchFrameworkFirst = true;
  152. this->SearchFrameworkOnly = false;
  153. }
  154. else if (ff == "LAST")
  155. {
  156. this->SearchFrameworkLast = true;
  157. this->SearchFrameworkFirst = false;
  158. this->SearchFrameworkOnly = false;
  159. }
  160. std::string fab = this->Makefile->GetSafeDefinition("CMAKE_FIND_APPBUNDLE");
  161. if(fab == "NEVER")
  162. {
  163. this->SearchAppBundleLast = false;
  164. this->SearchAppBundleFirst = false;
  165. this->SearchAppBundleOnly = false;
  166. }
  167. else if (fab == "ONLY")
  168. {
  169. this->SearchAppBundleLast = false;
  170. this->SearchAppBundleFirst = false;
  171. this->SearchAppBundleOnly = true;
  172. }
  173. else if (fab == "FIRST")
  174. {
  175. this->SearchAppBundleLast = false;
  176. this->SearchAppBundleFirst = true;
  177. this->SearchAppBundleOnly = false;
  178. }
  179. else if (fab == "LAST")
  180. {
  181. this->SearchAppBundleLast = true;
  182. this->SearchAppBundleFirst = false;
  183. this->SearchAppBundleOnly = false;
  184. }
  185. // CMake versions below 2.3 did not search all these extra
  186. // locations. Preserve compatibility unless a modern argument is
  187. // passed.
  188. bool compatibility = false;
  189. const char* versionValue =
  190. this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  191. int major = 0;
  192. int minor = 0;
  193. if(versionValue && sscanf(versionValue, "%d.%d", &major, &minor) != 2)
  194. {
  195. versionValue = 0;
  196. }
  197. if(versionValue && (major < 2 || major == 2 && minor < 3))
  198. {
  199. compatibility = true;
  200. }
  201. // copy argsIn into args so it can be modified,
  202. // in the process extract the DOC "documentation"
  203. size_t size = argsIn.size();
  204. std::vector<std::string> args;
  205. bool foundDoc = false;
  206. for(unsigned int j = 0; j < size; ++j)
  207. {
  208. if(foundDoc || argsIn[j] != "DOC" )
  209. {
  210. if(argsIn[j] == "ENV")
  211. {
  212. if(j+1 < size)
  213. {
  214. j++;
  215. cmSystemTools::GetPath(args, argsIn[j].c_str());
  216. }
  217. }
  218. else
  219. {
  220. args.push_back(argsIn[j]);
  221. }
  222. }
  223. else
  224. {
  225. if(j+1 < size)
  226. {
  227. foundDoc = true;
  228. this->VariableDocumentation = argsIn[j+1];
  229. j++;
  230. if(j >= size)
  231. {
  232. break;
  233. }
  234. }
  235. }
  236. }
  237. this->VariableName = args[0];
  238. if(this->CheckForVariableInCache())
  239. {
  240. this->AlreadyInCache = true;
  241. return true;
  242. }
  243. this->AlreadyInCache = false;
  244. std::vector<std::string> userPaths;
  245. std::string doc;
  246. bool doingNames = true; // assume it starts with a name
  247. bool doingPaths = false;
  248. bool doingPathSuf = false;
  249. bool newStyle = false;
  250. for (unsigned int j = 1; j < args.size(); ++j)
  251. {
  252. if(args[j] == "NAMES")
  253. {
  254. doingNames = true;
  255. newStyle = true;
  256. doingPathSuf = false;
  257. doingPaths = false;
  258. }
  259. else if (args[j] == "PATHS")
  260. {
  261. doingPaths = true;
  262. newStyle = true;
  263. doingNames = false;
  264. doingPathSuf = false;
  265. }
  266. else if (args[j] == "PATH_SUFFIXES")
  267. {
  268. compatibility = false;
  269. doingPathSuf = true;
  270. newStyle = true;
  271. doingNames = false;
  272. doingPaths = false;
  273. }
  274. else if (args[j] == "NO_SYSTEM_PATH")
  275. {
  276. doingPaths = false;
  277. doingPathSuf = false;
  278. doingNames = false;
  279. this->NoDefaultPath = true;
  280. }
  281. else if (args[j] == "NO_DEFAULT_PATH")
  282. {
  283. compatibility = false;
  284. doingPaths = false;
  285. doingPathSuf = false;
  286. doingNames = false;
  287. this->NoDefaultPath = true;
  288. }
  289. else if (args[j] == "NO_CMAKE_ENVIRONMENT_PATH")
  290. {
  291. compatibility = false;
  292. doingPaths = false;
  293. doingPathSuf = false;
  294. doingNames = false;
  295. this->NoCMakeEnvironmentPath = true;
  296. }
  297. else if (args[j] == "NO_CMAKE_PATH")
  298. {
  299. compatibility = false;
  300. doingPaths = false;
  301. doingPathSuf = false;
  302. doingNames = false;
  303. this->NoCMakePath = true;
  304. }
  305. else if (args[j] == "NO_SYSTEM_ENVIRONMENT_PATH")
  306. {
  307. compatibility = false;
  308. doingPaths = false;
  309. doingPathSuf = false;
  310. doingNames = false;
  311. this->NoSystemEnvironmentPath = true;
  312. }
  313. else if (args[j] == "NO_CMAKE_SYSTEM_PATH")
  314. {
  315. compatibility = false;
  316. doingPaths = false;
  317. doingPathSuf = false;
  318. doingNames = false;
  319. this->NoCMakeSystemPath = true;
  320. }
  321. else
  322. {
  323. if(doingNames)
  324. {
  325. this->Names.push_back(args[j]);
  326. }
  327. else if(doingPaths)
  328. {
  329. userPaths.push_back(args[j]);
  330. }
  331. else if(doingPathSuf)
  332. {
  333. this->SearchPathSuffixes.push_back(args[j]);
  334. }
  335. }
  336. }
  337. // Now that arguments have been parsed check the compatibility
  338. // setting. If we need to be compatible with CMake 2.2 and earlier
  339. // do not add the CMake system paths. It is safe to add the CMake
  340. // environment paths and system environment paths because that
  341. // existed in 2.2. It is safe to add the CMake user variable paths
  342. // because the user or project has explicitly set them.
  343. if(compatibility)
  344. {
  345. this->NoCMakeSystemPath = true;
  346. }
  347. if(this->VariableDocumentation.size() == 0)
  348. {
  349. this->VariableDocumentation = "Whare can ";
  350. if(this->Names.size() == 0)
  351. {
  352. this->VariableDocumentation += "the (unknown) library be found";
  353. }
  354. else if(this->Names.size() == 1)
  355. {
  356. this->VariableDocumentation += "the "
  357. + this->Names[0] + " library be found";
  358. }
  359. else
  360. {
  361. this->VariableDocumentation += "one of the " + this->Names[0];
  362. for (unsigned int j = 1; j < this->Names.size() - 1; ++j)
  363. {
  364. this->VariableDocumentation += ", " + this->Names[j];
  365. }
  366. this->VariableDocumentation += " or "
  367. + this->Names[this->Names.size() - 1] + " libraries be found";
  368. }
  369. }
  370. // look for old style
  371. // FIND_*(VAR name path1 path2 ...)
  372. if(!newStyle)
  373. {
  374. this->Names.clear(); // clear out any values in Names
  375. this->Names.push_back(args[1]);
  376. for(unsigned int j = 2; j < args.size(); ++j)
  377. {
  378. userPaths.push_back(args[j]);
  379. }
  380. }
  381. this->ExpandPaths(userPaths);
  382. return true;
  383. }
  384. void cmFindBase::ExpandPaths(std::vector<std::string> userPaths)
  385. {
  386. // if NO Default paths was not specified add the
  387. // standard search paths.
  388. if(!this->NoDefaultPath)
  389. {
  390. if(this->SearchFrameworkFirst)
  391. {
  392. this->AddFrameWorkPaths();
  393. }
  394. if(this->SearchAppBundleFirst)
  395. {
  396. this->AddAppBundlePaths();
  397. }
  398. if(!this->NoCMakeEnvironmentPath &&
  399. !(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
  400. {
  401. // Add CMAKE_*_PATH environment variables
  402. this->AddEnvironmentVairables();
  403. }
  404. if(!this->NoCMakePath &&
  405. !(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
  406. {
  407. // Add CMake varibles of the same name as the previous environment
  408. // varibles CMAKE_*_PATH to be used most of the time with -D
  409. // command line options
  410. this->AddCMakeVairables();
  411. }
  412. if(!this->NoSystemEnvironmentPath &&
  413. !(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
  414. {
  415. // add System environment PATH and (LIB or INCLUDE)
  416. this->AddSystemEnvironmentVairables();
  417. }
  418. if(!this->NoCMakeSystemPath &&
  419. !(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
  420. {
  421. // Add CMAKE_SYSTEM_*_PATH variables which are defined in platform files
  422. this->AddCMakeSystemVariables();
  423. }
  424. if(this->SearchAppBundleLast)
  425. {
  426. this->AddAppBundlePaths();
  427. }
  428. if(this->SearchFrameworkLast)
  429. {
  430. this->AddFrameWorkPaths();
  431. }
  432. }
  433. std::vector<std::string> paths;
  434. // add the paths specified in the FIND_* call
  435. for(unsigned int i =0; i < userPaths.size(); ++i)
  436. {
  437. paths.push_back(userPaths[i]);
  438. }
  439. this->AddPaths(paths);
  440. }
  441. void cmFindBase::AddEnvironmentVairables()
  442. {
  443. std::string var = "CMAKE_";
  444. var += this->CMakePathName;
  445. var += "_PATH";
  446. std::vector<std::string> paths;
  447. cmSystemTools::GetPath(paths, var.c_str());
  448. if(this->SearchAppBundleLast)
  449. {
  450. cmSystemTools::GetPath(paths, "CMAKE_APPBUNDLE_PATH");
  451. }
  452. if(this->SearchFrameworkLast)
  453. {
  454. cmSystemTools::GetPath(paths, "CMAKE_FRAMEWORK_PATH");
  455. }
  456. this->AddPaths(paths);
  457. }
  458. void cmFindBase::AddFrameWorkPaths()
  459. {
  460. if(this->NoDefaultPath)
  461. {
  462. return;
  463. }
  464. std::vector<std::string> paths;
  465. // first environment variables
  466. if(!this->NoCMakeEnvironmentPath)
  467. {
  468. cmSystemTools::GetPath(paths, "CMAKE_FRAMEWORK_PATH");
  469. }
  470. // add cmake variables
  471. if(!this->NoCMakePath)
  472. {
  473. if(const char* path =
  474. this->Makefile->GetDefinition("CMAKE_FRAMEWORK_PATH"))
  475. {
  476. cmSystemTools::ExpandListArgument(path, paths);
  477. }
  478. }
  479. // AddCMakeSystemVariables
  480. if(!this->NoCMakeSystemPath)
  481. {
  482. if(const char* path =
  483. this->Makefile->GetDefinition("CMAKE_SYSTEM_FRAMEWORK_PATH"))
  484. {
  485. cmSystemTools::ExpandListArgument(path, paths);
  486. }
  487. }
  488. this->AddPaths(paths);
  489. }
  490. void cmFindBase::AddPaths(std::vector<std::string> & paths)
  491. {
  492. // add suffixes and clean up paths
  493. this->ExpandRegistryAndCleanPath(paths);
  494. // add the paths to the search paths
  495. this->SearchPaths.insert(this->SearchPaths.end(),
  496. paths.begin(),
  497. paths.end());
  498. }
  499. void cmFindBase::AddAppBundlePaths()
  500. {
  501. if(this->NoDefaultPath)
  502. {
  503. return;
  504. }
  505. std::vector<std::string> paths;
  506. // first environment variables
  507. if(!this->NoCMakeEnvironmentPath)
  508. {
  509. cmSystemTools::GetPath(paths, "CMAKE_APPBUNDLE_PATH");
  510. }
  511. // add cmake variables
  512. if(!this->NoCMakePath)
  513. {
  514. if(const char* path =
  515. this->Makefile->GetDefinition("CMAKE_APPBUNDLE_PATH"))
  516. {
  517. cmSystemTools::ExpandListArgument(path, paths);
  518. }
  519. }
  520. // AddCMakeSystemVariables
  521. if(!this->NoCMakeSystemPath)
  522. {
  523. if(const char* path =
  524. this->Makefile->GetDefinition("CMAKE_SYSTEM_APPBUNDLE_PATH"))
  525. {
  526. cmSystemTools::ExpandListArgument(path, paths);
  527. }
  528. }
  529. this->AddPaths(paths);
  530. }
  531. void cmFindBase::AddCMakeVairables()
  532. {
  533. std::string var = "CMAKE_";
  534. var += this->CMakePathName;
  535. var += "_PATH";
  536. std::vector<std::string> paths;
  537. if(const char* path = this->Makefile->GetDefinition(var.c_str()))
  538. {
  539. cmSystemTools::ExpandListArgument(path, paths);
  540. }
  541. if(this->SearchAppBundleLast)
  542. {
  543. if(const char* path =
  544. this->Makefile->GetDefinition("CMAKE_APPBUNDLE_PATH"))
  545. {
  546. cmSystemTools::ExpandListArgument(path, paths);
  547. }
  548. }
  549. if(this->SearchFrameworkLast)
  550. {
  551. if(const char* path =
  552. this->Makefile->GetDefinition("CMAKE_FRAMEWORK_PATH"))
  553. {
  554. cmSystemTools::ExpandListArgument(path, paths);
  555. }
  556. }
  557. this->AddPaths(paths);
  558. }
  559. void cmFindBase::AddSystemEnvironmentVairables()
  560. {
  561. // Add LIB or INCLUDE
  562. std::vector<std::string> paths;
  563. if(this->EnvironmentPath.size())
  564. {
  565. cmSystemTools::GetPath(paths, this->EnvironmentPath.c_str());
  566. }
  567. // Add PATH
  568. cmSystemTools::GetPath(paths);
  569. this->AddPaths(paths);
  570. }
  571. void cmFindBase::AddCMakeSystemVariables()
  572. {
  573. std::string var = "CMAKE_SYSTEM_";
  574. var += this->CMakePathName;
  575. var += "_PATH";
  576. std::vector<std::string> paths;
  577. if(const char* path = this->Makefile->GetDefinition(var.c_str()))
  578. {
  579. cmSystemTools::ExpandListArgument(path, paths);
  580. }
  581. if(this->SearchAppBundleLast)
  582. {
  583. if(const char* path =
  584. this->Makefile->GetDefinition("CMAKE_SYSTEM_APPBUNDLE_PATH"))
  585. {
  586. cmSystemTools::ExpandListArgument(path, paths);
  587. }
  588. }
  589. if(this->SearchFrameworkLast)
  590. {
  591. if(const char* path =
  592. this->Makefile->GetDefinition("CMAKE_SYSTEM_FRAMEWORK_PATH"))
  593. {
  594. cmSystemTools::ExpandListArgument(path, paths);
  595. }
  596. }
  597. this->AddPaths(paths);
  598. }
  599. void cmFindBase::ExpandRegistryAndCleanPath(std::vector<std::string>& paths)
  600. {
  601. std::vector<std::string> finalPath;
  602. std::vector<std::string>::iterator i;
  603. // glob and expand registry stuff from paths and put
  604. // into finalPath
  605. for(i = paths.begin();
  606. i != paths.end(); ++i)
  607. {
  608. cmSystemTools::ExpandRegistryValues(*i);
  609. cmSystemTools::GlobDirs(i->c_str(), finalPath);
  610. }
  611. // clear the path
  612. paths.clear();
  613. // convert all paths to unix slashes and add search path suffixes
  614. // if there are any
  615. for(i = finalPath.begin();
  616. i != finalPath.end(); ++i)
  617. {
  618. cmSystemTools::ConvertToUnixSlashes(*i);
  619. // copy each finalPath combined with SearchPathSuffixes
  620. // to the SearchPaths ivar
  621. for(std::vector<std::string>::iterator j =
  622. this->SearchPathSuffixes.begin();
  623. j != this->SearchPathSuffixes.end(); ++j)
  624. {
  625. std::string p = *i + std::string("/") + *j;
  626. // add to all paths because the search path may be modified
  627. // later with lib being replaced for lib64 which may exist
  628. paths.push_back(p);
  629. }
  630. }
  631. // now put the path without the path suffixes in the SearchPaths
  632. for(i = finalPath.begin();
  633. i != finalPath.end(); ++i)
  634. {
  635. // put all search paths in because it may later be replaced
  636. // by lib64 stuff fixes bug 4009
  637. paths.push_back(*i);
  638. }
  639. }
  640. void cmFindBase::PrintFindStuff()
  641. {
  642. std::cerr << "SearchFrameworkLast: " << this->SearchFrameworkLast << "\n";
  643. std::cerr << "SearchFrameworkOnly: " << this->SearchFrameworkOnly << "\n";
  644. std::cerr << "SearchFrameworkFirst: " << this->SearchFrameworkFirst << "\n";
  645. std::cerr << "SearchAppBundleLast: " << this->SearchAppBundleLast << "\n";
  646. std::cerr << "SearchAppBundleOnly: " << this->SearchAppBundleOnly << "\n";
  647. std::cerr << "SearchAppBundleFirst: " << this->SearchAppBundleFirst << "\n";
  648. std::cerr << "VariableName " << this->VariableName << "\n";
  649. std::cerr << "VariableDocumentation "
  650. << this->VariableDocumentation << "\n";
  651. std::cerr << "NoDefaultPath " << this->NoDefaultPath << "\n";
  652. std::cerr << "NoCMakeEnvironmentPath "
  653. << this->NoCMakeEnvironmentPath << "\n";
  654. std::cerr << "NoCMakePath " << this->NoCMakePath << "\n";
  655. std::cerr << "NoSystemEnvironmentPath "
  656. << this->NoSystemEnvironmentPath << "\n";
  657. std::cerr << "NoCMakeSystemPath " << this->NoCMakeSystemPath << "\n";
  658. std::cerr << "EnvironmentPath " << this->EnvironmentPath << "\n";
  659. std::cerr << "CMakePathName " << this->CMakePathName << "\n";
  660. std::cerr << "Names ";
  661. for(unsigned int i =0; i < this->Names.size(); ++i)
  662. {
  663. std::cerr << this->Names[i] << " ";
  664. }
  665. std::cerr << "\n";
  666. std::cerr << "\n";
  667. std::cerr << "SearchPathSuffixes ";
  668. for(unsigned int i =0; i < this->SearchPathSuffixes.size(); ++i)
  669. {
  670. std::cerr << this->SearchPathSuffixes[i] << "\n";
  671. }
  672. std::cerr << "\n";
  673. std::cerr << "SearchPaths\n";
  674. for(unsigned int i =0; i < this->SearchPaths.size(); ++i)
  675. {
  676. std::cerr << "[" << this->SearchPaths[i] << "]\n";
  677. }
  678. }
  679. bool cmFindBase::CheckForVariableInCache()
  680. {
  681. if(const char* cacheValue =
  682. this->Makefile->GetDefinition(this->VariableName.c_str()))
  683. {
  684. cmCacheManager::CacheIterator it =
  685. this->Makefile->GetCacheManager()->
  686. GetCacheIterator(this->VariableName.c_str());
  687. bool found = !cmSystemTools::IsNOTFOUND(cacheValue);
  688. bool cached = !it.IsAtEnd();
  689. if(found)
  690. {
  691. // If the user specifies the entry on the command line without a
  692. // type we should add the type and docstring but keep the
  693. // original value. Tell the subclass implementations to do
  694. // this.
  695. if(cached && it.GetType() == cmCacheManager::UNINITIALIZED)
  696. {
  697. this->AlreadyInCacheWithoutMetaInfo = true;
  698. }
  699. return true;
  700. }
  701. else if(cached)
  702. {
  703. const char* hs = it.GetProperty("HELPSTRING");
  704. this->VariableDocumentation = hs?hs:"(none)";
  705. }
  706. }
  707. return false;
  708. }