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