cmFindPathCommand.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 "cmFindPathCommand.h"
  14. #include "cmCacheManager.h"
  15. // cmFindPathCommand
  16. bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn)
  17. {
  18. if(argsIn.size() < 2)
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. // Now check and see if the value has been stored in the cache
  24. // already, if so use that value and don't look for the program
  25. std::string helpString = "What is the path where the file ";
  26. helpString += argsIn[1] + " can be found";
  27. std::vector<std::string> argst;
  28. size_t size = argsIn.size();
  29. for(unsigned int j = 0; j < size; ++j)
  30. {
  31. if(argsIn[j] != "DOC")
  32. {
  33. argst.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> args;
  45. cmSystemTools::ExpandListArguments(argst, args);
  46. const char* cacheValue
  47. = m_Makefile->GetDefinition(args[0].c_str());
  48. if(cacheValue && strcmp(cacheValue, "NOTFOUND"))
  49. {
  50. return true;
  51. }
  52. if(cacheValue)
  53. {
  54. cmCacheManager::CacheIterator it =
  55. m_Makefile->GetCacheManager()->GetCacheIterator(args[0].c_str());
  56. if(!it.IsAtEnd())
  57. {
  58. const char* hs = it.GetProperty("HELPSTRING");
  59. helpString = hs?hs:"(none)";
  60. }
  61. }
  62. std::vector<std::string> path;
  63. // add any user specified paths
  64. for (unsigned int j = 2; j < args.size(); j++)
  65. {
  66. // expand variables
  67. std::string exp = args[j];
  68. cmSystemTools::ExpandRegistryValues(exp);
  69. // Glob the entry in case of wildcards.
  70. cmSystemTools::GlobDirs(exp.c_str(), path);
  71. }
  72. // add the standard path
  73. cmSystemTools::GetPath(path);
  74. unsigned int k;
  75. for(k=0; k < path.size(); k++)
  76. {
  77. std::string tryPath = path[k];
  78. tryPath += "/";
  79. tryPath += args[1];
  80. if(cmSystemTools::FileExists(tryPath.c_str()))
  81. {
  82. path[k] = cmSystemTools::CollapseFullPath(path[k].c_str());
  83. m_Makefile->AddCacheDefinition(args[0].c_str(),
  84. path[k].c_str(),
  85. helpString.c_str(),
  86. cmCacheManager::PATH);
  87. return true;
  88. }
  89. }
  90. m_Makefile->AddCacheDefinition(args[0].c_str(),
  91. "NOTFOUND",
  92. helpString.c_str(),
  93. cmCacheManager::PATH);
  94. return true;
  95. }