cmFindLibraryCommand.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2000 National Library of Medicine
  8. All rights reserved.
  9. See COPYRIGHT.txt for copyright details.
  10. =========================================================================*/
  11. #include "cmFindLibraryCommand.h"
  12. #include "cmCacheManager.h"
  13. // cmFindLibraryCommand
  14. bool cmFindLibraryCommand::Invoke(std::vector<std::string>& args)
  15. {
  16. if(args.size() < 2)
  17. {
  18. this->SetError("called with incorrect number of arguments");
  19. return false;
  20. }
  21. // Now check and see if the value has been stored in the cache
  22. // already, if so use that value and don't look for the program
  23. const char* cacheValue
  24. = cmCacheManager::GetInstance()->GetCacheValue(args[0].c_str());
  25. if(cacheValue)
  26. {
  27. if(strcmp(cacheValue, "NOTFOUND") != 0)
  28. {
  29. m_Makefile->AddDefinition(args[0].c_str(), cacheValue);
  30. }
  31. return true;
  32. }
  33. std::vector<std::string> path;
  34. // add any user specified paths
  35. for (unsigned int j = 2; j < args.size(); j++)
  36. {
  37. // expand variables
  38. std::string exp = args[j];
  39. m_Makefile->ExpandVariablesInString(exp);
  40. path.push_back(exp);
  41. }
  42. // add the standard path
  43. cmSystemTools::GetPath(path);
  44. unsigned int k;
  45. for(k=0; k < path.size(); k++)
  46. {
  47. std::string tryPath = path[k];
  48. tryPath += "/";
  49. std::string testF;
  50. testF = tryPath + args[1] + ".lib";
  51. if(cmSystemTools::FileExists(testF.c_str()))
  52. {
  53. m_Makefile->AddDefinition(args[0].c_str(), path[k].c_str());
  54. cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
  55. path[k].c_str(),
  56. cmCacheManager::PATH);
  57. return true;
  58. }
  59. testF = tryPath + "lib" + args[1] + ".so";
  60. if(cmSystemTools::FileExists(testF.c_str()))
  61. {
  62. m_Makefile->AddDefinition(args[0].c_str(), path[k].c_str());
  63. cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
  64. path[k].c_str(),
  65. cmCacheManager::PATH);
  66. return true;
  67. }
  68. testF = tryPath + "lib" + args[1] + ".a";
  69. if(cmSystemTools::FileExists(testF.c_str()))
  70. {
  71. m_Makefile->AddDefinition(args[0].c_str(), path[k].c_str());
  72. cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
  73. path[k].c_str(),
  74. cmCacheManager::PATH);
  75. return true;
  76. }
  77. testF = tryPath + "lib" + args[1] + ".sl";
  78. if(cmSystemTools::FileExists(testF.c_str()))
  79. {
  80. m_Makefile->AddDefinition(args[0].c_str(), path[k].c_str());
  81. cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
  82. path[k].c_str(),
  83. cmCacheManager::PATH);
  84. return true;
  85. }
  86. }
  87. cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
  88. "NOTFOUND",
  89. cmCacheManager::PATH);
  90. std::string message = "Library not found: ";
  91. message += args[1];
  92. message += "\n";
  93. message += "looked in ";
  94. for(k=0; k < path.size(); k++)
  95. {
  96. message += path[k];
  97. message += "\n";
  98. }
  99. this->SetError(message.c_str());
  100. return false;
  101. }