cmDefinePropertyCommand.cxx 2.89 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
#include "cmDefinePropertyCommand.h"
4

5 6 7 8
#include <sstream>

#include "cmMakefile.h"
#include "cmProperty.h"
9
#include "cmState.h"
10 11

class cmExecutionStatus;
12

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

21
  // Get the scope in which to define the property.
22
  cmProperty::ScopeType scope;
23
  if (args[0] == "GLOBAL") {
24
    scope = cmProperty::GLOBAL;
25
  } else if (args[0] == "DIRECTORY") {
26
    scope = cmProperty::DIRECTORY;
27
  } else if (args[0] == "TARGET") {
28
    scope = cmProperty::TARGET;
29
  } else if (args[0] == "SOURCE") {
30
    scope = cmProperty::SOURCE_FILE;
31
  } else if (args[0] == "TEST") {
32
    scope = cmProperty::TEST;
33
  } else if (args[0] == "VARIABLE") {
34
    scope = cmProperty::VARIABLE;
35
  } else if (args[0] == "CACHED_VARIABLE") {
36
    scope = cmProperty::CACHED_VARIABLE;
37
  } else {
38
    std::ostringstream e;
39 40 41 42
    e << "given invalid scope " << args[0] << ".  "
      << "Valid scopes are "
      << "GLOBAL, DIRECTORY, TARGET, SOURCE, "
      << "TEST, VARIABLE, CACHED_VARIABLE.";
43
    this->SetError(e.str());
44
    return false;
45
  }
46

47 48
  // Parse remaining arguments.
  bool inherited = false;
49 50 51 52 53 54 55
  enum Doing
  {
    DoingNone,
    DoingProperty,
    DoingBrief,
    DoingFull
  };
56
  Doing doing = DoingNone;
57 58
  for (unsigned int i = 1; i < args.size(); ++i) {
    if (args[i] == "PROPERTY") {
59
      doing = DoingProperty;
60
    } else if (args[i] == "BRIEF_DOCS") {
61
      doing = DoingBrief;
62
    } else if (args[i] == "FULL_DOCS") {
63
      doing = DoingFull;
64
    } else if (args[i] == "INHERITED") {
65 66
      doing = DoingNone;
      inherited = true;
67
    } else if (doing == DoingProperty) {
68 69
      doing = DoingNone;
      this->PropertyName = args[i];
70
    } else if (doing == DoingBrief) {
71
      this->BriefDocs += args[i];
72
    } else if (doing == DoingFull) {
73
      this->FullDocs += args[i];
74
    } else {
75
      std::ostringstream e;
76
      e << "given invalid argument \"" << args[i] << "\".";
77
      this->SetError(e.str());
78 79
      return false;
    }
80
  }
81 82

  // Make sure a property name was found.
83
  if (this->PropertyName.empty()) {
84 85
    this->SetError("not given a PROPERTY <name> argument.");
    return false;
86
  }
87 88

  // Make sure documentation was given.
89
  if (this->BriefDocs.empty()) {
90 91
    this->SetError("not given a BRIEF_DOCS <brief-doc> argument.");
    return false;
92 93
  }
  if (this->FullDocs.empty()) {
94 95
    this->SetError("not given a FULL_DOCS <full-doc> argument.");
    return false;
96
  }
97 98

  // Actually define the property.
99 100 101
  this->Makefile->GetState()->DefineProperty(
    this->PropertyName, scope, this->BriefDocs.c_str(), this->FullDocs.c_str(),
    inherited);
102

103 104
  return true;
}