cmFindProgramCommand.cxx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 "cmFindProgramCommand.h"
  12. #include "cmCacheManager.h"
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. // cmFindProgramCommand
  16. bool cmFindProgramCommand::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. cmSystemTools::GetPath(path);
  39. for(; i != args.end(); ++i)
  40. {
  41. for(unsigned int k=0; k < path.size(); k++)
  42. {
  43. std::string tryPath = path[k];
  44. tryPath += "/";
  45. tryPath += *i;
  46. #ifdef _WIN32
  47. tryPath += ".exe";
  48. #endif
  49. if(cmSystemTools::FileExists(tryPath.c_str()))
  50. {
  51. // Save the value in the cache
  52. cmCacheManager::GetInstance()->AddCacheEntry(define,
  53. tryPath.c_str(),
  54. cmCacheManager::FILEPATH);
  55. m_Makefile->AddDefinition(define, tryPath.c_str());
  56. return true;
  57. }
  58. }
  59. }
  60. return false;
  61. }