cmSourceGroupCommand.cxx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmSourceGroupCommand.h"
  11. // cmSourceGroupCommand
  12. bool cmSourceGroupCommand::InitialPass(std::vector<std::string> const& args,
  13. cmExecutionStatus&)
  14. {
  15. if (args.empty()) {
  16. this->SetError("called with incorrect number of arguments");
  17. return false;
  18. }
  19. std::string delimiter = "\\";
  20. if (this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER")) {
  21. delimiter = this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER");
  22. }
  23. std::vector<std::string> folders =
  24. cmSystemTools::tokenize(args[0], delimiter);
  25. cmSourceGroup* sg = CM_NULLPTR;
  26. sg = this->Makefile->GetSourceGroup(folders);
  27. if (!sg) {
  28. this->Makefile->AddSourceGroup(folders);
  29. sg = this->Makefile->GetSourceGroup(folders);
  30. }
  31. if (!sg) {
  32. this->SetError("Could not create or find source group");
  33. return false;
  34. }
  35. // If only two arguments are given, the pre-1.8 version of the
  36. // command is being invoked.
  37. if (args.size() == 2 && args[1] != "FILES") {
  38. sg->SetGroupRegex(args[1].c_str());
  39. return true;
  40. }
  41. // Process arguments.
  42. bool doingFiles = false;
  43. for (unsigned int i = 1; i < args.size(); ++i) {
  44. if (args[i] == "REGULAR_EXPRESSION") {
  45. // Next argument must specify the regex.
  46. if (i + 1 < args.size()) {
  47. ++i;
  48. sg->SetGroupRegex(args[i].c_str());
  49. } else {
  50. this->SetError("REGULAR_EXPRESSION argument given without a regex.");
  51. return false;
  52. }
  53. doingFiles = false;
  54. } else if (args[i] == "FILES") {
  55. // Next arguments will specify files.
  56. doingFiles = true;
  57. } else if (doingFiles) {
  58. // Convert name to full path and add to the group's list.
  59. std::string src = args[i];
  60. if (!cmSystemTools::FileIsFullPath(src.c_str())) {
  61. src = this->Makefile->GetCurrentSourceDirectory();
  62. src += "/";
  63. src += args[i];
  64. }
  65. src = cmSystemTools::CollapseFullPath(src.c_str());
  66. sg->AddGroupFile(src);
  67. } else {
  68. std::ostringstream err;
  69. err << "Unknown argument \"" << args[i] << "\". "
  70. << "Perhaps the FILES keyword is missing.\n";
  71. this->SetError(err.str());
  72. return false;
  73. }
  74. }
  75. return true;
  76. }