cmFindIncludeCommand.cxx 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. cacheValue
  32. = cmCacheManager::GetInstance()->GetCacheValue(args[1].c_str());
  33. if(cacheValue)
  34. {
  35. if(strcmp(cacheValue, "NOTFOUND") != 0)
  36. {
  37. m_Makefile->AddDefinition(args[1].c_str(), cacheValue);
  38. }
  39. }
  40. return true;
  41. }
  42. std::vector<std::string> path;
  43. // add any user specified paths
  44. for (unsigned int j = 3; j < args.size(); j++)
  45. {
  46. // expand variables
  47. std::string exp = args[j];
  48. m_Makefile->ExpandVariablesInString(exp);
  49. path.push_back(exp);
  50. }
  51. // add the standard path
  52. cmSystemTools::GetPath(path);
  53. unsigned int k;
  54. for(k=0; k < path.size(); k++)
  55. {
  56. std::string tryPath = path[k];
  57. tryPath += "/";
  58. tryPath += args[2];
  59. if(cmSystemTools::FileExists(tryPath.c_str()))
  60. {
  61. // Save the value in the cache
  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. m_Makefile->AddDefinition(args[1].c_str(), args[2].c_str());
  67. cmCacheManager::GetInstance()->AddCacheEntry(args[1].c_str(),
  68. args[2].c_str(),
  69. cmCacheManager::PATH);
  70. return true;
  71. }
  72. }
  73. cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
  74. "NOTFOUND",
  75. cmCacheManager::PATH);
  76. cmCacheManager::GetInstance()->AddCacheEntry(args[1].c_str(),
  77. "NOTFOUND",
  78. cmCacheManager::PATH);
  79. std::string message = "Include not found: ";
  80. message += args[1];
  81. message += "\n";
  82. message += "looked in ";
  83. for(k=0; k < path.size(); k++)
  84. {
  85. message += path[k];
  86. message += "\n";
  87. }
  88. this->SetError(message.c_str());
  89. return false;
  90. }