Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmQTWrapUICommand.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#include "cmQTWrapUICommand.h"
4
5
#include <utility>
6
7
#include <cm/memory>
8
#include <cm/string_view>
9
10
#include "cmCustomCommand.h"
11
#include "cmCustomCommandLines.h"
12
#include "cmExecutionStatus.h"
13
#include "cmMakefile.h"
14
#include "cmRange.h"
15
#include "cmSourceFile.h"
16
#include "cmStringAlgorithms.h"
17
#include "cmSystemTools.h"
18
19
bool cmQTWrapUICommand(std::vector<std::string> const& args,
20
                       cmExecutionStatus& status)
21
0
{
22
0
  if (args.size() < 4) {
23
0
    status.SetError("called with incorrect number of arguments");
24
0
    return false;
25
0
  }
26
27
0
  cmMakefile& mf = status.GetMakefile();
28
29
  // Get the uic and moc executables to run in the custom commands.
30
0
  std::string const& uic_exe = mf.GetRequiredDefinition("QT_UIC_EXECUTABLE");
31
0
  std::string const& moc_exe = mf.GetRequiredDefinition("QT_MOC_EXECUTABLE");
32
33
  // Get the variable holding the list of sources.
34
0
  std::string const& headerList = args[1];
35
0
  std::string const& sourceList = args[2];
36
0
  std::string headerListValue = mf.GetSafeDefinition(headerList);
37
0
  std::string sourceListValue = mf.GetSafeDefinition(sourceList);
38
39
  // Create rules for all sources listed.
40
0
  for (std::string const& arg : cmMakeRange(args).advance(3)) {
41
0
    cmSourceFile* curr = mf.GetSource(arg);
42
    // if we should wrap the class
43
0
    if (!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE"))) {
44
      // Compute the name of the files to generate.
45
0
      std::string srcName =
46
0
        cmSystemTools::GetFilenameWithoutLastExtension(arg);
47
0
      std::string hName =
48
0
        cmStrCat(mf.GetCurrentBinaryDirectory(), '/', srcName, ".h");
49
0
      std::string cxxName =
50
0
        cmStrCat(mf.GetCurrentBinaryDirectory(), '/', srcName, ".cxx");
51
0
      std::string mocName =
52
0
        cmStrCat(mf.GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx");
53
54
      // Compute the name of the ui file from which to generate others.
55
0
      std::string uiName;
56
0
      if (cmSystemTools::FileIsFullPath(arg)) {
57
0
        uiName = arg;
58
0
      } else {
59
0
        if (curr && curr->GetIsGenerated()) {
60
0
          uiName = mf.GetCurrentBinaryDirectory();
61
0
        } else {
62
0
          uiName = mf.GetCurrentSourceDirectory();
63
0
        }
64
0
        uiName += "/";
65
0
        uiName += arg;
66
0
      }
67
68
      // create the list of headers
69
0
      if (!headerListValue.empty()) {
70
0
        headerListValue += ";";
71
0
      }
72
0
      headerListValue += hName;
73
74
      // create the list of sources
75
0
      if (!sourceListValue.empty()) {
76
0
        sourceListValue += ";";
77
0
      }
78
0
      sourceListValue += cxxName;
79
0
      sourceListValue += ";";
80
0
      sourceListValue += mocName;
81
82
      // set up .ui to .h and .cxx command
83
0
      cmCustomCommandLines hCommandLines =
84
0
        cmMakeSingleCommandLine({ uic_exe, "-o", hName, uiName });
85
0
      cmCustomCommandLines cxxCommandLines = cmMakeSingleCommandLine(
86
0
        { uic_exe, "-impl", hName, "-o", cxxName, uiName });
87
0
      cmCustomCommandLines mocCommandLines =
88
0
        cmMakeSingleCommandLine({ moc_exe, "-o", mocName, hName });
89
90
0
      std::vector<std::string> depends;
91
0
      depends.push_back(uiName);
92
0
      auto cc = cm::make_unique<cmCustomCommand>();
93
0
      cc->SetOutputs(hName);
94
0
      cc->SetDepends(depends);
95
0
      cc->SetCommandLines(hCommandLines);
96
0
      mf.AddCustomCommandToOutput(std::move(cc));
97
98
0
      depends.push_back(hName);
99
0
      cc = cm::make_unique<cmCustomCommand>();
100
0
      cc->SetOutputs(cxxName);
101
0
      cc->SetDepends(depends);
102
0
      cc->SetCommandLines(cxxCommandLines);
103
0
      mf.AddCustomCommandToOutput(std::move(cc));
104
105
0
      depends.clear();
106
0
      depends.push_back(hName);
107
0
      cc = cm::make_unique<cmCustomCommand>();
108
0
      cc->SetOutputs(mocName);
109
0
      cc->SetDepends(depends);
110
0
      cc->SetCommandLines(mocCommandLines);
111
0
      mf.AddCustomCommandToOutput(std::move(cc));
112
0
    }
113
0
  }
114
115
  // Store the final list of source files and headers.
116
0
  mf.AddDefinition(sourceList, sourceListValue);
117
0
  mf.AddDefinition(headerList, headerListValue);
118
0
  return true;
119
0
}