cmFindFileCommand.cxx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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> argst;
  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. std::vector<std::string>::const_iterator i = args.begin();
  47. // Use the first argument as the name of something to be defined
  48. const char* define = (*i).c_str();
  49. i++; // move iterator to next arg
  50. // Now check and see if the value has been stored in the cache
  51. // already, if so use that value and don't look for the program
  52. const char* cacheValue
  53. = m_Makefile->GetDefinition(define);
  54. if(cacheValue && strcmp(cacheValue, "NOTFOUND"))
  55. {
  56. return true;
  57. }
  58. // if it is not in the cache, then search the system path
  59. std::vector<std::string> path;
  60. // add any user specified paths
  61. for (unsigned int j = 2; j < args.size(); j++)
  62. {
  63. // Glob the entry in case of wildcards.
  64. cmSystemTools::GlobDirs(args[j].c_str(), path);
  65. }
  66. // add the standard path
  67. cmSystemTools::GetPath(path);
  68. for(unsigned int k=0; k < path.size(); k++)
  69. {
  70. std::string tryPath = path[k];
  71. tryPath += "/";
  72. tryPath += *i;
  73. if(cmSystemTools::FileExists(tryPath.c_str()))
  74. {
  75. // Save the value in the cache
  76. m_Makefile->AddCacheDefinition(define,
  77. tryPath.c_str(),
  78. helpString.c_str(),
  79. cmCacheManager::FILEPATH);
  80. return true;
  81. }
  82. }
  83. m_Makefile->AddCacheDefinition(args[0].c_str(),
  84. "NOTFOUND",
  85. helpString.c_str(),
  86. cmCacheManager::FILEPATH);
  87. return true;
  88. }