cmSourceGroupCommand.cxx 2.43 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3 4
#include "cmSourceGroupCommand.h"

5 6 7 8 9 10 11 12
#include <sstream>

#include "cmMakefile.h"
#include "cmSourceGroup.h"
#include "cmSystemTools.h"

class cmExecutionStatus;

13
// cmSourceGroupCommand
14 15
bool cmSourceGroupCommand::InitialPass(std::vector<std::string> const& args,
                                       cmExecutionStatus&)
16
{
17
  if (args.empty()) {
18 19
    this->SetError("called with incorrect number of arguments");
    return false;
20
  }
21 22

  std::string delimiter = "\\";
23
  if (this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER")) {
24
    delimiter = this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER");
25
  }
26

27 28
  std::vector<std::string> folders =
    cmSystemTools::tokenize(args[0], delimiter);
29

Daniel Pfeifer's avatar
Daniel Pfeifer committed
30
  cmSourceGroup* sg = CM_NULLPTR;
31
  sg = this->Makefile->GetSourceGroup(folders);
32
  if (!sg) {
33 34
    this->Makefile->AddSourceGroup(folders);
    sg = this->Makefile->GetSourceGroup(folders);
35
  }
36

37
  if (!sg) {
38 39
    this->SetError("Could not create or find source group");
    return false;
40
  }
41 42
  // If only two arguments are given, the pre-1.8 version of the
  // command is being invoked.
43
  if (args.size() == 2 && args[1] != "FILES") {
44 45
    sg->SetGroupRegex(args[1].c_str());
    return true;
46
  }
47

48 49
  // Process arguments.
  bool doingFiles = false;
50 51
  for (unsigned int i = 1; i < args.size(); ++i) {
    if (args[i] == "REGULAR_EXPRESSION") {
52
      // Next argument must specify the regex.
53
      if (i + 1 < args.size()) {
54 55
        ++i;
        sg->SetGroupRegex(args[i].c_str());
56
      } else {
57 58 59
        this->SetError("REGULAR_EXPRESSION argument given without a regex.");
        return false;
      }
60 61
      doingFiles = false;
    } else if (args[i] == "FILES") {
62 63
      // Next arguments will specify files.
      doingFiles = true;
64
    } else if (doingFiles) {
65
      // Convert name to full path and add to the group's list.
66
      std::string src = args[i];
67
      if (!cmSystemTools::FileIsFullPath(src.c_str())) {
68
        src = this->Makefile->GetCurrentSourceDirectory();
69 70
        src += "/";
        src += args[i];
71
      }
72
      src = cmSystemTools::CollapseFullPath(src);
73
      sg->AddGroupFile(src);
74
    } else {
75
      std::ostringstream err;
76
      err << "Unknown argument \"" << args[i] << "\".  "
77
          << "Perhaps the FILES keyword is missing.\n";
78
      this->SetError(err.str());
79
      return false;
80
    }
81
  }
82

83
  return true;
84
}