cmFindFileCommand.cxx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmFindFileCommand.h"
  14. #include "cmCacheManager.h"
  15. #include <stdlib.h>
  16. // cmFindFileCommand
  17. bool cmFindFileCommand::InitialPass(std::vector<std::string> const& argsIn)
  18. {
  19. if(argsIn.size() < 2)
  20. {
  21. this->SetError("called with incorrect number of arguments");
  22. return false;
  23. }
  24. std::string helpString = "Where can the ";
  25. helpString += argsIn[1] + " file be found";
  26. size_t size = argsIn.size();
  27. std::vector<std::string> args;
  28. for(unsigned int j = 0; j < size; ++j)
  29. {
  30. if(argsIn[j] != "DOC")
  31. {
  32. args.push_back(argsIn[j]);
  33. }
  34. else
  35. {
  36. if(j+1 < size)
  37. {
  38. helpString = argsIn[j+1];
  39. }
  40. break;
  41. }
  42. }
  43. std::vector<std::string>::const_iterator i = args.begin();
  44. // Use the first argument as the name of something to be defined
  45. const char* define = (*i).c_str();
  46. i++; // move iterator to next arg
  47. // Now check and see if the value has been stored in the cache
  48. // already, if so use that value and don't look for the program
  49. const char* cacheValue
  50. = m_Makefile->GetDefinition(define);
  51. if(cacheValue && !cmSystemTools::IsNOTFOUND(cacheValue))
  52. {
  53. return true;
  54. }
  55. // if it is not in the cache, then search the system path
  56. std::vector<std::string> path;
  57. // add any user specified paths
  58. for (unsigned int j = 2; j < args.size(); j++)
  59. {
  60. // Glob the entry in case of wildcards.
  61. cmSystemTools::GlobDirs(args[j].c_str(), path);
  62. }
  63. // add the standard path
  64. cmSystemTools::GetPath(path);
  65. for(unsigned int k=0; k < path.size(); k++)
  66. {
  67. std::string tryPath = path[k];
  68. tryPath += "/";
  69. tryPath += *i;
  70. if(cmSystemTools::FileExists(tryPath.c_str()))
  71. {
  72. // Save the value in the cache
  73. m_Makefile->AddCacheDefinition(define,
  74. tryPath.c_str(),
  75. helpString.c_str(),
  76. cmCacheManager::FILEPATH);
  77. return true;
  78. }
  79. }
  80. std::string s = args[0] + "-NOTFOUND";
  81. m_Makefile->AddCacheDefinition(args[0].c_str(),
  82. s.c_str(),
  83. helpString.c_str(),
  84. cmCacheManager::FILEPATH);
  85. return true;
  86. }