1
0

cmFindLibraryCommand.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. unsigned int 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. m_Makefile->ExpandVariablesInString(args[j]);
  61. if(doingNames)
  62. {
  63. names.push_back(args[j]);
  64. }
  65. else
  66. {
  67. cmSystemTools::ExpandRegistryValues(args[j]);
  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. m_Makefile->ExpandVariablesInString(exp);
  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. if(library != "")
  124. {
  125. m_Makefile->AddCacheDefinition(args[0].c_str(),
  126. library.c_str(),
  127. helpString.c_str(),
  128. cmCacheManager::FILEPATH);
  129. return true;
  130. }
  131. }
  132. m_Makefile->AddCacheDefinition(args[0].c_str(),
  133. "NOTFOUND",
  134. helpString.c_str(),
  135. cmCacheManager::FILEPATH);
  136. return true;
  137. }