cmGetFilenameComponentCommand.cxx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "cmGetFilenameComponentCommand.h"
  14. #include "cmSystemTools.h"
  15. // cmGetFilenameComponentCommand
  16. bool cmGetFilenameComponentCommand::InitialPass(std::vector<std::string> const& args)
  17. {
  18. if(args.size() < 3)
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. // Check and see if the value has been stored in the cache
  24. // already, if so use that value
  25. if(args.size() == 4 && args[3] == "CACHE")
  26. {
  27. const char* cacheValue = m_Makefile->GetDefinition(args[0].c_str());
  28. if(cacheValue && strcmp(cacheValue, "NOTFOUND"))
  29. {
  30. return true;
  31. }
  32. }
  33. std::string result;
  34. std::string filename = args[1];
  35. if (args[2] == "PATH")
  36. {
  37. result = cmSystemTools::GetFilenamePath(filename);
  38. }
  39. else if (args[2] == "NAME")
  40. {
  41. result = cmSystemTools::GetFilenameName(filename);
  42. }
  43. else if (args[2] == "EXT")
  44. {
  45. result = cmSystemTools::GetFilenameExtension(filename);
  46. }
  47. else if (args[2] == "NAME_WE")
  48. {
  49. result = cmSystemTools::GetFilenameWithoutExtension(filename);
  50. }
  51. else
  52. {
  53. std::string err = "unknow component " + args[2];
  54. this->SetError(err.c_str());
  55. return false;
  56. }
  57. if(args.size() == 4 && args[3] == "CACHE")
  58. {
  59. m_Makefile->AddCacheDefinition(args[0].c_str(),
  60. result.c_str(),
  61. "",
  62. args[2] == "PATH" ? cmCacheManager::FILEPATH
  63. : cmCacheManager::STRING);
  64. }
  65. else
  66. {
  67. m_Makefile->AddDefinition(args[0].c_str(), result.c_str());
  68. }
  69. return true;
  70. }