cmGetFilenameComponentCommand.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 && strcmp(cacheValue, "NOTFOUND"))
  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
  70. {
  71. std::string err = "unknow component " + args[2];
  72. this->SetError(err.c_str());
  73. return false;
  74. }
  75. if(args.size() == 4 && args[3] == "CACHE")
  76. {
  77. if(programArgs.size() && storeArgs.size())
  78. {
  79. m_Makefile->AddCacheDefinition(storeArgs.c_str(),
  80. programArgs.c_str(),
  81. "",
  82. args[2] == "PATH" ? cmCacheManager::FILEPATH
  83. : cmCacheManager::STRING);
  84. }
  85. m_Makefile->AddCacheDefinition(args[0].c_str(),
  86. result.c_str(),
  87. "",
  88. args[2] == "PATH" ? cmCacheManager::FILEPATH
  89. : cmCacheManager::STRING);
  90. }
  91. else
  92. {
  93. if(programArgs.size() && storeArgs.size())
  94. {
  95. m_Makefile->AddDefinition(storeArgs.c_str(), programArgs.c_str());
  96. }
  97. m_Makefile->AddDefinition(args[0].c_str(), result.c_str());
  98. }
  99. return true;
  100. }