Coverage Report

Created: 2026-10-28 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmQTWrapCPPCommand.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 "cmQTWrapCPPCommand.h"
4
5
#include <utility>
6
7
#include <cm/memory>
8
#include <cm/optional>
9
#include <cm/string_view>
10
11
#include "cmCustomCommand.h"
12
#include "cmCustomCommandLines.h"
13
#include "cmExecutionStatus.h"
14
#include "cmMakefile.h"
15
#include "cmRange.h"
16
#include "cmSourceFile.h"
17
#include "cmStringAlgorithms.h"
18
#include "cmSystemTools.h"
19
20
bool cmQTWrapCPPCommand(std::vector<std::string> const& args,
21
                        cmExecutionStatus& status)
22
0
{
23
0
  if (args.size() < 3) {
24
0
    status.SetError("called with incorrect number of arguments");
25
0
    return false;
26
0
  }
27
28
0
  cmMakefile& mf = status.GetMakefile();
29
30
  // Get the moc executable to run in the custom command.
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& sourceList = args[1];
35
0
  std::string sourceListValue = mf.GetSafeDefinition(sourceList);
36
37
  // Create a rule for all sources listed.
38
0
  for (std::string const& arg : cmMakeRange(args).advance(2)) {
39
0
    cmSourceFile* curr = mf.GetSource(arg);
40
    // if we should wrap the class
41
0
    if (!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE"))) {
42
      // Compute the name of the file to generate.
43
0
      std::string srcName =
44
0
        cmSystemTools::GetFilenameWithoutLastExtension(arg);
45
0
      std::string newName =
46
0
        cmStrCat(mf.GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx");
47
0
      cmSourceFile* sf = mf.GetOrCreateSource(newName, true);
48
0
      sf->SetSpecialSourceType(
49
0
        cmSourceFile::SpecialSourceType::QtWrapCppSource);
50
0
      if (curr) {
51
0
        sf->SetProperty("ABSTRACT", curr->GetProperty("ABSTRACT"));
52
0
      }
53
54
      // Compute the name of the header from which to generate the file.
55
0
      std::string hname;
56
0
      if (cmSystemTools::FileIsFullPath(arg)) {
57
0
        hname = arg;
58
0
      } else {
59
0
        if (curr && curr->GetIsGenerated()) {
60
0
          hname = mf.GetCurrentBinaryDirectory();
61
0
        } else {
62
0
          hname = mf.GetCurrentSourceDirectory();
63
0
        }
64
0
        hname += "/";
65
0
        hname += arg;
66
0
      }
67
68
      // Append the generated source file to the list.
69
0
      if (!sourceListValue.empty()) {
70
0
        sourceListValue += ";";
71
0
      }
72
0
      sourceListValue += newName;
73
74
      // Create the custom command to generate the file.
75
0
      cmCustomCommandLines commandLines =
76
0
        cmMakeSingleCommandLine({ moc_exe, "-o", newName, hname });
77
78
0
      std::vector<std::string> depends;
79
0
      depends.push_back(moc_exe);
80
0
      depends.push_back(hname);
81
82
0
      auto cc = cm::make_unique<cmCustomCommand>();
83
0
      cc->SetOutputs(newName);
84
0
      cc->SetDepends(depends);
85
0
      cc->SetCommandLines(commandLines);
86
0
      cc->SetComment("Qt Wrapped File");
87
0
      mf.AddCustomCommandToOutput(std::move(cc));
88
0
    }
89
0
  }
90
91
  // Store the final list of source files.
92
0
  mf.AddDefinition(sourceList, sourceListValue);
93
0
  return true;
94
0
}