cmQTWrapUICommand.cxx 4.59 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 "cmQTWrapUICommand.h"

5 6
#include "cmCustomCommandLines.h"
#include "cmMakefile.h"
7
#include "cmRange.h"
8 9 10
#include "cmSourceFile.h"
#include "cmSystemTools.h"

11 12
#include <utility>

13 14
class cmExecutionStatus;

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

  // Get the uic and moc executables to run in the custom commands.
25
  std::string const& uic_exe =
26
    this->Makefile->GetRequiredDefinition("QT_UIC_EXECUTABLE");
27
  std::string const& moc_exe =
28 29 30 31 32
    this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");

  // Get the variable holding the list of sources.
  std::string const& headerList = args[1];
  std::string const& sourceList = args[2];
33 34
  std::string headerListValue = this->Makefile->GetSafeDefinition(headerList);
  std::string sourceListValue = this->Makefile->GetSafeDefinition(sourceList);
35 36

  // Create rules for all sources listed.
37 38
  for (std::string const& arg : cmMakeRange(args).advance(3)) {
    cmSourceFile* curr = this->Makefile->GetSource(arg);
39
    // if we should wrap the class
40
    if (!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE"))) {
41
      // Compute the name of the files to generate.
42 43
      std::string srcName =
        cmSystemTools::GetFilenameWithoutLastExtension(arg);
44
      std::string hName = this->Makefile->GetCurrentBinaryDirectory();
45 46 47
      hName += "/";
      hName += srcName;
      hName += ".h";
48
      std::string cxxName = this->Makefile->GetCurrentBinaryDirectory();
49 50 51
      cxxName += "/";
      cxxName += srcName;
      cxxName += ".cxx";
52
      std::string mocName = this->Makefile->GetCurrentBinaryDirectory();
53 54 55 56 57 58
      mocName += "/moc_";
      mocName += srcName;
      mocName += ".cxx";

      // Compute the name of the ui file from which to generate others.
      std::string uiName;
59 60
      if (cmSystemTools::FileIsFullPath(arg)) {
        uiName = arg;
61
      } else {
62
        if (curr && curr->GetIsGenerated()) {
63
          uiName = this->Makefile->GetCurrentBinaryDirectory();
64
        } else {
65
          uiName = this->Makefile->GetCurrentSourceDirectory();
66
        }
67
        uiName += "/";
68
        uiName += arg;
69
      }
70 71

      // create the list of headers
72
      if (!headerListValue.empty()) {
73
        headerListValue += ";";
74
      }
75 76
      headerListValue += hName;

77
      // create the list of sources
78
      if (!sourceListValue.empty()) {
79
        sourceListValue += ";";
80
      }
81
      sourceListValue += cxxName;
82
      sourceListValue += ";";
83 84 85 86 87 88 89 90 91
      sourceListValue += mocName;

      // set up .ui to .h and .cxx command
      cmCustomCommandLine hCommand;
      hCommand.push_back(uic_exe);
      hCommand.push_back("-o");
      hCommand.push_back(hName);
      hCommand.push_back(uiName);
      cmCustomCommandLines hCommandLines;
92
      hCommandLines.push_back(std::move(hCommand));
93 94 95 96 97 98 99 100 101

      cmCustomCommandLine cxxCommand;
      cxxCommand.push_back(uic_exe);
      cxxCommand.push_back("-impl");
      cxxCommand.push_back(hName);
      cxxCommand.push_back("-o");
      cxxCommand.push_back(cxxName);
      cxxCommand.push_back(uiName);
      cmCustomCommandLines cxxCommandLines;
102
      cxxCommandLines.push_back(std::move(cxxCommand));
103 104 105 106 107 108 109

      cmCustomCommandLine mocCommand;
      mocCommand.push_back(moc_exe);
      mocCommand.push_back("-o");
      mocCommand.push_back(mocName);
      mocCommand.push_back(hName);
      cmCustomCommandLines mocCommandLines;
110
      mocCommandLines.push_back(std::move(mocCommand));
111 112 113

      std::vector<std::string> depends;
      depends.push_back(uiName);
114
      std::string no_main_dependency;
Daniel Pfeifer's avatar
Daniel Pfeifer committed
115 116
      const char* no_comment = nullptr;
      const char* no_working_dir = nullptr;
117 118 119
      this->Makefile->AddCustomCommandToOutput(
        hName, depends, no_main_dependency, hCommandLines, no_comment,
        no_working_dir);
120 121

      depends.push_back(hName);
122 123 124
      this->Makefile->AddCustomCommandToOutput(
        cxxName, depends, no_main_dependency, cxxCommandLines, no_comment,
        no_working_dir);
125 126 127

      depends.clear();
      depends.push_back(hName);
128 129 130
      this->Makefile->AddCustomCommandToOutput(
        mocName, depends, no_main_dependency, mocCommandLines, no_comment,
        no_working_dir);
131
    }
132
  }
133

134
  // Store the final list of source files and headers.
135 136
  this->Makefile->AddDefinition(sourceList, sourceListValue.c_str());
  this->Makefile->AddDefinition(headerList, headerListValue.c_str());
137
  return true;
138
}