cmFindFileCommand.cxx 2.8 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. #include <stdio.h>
  17. // cmFindFileCommand
  18. bool cmFindFileCommand::InitialPass(std::vector<std::string> const& argsIn)
  19. {
  20. if(argsIn.size() < 2)
  21. {
  22. this->SetError("called with incorrect number of arguments");
  23. return false;
  24. }
  25. std::string helpString = "Where can the ";
  26. helpString += argsIn[1] + " file be found";
  27. size_t size = argsIn.size();
  28. std::vector<std::string> args;
  29. for(unsigned int j = 0; j < size; ++j)
  30. {
  31. if(argsIn[j] != "DOC")
  32. {
  33. args.push_back(argsIn[j]);
  34. }
  35. else
  36. {
  37. if(j+1 < size)
  38. {
  39. helpString = argsIn[j+1];
  40. }
  41. break;
  42. }
  43. }
  44. std::vector<std::string>::const_iterator i = args.begin();
  45. // Use the first argument as the name of something to be defined
  46. const char* define = (*i).c_str();
  47. i++; // move iterator to next arg
  48. // Now check and see if the value has been stored in the cache
  49. // already, if so use that value and don't look for the program
  50. const char* cacheValue
  51. = m_Makefile->GetDefinition(define);
  52. if(cacheValue && strcmp(cacheValue, "NOTFOUND"))
  53. {
  54. return true;
  55. }
  56. // if it is not in the cache, then search the system path
  57. std::vector<std::string> path;
  58. // add any user specified paths
  59. for (unsigned int j = 2; j < args.size(); j++)
  60. {
  61. // Glob the entry in case of wildcards.
  62. cmSystemTools::GlobDirs(args[j].c_str(), path);
  63. }
  64. // add the standard path
  65. cmSystemTools::GetPath(path);
  66. for(unsigned int k=0; k < path.size(); k++)
  67. {
  68. std::string tryPath = path[k];
  69. tryPath += "/";
  70. tryPath += *i;
  71. if(cmSystemTools::FileExists(tryPath.c_str()))
  72. {
  73. // Save the value in the cache
  74. m_Makefile->AddCacheDefinition(define,
  75. tryPath.c_str(),
  76. helpString.c_str(),
  77. cmCacheManager::FILEPATH);
  78. return true;
  79. }
  80. }
  81. m_Makefile->AddCacheDefinition(args[0].c_str(),
  82. "NOTFOUND",
  83. helpString.c_str(),
  84. cmCacheManager::FILEPATH);
  85. return true;
  86. }