summaryrefslogtreecommitdiffstats
path: root/Source/cmQtAutoGenerators.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-04-21 12:42:38 (GMT)
committerKitware Robot <kwrobot@kitware.com>2017-04-21 12:43:43 (GMT)
commit2b7aecba1663f86148b8c2f1033cfcbd87453ad3 (patch)
treed13754063e6795fcbab8f492dbf69fe7dcdf36a2 /Source/cmQtAutoGenerators.cxx
parent1b0c7bca5ede6eb3965cb23471c6530a08d0d2d5 (diff)
parent0903531964cff8888dd1cbf2a9c82ac6bb9a522f (diff)
downloadCMake-2b7aecba1663f86148b8c2f1033cfcbd87453ad3.zip
CMake-2b7aecba1663f86148b8c2f1033cfcbd87453ad3.tar.gz
CMake-2b7aecba1663f86148b8c2f1033cfcbd87453ad3.tar.bz2
Merge topic 'autogen-fixes'
09035319 Autogen: Pass explicit predefines header to moc if possible Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !671
Diffstat (limited to 'Source/cmQtAutoGenerators.cxx')
-rw-r--r--Source/cmQtAutoGenerators.cxx63
1 files changed, 60 insertions, 3 deletions
diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx
index 88ec9e8..d142693 100644
--- a/Source/cmQtAutoGenerators.cxx
+++ b/Source/cmQtAutoGenerators.cxx
@@ -360,6 +360,8 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile(
InfoGet(makefile, "AM_QT_MOC_EXECUTABLE", this->MocExecutable);
InfoGet(makefile, "AM_QT_UIC_EXECUTABLE", this->UicExecutable);
InfoGet(makefile, "AM_QT_RCC_EXECUTABLE", this->RccExecutable);
+
+ InfoGet(makefile, "AM_MOC_PREDEFS_CMD", this->MocPredefsCmd);
// Check Qt version
if ((this->QtMajorVersion != "4") && (this->QtMajorVersion != "5")) {
this->LogError("AutoGen: Error: Unsupported Qt version: " +
@@ -579,6 +581,12 @@ void cmQtAutoGenerators::Init(cmMakefile* makefile)
this->MocCppFilenameAbs = this->CurrentBinaryDir + this->MocCppFilenameRel;
+ // Moc predefs file
+ if (!this->MocPredefsCmd.empty()) {
+ this->MocPredefsFileRel = this->AutogenBuildSubDir + "moc_predefs.h";
+ this->MocPredefsFileAbs = this->CurrentBinaryDir + this->MocPredefsFileRel;
+ }
+
// Init file path checksum generator
fpathCheckSum.setupParentDirs(this->CurrentSourceDir, this->CurrentBinaryDir,
this->ProjectSourceDir,
@@ -1142,6 +1150,50 @@ bool cmQtAutoGenerators::MocGenerateAll(
return true;
}
+ // Generate moc_predefs
+ if (!this->MocPredefsCmd.empty()) {
+ if (!this->MakeParentDirectory(this->MocPredefsFileAbs)) {
+ this->LogError("AutoMoc: Error creating directory for " +
+ this->MocPredefsFileRel);
+ return false;
+ }
+ this->LogBold("Generating MOC predefs " + this->MocPredefsFileRel);
+
+ std::vector<std::string> cmd = this->MocPredefsCmd;
+ cmd.insert(cmd.end(), this->MocIncludes.begin(), this->MocIncludes.end());
+ for (std::vector<std::string>::const_iterator it =
+ this->MocDefinitions.begin();
+ it != this->MocDefinitions.end(); ++it) {
+ cmd.push_back("-D" + (*it));
+ }
+ cmd.insert(cmd.end(), this->MocOptions.begin(), this->MocOptions.end());
+
+ std::string output;
+ bool moc_predefsGenerated = this->RunCommand(cmd, output, false);
+ if (!moc_predefsGenerated) {
+ return false;
+ }
+
+ // actually write the file
+ cmsys::ofstream outfile;
+ outfile.open(this->MocPredefsFileAbs.c_str(), std::ios::trunc);
+ if (!outfile) {
+ moc_predefsGenerated = false;
+ this->LogError("AutoMoc: Error opening " + this->MocPredefsFileRel);
+ } else {
+ outfile << output;
+ // Check for write errors
+ if (!outfile.good()) {
+ moc_predefsGenerated = false;
+ this->LogError("AutoMoc: Error writing " + this->MocPredefsFileRel);
+ }
+ }
+
+ if (!moc_predefsGenerated) {
+ return false;
+ }
+ }
+
bool mocCompFileGenerated = false;
bool mocCompChanged = false;
@@ -1305,6 +1357,10 @@ bool cmQtAutoGenerators::MocGenerateFile(
cmd.push_back("-D" + (*it));
}
cmd.insert(cmd.end(), this->MocOptions.begin(), this->MocOptions.end());
+ if (!this->MocPredefsFileAbs.empty()) {
+ cmd.push_back("--include");
+ cmd.push_back(this->MocPredefsFileAbs);
+ }
#ifdef _WIN32
cmd.push_back("-DWIN32");
#endif
@@ -1805,7 +1861,7 @@ bool cmQtAutoGenerators::MakeParentDirectory(const std::string& filename) const
* @return True on success
*/
bool cmQtAutoGenerators::RunCommand(const std::vector<std::string>& command,
- std::string& output) const
+ std::string& output, bool verbose) const
{
// Log command
if (this->Verbose) {
@@ -1813,8 +1869,9 @@ bool cmQtAutoGenerators::RunCommand(const std::vector<std::string>& command,
}
// Execute command
int retVal = 0;
- bool res =
- cmSystemTools::RunSingleCommand(command, &output, &output, &retVal);
+ bool res = cmSystemTools::RunSingleCommand(
+ command, &output, &output, &retVal, CM_NULLPTR,
+ verbose ? cmSystemTools::OUTPUT_MERGE : cmSystemTools::OUTPUT_NONE);
return (res && (retVal == 0));
}