cmSetSourceFilesPropertiesCommand.cxx 3.92 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 "cmSetSourceFilesPropertiesCommand.h"

5
#include "cmMakefile.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
6
#include "cmSourceFile.h"
7
#include "cmSystemTools.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
8

9 10
class cmExecutionStatus;

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

20 21 22 23 24
  // break the arguments into source file names and properties
  int numFiles = 0;
  std::vector<std::string>::const_iterator j;
  j = args.begin();
  // old style allows for specifier before PROPERTIES keyword
25 26 27
  while (j != args.end() && *j != "ABSTRACT" && *j != "WRAP_EXCLUDE" &&
         *j != "GENERATED" && *j != "COMPILE_FLAGS" &&
         *j != "OBJECT_DEPENDS" && *j != "PROPERTIES") {
28 29
    numFiles++;
    ++j;
30
  }
31

32
  // now call the worker function
33
  std::string errors;
34 35 36 37
  bool ret = cmSetSourceFilesPropertiesCommand::RunCommand(
    this->Makefile, args.begin(), args.begin() + numFiles,
    args.begin() + numFiles, args.end(), errors);
  if (!ret) {
38
    this->SetError(errors);
39
  }
40 41 42
  return ret;
}

43 44 45 46 47
bool cmSetSourceFilesPropertiesCommand::RunCommand(
  cmMakefile* mf, std::vector<std::string>::const_iterator filebeg,
  std::vector<std::string>::const_iterator fileend,
  std::vector<std::string>::const_iterator propbeg,
  std::vector<std::string>::const_iterator propend, std::string& errors)
48
{
49
  std::vector<std::string> propertyPairs;
50
  bool generated = false;
51
  std::vector<std::string>::const_iterator j;
52
  // build the property pairs
53
  for (j = propbeg; j != propend; ++j) {
54
    // old style allows for specifier before PROPERTIES keyword
55
    if (*j == "ABSTRACT") {
wahikihiki's avatar
wahikihiki committed
56 57
      propertyPairs.emplace_back("ABSTRACT");
      propertyPairs.emplace_back("1");
58
    } else if (*j == "WRAP_EXCLUDE") {
wahikihiki's avatar
wahikihiki committed
59 60
      propertyPairs.emplace_back("WRAP_EXCLUDE");
      propertyPairs.emplace_back("1");
61
    } else if (*j == "GENERATED") {
62
      generated = true;
wahikihiki's avatar
wahikihiki committed
63 64
      propertyPairs.emplace_back("GENERATED");
      propertyPairs.emplace_back("1");
65
    } else if (*j == "COMPILE_FLAGS") {
wahikihiki's avatar
wahikihiki committed
66
      propertyPairs.emplace_back("COMPILE_FLAGS");
67
      ++j;
68
      if (j == propend) {
69
        errors = "called with incorrect number of arguments "
70
                 "COMPILE_FLAGS with no flags";
71 72
        return false;
      }
73 74
      propertyPairs.push_back(*j);
    } else if (*j == "OBJECT_DEPENDS") {
wahikihiki's avatar
wahikihiki committed
75
      propertyPairs.emplace_back("OBJECT_DEPENDS");
76
      ++j;
77
      if (j == propend) {
78
        errors = "called with incorrect number of arguments "
79
                 "OBJECT_DEPENDS with no dependencies";
80 81
        return false;
      }
82 83
      propertyPairs.push_back(*j);
    } else if (*j == "PROPERTIES") {
84 85
      // now loop through the rest of the arguments, new style
      ++j;
86
      while (j != propend) {
87
        propertyPairs.push_back(*j);
88
        if (*j == "GENERATED") {
89
          ++j;
90
          if (j != propend && cmSystemTools::IsOn(*j)) {
91 92
            generated = true;
          }
93
        } else {
94
          ++j;
95 96
        }
        if (j == propend) {
97
          errors = "called with incorrect number of arguments.";
98
          return false;
99
        }
100
        propertyPairs.push_back(*j);
101
        ++j;
102
      }
Ken Martin's avatar
Ken Martin committed
103 104
      // break out of the loop because j is already == end
      break;
105
    } else {
106
      errors = "called with illegal arguments, maybe missing a "
107
               "PROPERTIES specifier?";
108
      return false;
109
    }
110
  }
111

112
  // now loop over all the files
113
  for (j = filebeg; j != fileend; ++j) {
114
    // get the source file
115 116
    cmSourceFile* sf = mf->GetOrCreateSource(*j, generated);
    if (sf) {
117
      // now loop through all the props and set them
118
      unsigned int k;
119 120
      for (k = 0; k < propertyPairs.size(); k = k + 2) {
        sf->SetProperty(propertyPairs[k], propertyPairs[k + 1].c_str());
121 122
      }
    }
123
  }
124 125
  return true;
}