cmFindIncludeCommand.cxx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "cmFindIncludeCommand.h"
  12. #include "cmCacheManager.h"
  13. // cmFindIncludeCommand
  14. bool cmFindIncludeCommand::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. // Save the value in the cache
  54. cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
  55. path[k].c_str(),
  56. cmCacheManager::PATH);
  57. return true;
  58. }
  59. }
  60. cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
  61. "NOTFOUND",
  62. cmCacheManager::PATH);
  63. std::string message = "Include not found: ";
  64. message += args[1];
  65. message += "\n";
  66. message += "looked in ";
  67. for(k=0; k < path.size(); k++)
  68. {
  69. message += path[k];
  70. message += "\n";
  71. }
  72. this->SetError(message.c_str());
  73. return false;
  74. }