cmFindBase.cxx 27 KB

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