cmSourceGroupCommand.cxx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. // Process arguments.
  30. bool doingFiles = false;
  31. for(unsigned int i=1; i < args.size(); ++i)
  32. {
  33. if(args[i] == "REGULAR_EXPRESSION")
  34. {
  35. // Next argument must specify the regex.
  36. if(i+1 < args.size())
  37. {
  38. ++i;
  39. sg->SetGroupRegex(args[i].c_str());
  40. }
  41. else
  42. {
  43. this->SetError("REGULAR_EXPRESSION argument given without a regex.");
  44. return false;
  45. }
  46. doingFiles = false;
  47. }
  48. else if(args[i] == "FILES")
  49. {
  50. // Next arguments will specify files.
  51. doingFiles = true;
  52. }
  53. else if(doingFiles)
  54. {
  55. // Convert name to full path and add to the group's list.
  56. std::string src = args[i].c_str();
  57. if(!cmSystemTools::FileIsFullPath(src.c_str()))
  58. {
  59. src = m_Makefile->GetCurrentDirectory();
  60. src += "/";
  61. src += args[i];
  62. }
  63. sg->AddGroupFile(src.c_str());
  64. }
  65. else
  66. {
  67. cmOStringStream err;
  68. err << "Unknown argument \"" << args[i].c_str() << "\". "
  69. << "Perhaps the FILES keyword is missing.\n";
  70. this->SetError(err.str().c_str());
  71. return false;
  72. }
  73. }
  74. return true;
  75. }