cmFindIncludeCommand.cxx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. m_Makefile->AddDefinition(args[0].c_str(), cacheValue);
  28. return true;
  29. }
  30. std::vector<std::string> path;
  31. // add any user specified paths
  32. for (unsigned int j = 2; j < args.size(); j++)
  33. {
  34. // expand variables
  35. std::string exp = args[j];
  36. m_Makefile->ExpandVariablesInString(exp);
  37. path.push_back(exp);
  38. }
  39. // add the standard path
  40. cmSystemTools::GetPath(path);
  41. for(unsigned int k=0; k < path.size(); k++)
  42. {
  43. std::string tryPath = path[k];
  44. tryPath += "/";
  45. tryPath += args[1];
  46. if(cmSystemTools::FileExists(tryPath.c_str()))
  47. {
  48. m_Makefile->AddDefinition(args[0].c_str(), path[k].c_str());
  49. // Save the value in the cache
  50. cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
  51. path[k].c_str(),
  52. cmCacheManager::PATH);
  53. return true;
  54. }
  55. }
  56. return false;
  57. }