cmGetFilenameComponentCommand.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 "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 && !cmSystemTools::IsNOTFOUND(cacheValue))
  29. {
  30. return true;
  31. }
  32. }
  33. std::string result;
  34. std::string filename = args[1];
  35. cmSystemTools::ExpandRegistryValues(filename);
  36. std::string storeArgs;
  37. std::string programArgs;
  38. if (args[2] == "PATH")
  39. {
  40. result = cmSystemTools::GetFilenamePath(filename);
  41. }
  42. else if (args[2] == "NAME")
  43. {
  44. result = cmSystemTools::GetFilenameName(filename);
  45. }
  46. else if (args[2] == "PROGRAM")
  47. {
  48. for(unsigned int i=2; i < args.size(); ++i)
  49. {
  50. if(args[i] == "PROGRAM_ARGS")
  51. {
  52. i++;
  53. if(i < args.size())
  54. {
  55. storeArgs = args[i];
  56. }
  57. }
  58. }
  59. cmSystemTools::SplitProgramFromArgs(filename.c_str(), result, programArgs);
  60. }
  61. else if (args[2] == "EXT")
  62. {
  63. result = cmSystemTools::GetFilenameExtension(filename);
  64. }
  65. else if (args[2] == "NAME_WE")
  66. {
  67. result = cmSystemTools::GetFilenameWithoutExtension(filename);
  68. }
  69. else if (args[2] == "ABSOLUTE")
  70. {
  71. result = cmSystemTools::CollapseFullPath(filename.c_str());
  72. }
  73. else
  74. {
  75. std::string err = "unknown component " + args[2];
  76. this->SetError(err.c_str());
  77. return false;
  78. }
  79. if(args.size() == 4 && args[3] == "CACHE")
  80. {
  81. if(programArgs.size() && storeArgs.size())
  82. {
  83. m_Makefile->AddCacheDefinition(storeArgs.c_str(),
  84. programArgs.c_str(),
  85. "",
  86. args[2] == "PATH" ? cmCacheManager::FILEPATH
  87. : cmCacheManager::STRING);
  88. }
  89. m_Makefile->AddCacheDefinition(args[0].c_str(),
  90. result.c_str(),
  91. "",
  92. args[2] == "PATH" ? cmCacheManager::FILEPATH
  93. : cmCacheManager::STRING);
  94. }
  95. else
  96. {
  97. if(programArgs.size() && storeArgs.size())
  98. {
  99. m_Makefile->AddDefinition(storeArgs.c_str(), programArgs.c_str());
  100. }
  101. m_Makefile->AddDefinition(args[0].c_str(), result.c_str());
  102. }
  103. return true;
  104. }