cmFindLibraryCommand.cxx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 "cmFindLibraryCommand.h"
  14. #include "cmCacheManager.h"
  15. // cmFindLibraryCommand
  16. bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn)
  17. {
  18. if(argsIn.size() < 2)
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. std::string helpString;
  24. size_t size = argsIn.size();
  25. std::vector<std::string> args;
  26. for(unsigned int j = 0; j < size; ++j)
  27. {
  28. if(argsIn[j] != "DOC")
  29. {
  30. args.push_back(argsIn[j]);
  31. }
  32. else
  33. {
  34. if(j+1 < size)
  35. {
  36. helpString = argsIn[j+1];
  37. }
  38. break;
  39. }
  40. }
  41. std::vector<std::string> path;
  42. std::vector<std::string> names;
  43. bool foundName = false;
  44. bool foundPath = false;
  45. bool doingNames = true;
  46. for (unsigned int j = 1; j < args.size(); ++j)
  47. {
  48. if(args[j] == "NAMES")
  49. {
  50. doingNames = true;
  51. foundName = true;
  52. }
  53. else if (args[j] == "PATHS")
  54. {
  55. doingNames = false;
  56. foundPath = true;
  57. }
  58. else
  59. {
  60. if(doingNames)
  61. {
  62. names.push_back(args[j]);
  63. }
  64. else
  65. {
  66. cmSystemTools::ExpandRegistryValues(args[j]);
  67. // Glob the entry in case of wildcards.
  68. cmSystemTools::GlobDirs(args[j].c_str(), path);
  69. }
  70. }
  71. }
  72. // old style name path1 path2 path3
  73. if(!foundPath && !foundName)
  74. {
  75. names.clear();
  76. path.clear();
  77. names.push_back(args[1]);
  78. // add any user specified paths
  79. for (unsigned int j = 2; j < args.size(); j++)
  80. {
  81. // expand variables
  82. std::string exp = args[j];
  83. cmSystemTools::ExpandRegistryValues(exp);
  84. // Glob the entry in case of wildcards.
  85. cmSystemTools::GlobDirs(exp.c_str(), path);
  86. }
  87. }
  88. if(helpString.size() == 0)
  89. {
  90. helpString = "Where can ";
  91. if (names.size() == 0)
  92. {
  93. helpString += "the (unknown) library be found";
  94. }
  95. else if (names.size() == 1)
  96. {
  97. helpString += "the " + names[0] + " library be found";
  98. }
  99. else
  100. {
  101. helpString += "one of the " + names[0];
  102. for (unsigned int j = 1; j < names.size() - 1; ++j)
  103. {
  104. helpString += ", " + names[j];
  105. }
  106. helpString += " or " + names[names.size() - 1] + " libraries be found";
  107. }
  108. }
  109. const char* cacheValue
  110. = m_Makefile->GetDefinition(args[0].c_str());
  111. if(cacheValue && strcmp(cacheValue, "NOTFOUND"))
  112. {
  113. return true;
  114. }
  115. std::string library;
  116. for(std::vector<std::string>::iterator i = names.begin();
  117. i != names.end() ; ++i)
  118. {
  119. library = m_Makefile->FindLibrary(i->c_str(), path);
  120. if(library != "")
  121. {
  122. m_Makefile->AddCacheDefinition(args[0].c_str(),
  123. library.c_str(),
  124. helpString.c_str(),
  125. cmCacheManager::FILEPATH);
  126. return true;
  127. }
  128. }
  129. m_Makefile->AddCacheDefinition(args[0].c_str(),
  130. "NOTFOUND",
  131. helpString.c_str(),
  132. cmCacheManager::FILEPATH);
  133. return true;
  134. }