cmSourceGroupCommand.cxx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "cmSourceGroupCommand.h"
  14. // cmSourceGroupCommand
  15. bool cmSourceGroupCommand::InitialPass(std::vector<std::string> const& args)
  16. {
  17. if(args.size() < 1)
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. // Get the source group with the given name.
  23. cmSourceGroup* sg = m_Makefile->GetSourceGroup(args[0].c_str());
  24. if(!sg)
  25. {
  26. m_Makefile->AddSourceGroup(args[0].c_str(), 0);
  27. sg = m_Makefile->GetSourceGroup(args[0].c_str());
  28. }
  29. // If only two arguments are given, the pre-1.8 version of the
  30. // command is being invoked.
  31. if(args.size() == 2 && args[1] != "FILES")
  32. {
  33. sg->SetGroupRegex(args[1].c_str());
  34. return true;
  35. }
  36. // Process arguments.
  37. bool doingFiles = false;
  38. for(unsigned int i=1; i < args.size(); ++i)
  39. {
  40. if(args[i] == "REGULAR_EXPRESSION")
  41. {
  42. // Next argument must specify the regex.
  43. if(i+1 < args.size())
  44. {
  45. ++i;
  46. sg->SetGroupRegex(args[i].c_str());
  47. }
  48. else
  49. {
  50. this->SetError("REGULAR_EXPRESSION argument given without a regex.");
  51. return false;
  52. }
  53. doingFiles = false;
  54. }
  55. else if(args[i] == "FILES")
  56. {
  57. // Next arguments will specify files.
  58. doingFiles = true;
  59. }
  60. else if(doingFiles)
  61. {
  62. // Convert name to full path and add to the group's list.
  63. std::string src = args[i].c_str();
  64. if(!cmSystemTools::FileIsFullPath(src.c_str()))
  65. {
  66. src = m_Makefile->GetCurrentDirectory();
  67. src += "/";
  68. src += args[i];
  69. }
  70. sg->AddGroupFile(src.c_str());
  71. }
  72. else
  73. {
  74. cmOStringStream err;
  75. err << "Unknown argument \"" << args[i].c_str() << "\". "
  76. << "Perhaps the FILES keyword is missing.\n";
  77. this->SetError(err.str().c_str());
  78. return false;
  79. }
  80. }
  81. return true;
  82. }