diff options
author | Aleix Pol <aleixpol@kde.org> | 2017-04-06 02:14:35 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-04-20 12:59:07 (GMT) |
commit | 0903531964cff8888dd1cbf2a9c82ac6bb9a522f (patch) | |
tree | 2cf7d844d3ee291ecb5ba77547bddb0a490aa150 /Source/cmQtAutoGenerators.cxx | |
parent | 135611176c5d4958b9b5a36c63fada8a9e4fb1ef (diff) | |
download | CMake-0903531964cff8888dd1cbf2a9c82ac6bb9a522f.zip CMake-0903531964cff8888dd1cbf2a9c82ac6bb9a522f.tar.gz CMake-0903531964cff8888dd1cbf2a9c82ac6bb9a522f.tar.bz2 |
Autogen: Pass explicit predefines header to moc if possible
Qt is relying on whoever calls moc to include a file with the predefined
values that will be used by the compiler, otherwise moc takes wrong
paths and weird things happen.
Instead, generate an include file and feed it to all mocs to make sure
it's generating correct code.
Co-Author: Sebastian Holtermann <sebholt@xwmw.org>
Fixes: #16640
Diffstat (limited to 'Source/cmQtAutoGenerators.cxx')
-rw-r--r-- | Source/cmQtAutoGenerators.cxx | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 246dd8d..875062c 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)); } |