cmake/Source/cmQTWrapCPPCommand.cxx

87 lines
2.8 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmQTWrapCPPCommand.h"
2017-04-14 19:02:05 +02:00
#include "cmCustomCommandLines.h"
2020-02-01 23:06:01 +01:00
#include "cmExecutionStatus.h"
2017-04-14 19:02:05 +02:00
#include "cmMakefile.h"
2020-08-30 11:54:41 +02:00
#include "cmProperty.h"
2019-11-11 23:01:05 +01:00
#include "cmRange.h"
2017-04-14 19:02:05 +02:00
#include "cmSourceFile.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2017-04-14 19:02:05 +02:00
#include "cmSystemTools.h"
2020-02-01 23:06:01 +01:00
bool cmQTWrapCPPCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
2016-07-09 11:21:54 +02:00
if (args.size() < 3) {
2020-02-01 23:06:01 +01:00
status.SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
cmMakefile& mf = status.GetMakefile();
// Get the moc executable to run in the custom command.
2020-02-01 23:06:01 +01:00
std::string const& moc_exe = mf.GetRequiredDefinition("QT_MOC_EXECUTABLE");
// Get the variable holding the list of sources.
std::string const& sourceList = args[1];
2020-02-01 23:06:01 +01:00
std::string sourceListValue = mf.GetSafeDefinition(sourceList);
// Create a rule for all sources listed.
2019-11-11 23:01:05 +01:00
for (std::string const& arg : cmMakeRange(args).advance(2)) {
2020-02-01 23:06:01 +01:00
cmSourceFile* curr = mf.GetSource(arg);
// if we should wrap the class
2016-07-09 11:21:54 +02:00
if (!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE"))) {
// Compute the name of the file to generate.
2019-11-11 23:01:05 +01:00
std::string srcName =
cmSystemTools::GetFilenameWithoutLastExtension(arg);
2020-02-01 23:06:01 +01:00
std::string newName =
cmStrCat(mf.GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx");
cmSourceFile* sf = mf.GetOrCreateSource(newName, true);
2016-07-09 11:21:54 +02:00
if (curr) {
2020-08-30 11:54:41 +02:00
cmProp p = curr->GetProperty("ABSTRACT");
sf->SetProperty("ABSTRACT", p ? p->c_str() : nullptr);
2016-07-09 11:21:54 +02:00
}
// Compute the name of the header from which to generate the file.
std::string hname;
2019-11-11 23:01:05 +01:00
if (cmSystemTools::FileIsFullPath(arg)) {
hname = arg;
2016-07-09 11:21:54 +02:00
} else {
2019-11-11 23:01:05 +01:00
if (curr && curr->GetIsGenerated()) {
2020-02-01 23:06:01 +01:00
hname = mf.GetCurrentBinaryDirectory();
2016-07-09 11:21:54 +02:00
} else {
2020-02-01 23:06:01 +01:00
hname = mf.GetCurrentSourceDirectory();
2016-07-09 11:21:54 +02:00
}
hname += "/";
2019-11-11 23:01:05 +01:00
hname += arg;
2016-07-09 11:21:54 +02:00
}
// Append the generated source file to the list.
2016-07-09 11:21:54 +02:00
if (!sourceListValue.empty()) {
sourceListValue += ";";
2016-07-09 11:21:54 +02:00
}
sourceListValue += newName;
// Create the custom command to generate the file.
2020-02-01 23:06:01 +01:00
cmCustomCommandLines commandLines =
cmMakeSingleCommandLine({ moc_exe, "-o", newName, hname });
std::vector<std::string> depends;
depends.push_back(moc_exe);
depends.push_back(hname);
2017-04-14 19:02:05 +02:00
std::string no_main_dependency;
2018-01-26 17:06:56 +01:00
const char* no_working_dir = nullptr;
2020-02-01 23:06:01 +01:00
mf.AddCustomCommandToOutput(newName, depends, no_main_dependency,
commandLines, "Qt Wrapped File",
no_working_dir);
}
2016-07-09 11:21:54 +02:00
}
// Store the final list of source files.
2020-02-01 23:06:01 +01:00
mf.AddDefinition(sourceList, sourceListValue);
return true;
}