cmSourceGroupCommand.cxx 2.4 KB

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