cmFindLibraryCommand.cxx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. tryPath += args[1];
  50. if(cmSystemTools::FileExists(tryPath.c_str()))
  51. {
  52. m_Makefile->AddDefinition(args[0].c_str(), path[k].c_str());
  53. cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
  54. path[k].c_str(),
  55. cmCacheManager::PATH);
  56. return true;
  57. }
  58. }
  59. cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
  60. "NOTFOUND",
  61. cmCacheManager::PATH);
  62. std::string message = "Library not found: ";
  63. message += args[1];
  64. message += "\n";
  65. message += "looked in ";
  66. for(k=0; k < path.size(); k++)
  67. {
  68. message += path[k];
  69. message += "\n";
  70. }
  71. this->SetError(message.c_str());
  72. return false;
  73. }