cmFindLibraryCommand.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. cmSystemTools::ExpandRegistryValues(args[j]);
  69. // Glob the entry in case of wildcards.
  70. cmSystemTools::GlobDirs(args[j].c_str(), path);
  71. }
  72. }
  73. }
  74. // old style name path1 path2 path3
  75. if(!foundPath && !foundName)
  76. {
  77. names.clear();
  78. path.clear();
  79. names.push_back(args[1]);
  80. // add any user specified paths
  81. for (unsigned int j = 2; j < args.size(); j++)
  82. {
  83. // expand variables
  84. std::string exp = args[j];
  85. cmSystemTools::ExpandRegistryValues(exp);
  86. // Glob the entry in case of wildcards.
  87. cmSystemTools::GlobDirs(exp.c_str(), path);
  88. }
  89. }
  90. if(helpString.size() == 0)
  91. {
  92. helpString = "Where can ";
  93. if (names.size() == 0)
  94. {
  95. helpString += "the (unknown) library be found";
  96. }
  97. else if (names.size() == 1)
  98. {
  99. helpString += "the " + names[0] + " library be found";
  100. }
  101. else
  102. {
  103. helpString += "one of the " + names[0];
  104. for (unsigned int j = 1; j < names.size() - 1; ++j)
  105. {
  106. helpString += ", " + names[j];
  107. }
  108. helpString += " or " + names[names.size() - 1] + " libraries be found";
  109. }
  110. }
  111. const char* cacheValue
  112. = m_Makefile->GetDefinition(args[0].c_str());
  113. if(cacheValue && strcmp(cacheValue, "NOTFOUND"))
  114. {
  115. return true;
  116. }
  117. std::string library;
  118. for(std::vector<std::string>::iterator i = names.begin();
  119. i != names.end() ; ++i)
  120. {
  121. library = cmSystemTools::FindLibrary(i->c_str(),
  122. path,
  123. m_Makefile);
  124. if(library != "")
  125. {
  126. m_Makefile->AddCacheDefinition(args[0].c_str(),
  127. library.c_str(),
  128. helpString.c_str(),
  129. cmCacheManager::FILEPATH);
  130. return true;
  131. }
  132. }
  133. m_Makefile->AddCacheDefinition(args[0].c_str(),
  134. "NOTFOUND",
  135. helpString.c_str(),
  136. cmCacheManager::FILEPATH);
  137. return true;
  138. }