cmake/Source/cmQTWrapUICommand.cxx

108 lines
3.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 "cmQTWrapUICommand.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"
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 cmQTWrapUICommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
2016-07-09 11:21:54 +02:00
if (args.size() < 4) {
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 uic and moc executables to run in the custom commands.
2020-02-01 23:06:01 +01:00
std::string const& uic_exe = mf.GetRequiredDefinition("QT_UIC_EXECUTABLE");
std::string const& moc_exe = mf.GetRequiredDefinition("QT_MOC_EXECUTABLE");
// Get the variable holding the list of sources.
std::string const& headerList = args[1];
std::string const& sourceList = args[2];
2020-02-01 23:06:01 +01:00
std::string headerListValue = mf.GetSafeDefinition(headerList);
std::string sourceListValue = mf.GetSafeDefinition(sourceList);
// Create rules for all sources listed.
2019-11-11 23:01:05 +01:00
for (std::string const& arg : cmMakeRange(args).advance(3)) {
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 files 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 hName =
cmStrCat(mf.GetCurrentBinaryDirectory(), '/', srcName, ".h");
std::string cxxName =
cmStrCat(mf.GetCurrentBinaryDirectory(), '/', srcName, ".cxx");
std::string mocName =
cmStrCat(mf.GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx");
// Compute the name of the ui file from which to generate others.
std::string uiName;
2019-11-11 23:01:05 +01:00
if (cmSystemTools::FileIsFullPath(arg)) {
uiName = 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
uiName = mf.GetCurrentBinaryDirectory();
2016-07-09 11:21:54 +02:00
} else {
2020-02-01 23:06:01 +01:00
uiName = mf.GetCurrentSourceDirectory();
2016-07-09 11:21:54 +02:00
}
uiName += "/";
2019-11-11 23:01:05 +01:00
uiName += arg;
2016-07-09 11:21:54 +02:00
}
// create the list of headers
2016-07-09 11:21:54 +02:00
if (!headerListValue.empty()) {
headerListValue += ";";
2016-07-09 11:21:54 +02:00
}
headerListValue += hName;
// create the list of sources
2016-07-09 11:21:54 +02:00
if (!sourceListValue.empty()) {
sourceListValue += ";";
2016-07-09 11:21:54 +02:00
}
sourceListValue += cxxName;
sourceListValue += ";";
sourceListValue += mocName;
// set up .ui to .h and .cxx command
2020-02-01 23:06:01 +01:00
cmCustomCommandLines hCommandLines =
cmMakeSingleCommandLine({ uic_exe, "-o", hName, uiName });
cmCustomCommandLines cxxCommandLines = cmMakeSingleCommandLine(
{ uic_exe, "-impl", hName, "-o", cxxName, uiName });
cmCustomCommandLines mocCommandLines =
cmMakeSingleCommandLine({ moc_exe, "-o", mocName, hName });
std::vector<std::string> depends;
depends.push_back(uiName);
2017-04-14 19:02:05 +02:00
std::string no_main_dependency;
2018-01-26 17:06:56 +01:00
const char* no_comment = nullptr;
const char* no_working_dir = nullptr;
2020-02-01 23:06:01 +01:00
mf.AddCustomCommandToOutput(hName, depends, no_main_dependency,
hCommandLines, no_comment, no_working_dir);
depends.push_back(hName);
2020-02-01 23:06:01 +01:00
mf.AddCustomCommandToOutput(cxxName, depends, no_main_dependency,
cxxCommandLines, no_comment, no_working_dir);
depends.clear();
depends.push_back(hName);
2020-02-01 23:06:01 +01:00
mf.AddCustomCommandToOutput(mocName, depends, no_main_dependency,
mocCommandLines, no_comment, no_working_dir);
}
2016-07-09 11:21:54 +02:00
}
// Store the final list of source files and headers.
2020-02-01 23:06:01 +01:00
mf.AddDefinition(sourceList, sourceListValue);
mf.AddDefinition(headerList, headerListValue);
return true;
}