cmFindLibraryCommand.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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> argst;
  26. for(unsigned int j = 0; j < size; ++j)
  27. {
  28. if(argsIn[j] != "DOC")
  29. {
  30. argst.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> args;
  42. cmSystemTools::ExpandListArguments(argst, args);
  43. std::vector<std::string> path;
  44. std::vector<std::string> names;
  45. bool foundName = false;
  46. bool foundPath = false;
  47. bool doingNames = true;
  48. for (unsigned int j = 1; j < args.size(); ++j)
  49. {
  50. if(args[j] == "NAMES")
  51. {
  52. doingNames = true;
  53. foundName = true;
  54. }
  55. else if (args[j] == "PATHS")
  56. {
  57. doingNames = false;
  58. foundPath = true;
  59. }
  60. else
  61. {
  62. if(doingNames)
  63. {
  64. names.push_back(args[j]);
  65. }
  66. else
  67. {
  68. // Glob the entry in case of wildcards.
  69. cmSystemTools::GlobDirs(args[j].c_str(), path);
  70. }
  71. }
  72. }
  73. // old style name path1 path2 path3
  74. if(!foundPath && !foundName)
  75. {
  76. names.clear();
  77. path.clear();
  78. names.push_back(args[1]);
  79. // add any user specified paths
  80. for (unsigned int j = 2; j < args.size(); j++)
  81. {
  82. // expand variables
  83. std::string exp = args[j];
  84. cmSystemTools::ExpandRegistryValues(exp);
  85. // Glob the entry in case of wildcards.
  86. cmSystemTools::GlobDirs(exp.c_str(), path);
  87. }
  88. }
  89. if(helpString.size() == 0)
  90. {
  91. helpString = "Where can ";
  92. if (names.size() == 0)
  93. {
  94. helpString += "the (unknown) library be found";
  95. }
  96. else if (names.size() == 1)
  97. {
  98. helpString += "the " + names[0] + " library be found";
  99. }
  100. else
  101. {
  102. helpString += "one of the " + names[0];
  103. for (unsigned int j = 1; j < names.size() - 1; ++j)
  104. {
  105. helpString += ", " + names[j];
  106. }
  107. helpString += " or " + names[names.size() - 1] + " libraries be found";
  108. }
  109. }
  110. const char* cacheValue
  111. = m_Makefile->GetDefinition(args[0].c_str());
  112. if(cacheValue && strcmp(cacheValue, "NOTFOUND"))
  113. {
  114. return true;
  115. }
  116. std::string library;
  117. for(std::vector<std::string>::iterator i = names.begin();
  118. i != names.end() ; ++i)
  119. {
  120. library = cmSystemTools::FindLibrary(i->c_str(),
  121. path);
  122. if(library != "")
  123. {
  124. m_Makefile->AddCacheDefinition(args[0].c_str(),
  125. library.c_str(),
  126. helpString.c_str(),
  127. cmCacheManager::FILEPATH);
  128. return true;
  129. }
  130. }
  131. m_Makefile->AddCacheDefinition(args[0].c_str(),
  132. "NOTFOUND",
  133. helpString.c_str(),
  134. cmCacheManager::FILEPATH);
  135. return true;
  136. }