cmFindFileCommand.cxx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 "cmFindFileCommand.h"
  12. #include "cmCacheManager.h"
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. // cmFindFileCommand
  16. bool cmFindFileCommand::Invoke(std::vector<std::string>& args)
  17. {
  18. if(args.size() < 2 )
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. std::vector<std::string>::iterator i = args.begin();
  24. // Use the first argument as the name of something to be defined
  25. const char* define = (*i).c_str();
  26. i++; // move iterator to next arg
  27. // Now check and see if the value has been stored in the cache
  28. // already, if so use that value and don't look for the program
  29. const char* cacheValue
  30. = cmCacheManager::GetInstance()->GetCacheValue(define);
  31. if(cacheValue)
  32. {
  33. m_Makefile->AddDefinition(define, cacheValue);
  34. return true;
  35. }
  36. // if it is not in the cache, then search the system path
  37. std::vector<std::string> path;
  38. // add any user specified paths
  39. for (unsigned int j = 2; j < args.size(); j++)
  40. {
  41. // expand variables
  42. std::string exp = args[j];
  43. m_Makefile->ExpandVariablesInString(exp);
  44. path.push_back(exp);
  45. }
  46. // add the standard path
  47. cmSystemTools::GetPath(path);
  48. for(unsigned int k=0; k < path.size(); k++)
  49. {
  50. std::string tryPath = path[k];
  51. tryPath += "/";
  52. tryPath += *i;
  53. if(cmSystemTools::FileExists(tryPath.c_str()))
  54. {
  55. // Save the value in the cache
  56. cmCacheManager::GetInstance()->AddCacheEntry(define,
  57. tryPath.c_str(),
  58. cmCacheManager::FILEPATH);
  59. m_Makefile->AddDefinition(define, tryPath.c_str());
  60. return true;
  61. }
  62. }
  63. return false;
  64. }