Commit 8c935838 authored by Sebastian Holtermann's avatar Sebastian Holtermann Committed by Brad King

QtAutogen: Generate included ui_ and moc_ files in _automoc/includes

ui_ and moc_ files that are include in source files get generated in
$CURRENT_BUILD_DIR/$TARGETNAME_automoc/include.
The directory is added to the INCLUDE_DIRECTORIES of the origin target
in the generation stage.

From now on all autogen files get generated below
$CURRENT_BUILD_DIR/$TARGETNAME_automoc.
parent 8f47a5f1
......@@ -658,8 +658,8 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenSources(
{
if (target->GetPropertyAsBool("AUTOMOC")) {
cmMakefile* makefile = target->Target->GetMakefile();
std::string mocCppFile = GetAutogenTargetBuildDir(target);
mocCppFile += "moc_compilation.cpp";
const std::string mocCppFile =
GetAutogenTargetBuildDir(target) + "moc_compilation.cpp";
makefile->GetOrCreateSource(mocCppFile, true);
makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", mocCppFile.c_str(),
false);
......@@ -675,6 +675,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
// Create a custom target for running generators at buildtime
const std::string autogenTargetName = GetAutogenTargetName(target);
const std::string autogenBuildDir = GetAutogenTargetBuildDir(target);
const std::string workingDirectory =
cmSystemTools::CollapseFullPath("", makefile->GetCurrentBinaryDirectory());
......@@ -683,6 +684,18 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR");
}
// Create autogen target build directory
cmSystemTools::MakeDirectory(autogenBuildDir);
// Create autogen target includes directory and
// add it to the origin target INCLUDE_DIRECTORIES
if (target->GetPropertyAsBool("AUTOMOC") ||
target->GetPropertyAsBool("AUTOUIC")) {
const std::string incsDir = autogenBuildDir + "include";
cmSystemTools::MakeDirectory(incsDir);
target->AddIncludeDirectory(incsDir, true);
}
// Initialize autogen target dependencies
std::vector<std::string> depends;
if (const char* autogenDepends =
......
......@@ -986,8 +986,8 @@ void cmQtAutoGenerators::ParseHeaders(
std::string macroName;
if (requiresMocing(contents, macroName)) {
notIncludedMocs[headerName] = this->TargetBuildSubDir +
fpathCheckSum.getPart(headerName) + "/moc_" +
notIncludedMocs[headerName] = fpathCheckSum.getPart(headerName) +
"/moc_" +
cmsys::SystemTools::GetFilenameWithoutLastExtension(headerName) +
".cpp";
}
......@@ -1021,26 +1021,32 @@ bool cmQtAutoGenerators::GenerateMocFiles(
}
// generate moc files that are included by source files.
for (std::map<std::string, std::string>::const_iterator it =
includedMocs.begin();
it != includedMocs.end(); ++it) {
if (!this->GenerateMoc(it->first, it->second)) {
if (this->RunMocFailed) {
return false;
{
const std::string subDirPrefix = "include/";
for (std::map<std::string, std::string>::const_iterator it =
includedMocs.begin();
it != includedMocs.end(); ++it) {
if (!this->GenerateMoc(it->first, it->second, subDirPrefix)) {
if (this->RunMocFailed) {
return false;
}
}
}
}
// generate moc files that are _not_ included by source files.
bool automocCppChanged = false;
for (std::map<std::string, std::string>::const_iterator it =
notIncludedMocs.begin();
it != notIncludedMocs.end(); ++it) {
if (this->GenerateMoc(it->first, it->second)) {
automocCppChanged = true;
} else {
if (this->RunMocFailed) {
return false;
{
const std::string subDirPrefix;
for (std::map<std::string, std::string>::const_iterator it =
notIncludedMocs.begin();
it != notIncludedMocs.end(); ++it) {
if (this->GenerateMoc(it->first, it->second, subDirPrefix)) {
automocCppChanged = true;
} else {
if (this->RunMocFailed) {
return false;
}
}
}
}
......@@ -1054,13 +1060,11 @@ bool cmQtAutoGenerators::GenerateMocFiles(
// Dummy content
outStream << "enum some_compilers { need_more_than_nothing };\n";
} else {
// Includes content
// Valid content
for (std::map<std::string, std::string>::const_iterator it =
notIncludedMocs.begin();
it != notIncludedMocs.end(); ++it) {
outStream << "#include \""
<< it->second.substr(this->TargetBuildSubDir.size())
<< "\"\n";
outStream << "#include \"" << it->second << "\"\n";
}
}
outStream.flush();
......@@ -1117,21 +1121,21 @@ bool cmQtAutoGenerators::GenerateMocFiles(
* @return True if a moc file was created. False may indicate an error.
*/
bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile,
const std::string& mocFileName)
const std::string& mocFileName,
const std::string& subDirPrefix)
{
const std::string mocFilePath = this->Builddir + mocFileName;
const std::string mocFileRel =
this->TargetBuildSubDir + subDirPrefix + mocFileName;
const std::string mocFileAbs = this->Builddir + mocFileRel;
int sourceNewerThanMoc = 0;
bool success = cmsys::SystemTools::FileTimeCompare(sourceFile, mocFilePath,
bool success = cmsys::SystemTools::FileTimeCompare(sourceFile, mocFileAbs,
&sourceNewerThanMoc);
if (this->GenerateAll || !success || sourceNewerThanMoc >= 0) {
{
std::string msg = "Generating MOC source ";
msg += mocFileName;
this->LogBold(msg);
}
// Log
this->LogBold("Generating MOC source " + mocFileRel);
// Make sure the parent directory exists
if (!this->makeParentDirectory(mocFilePath)) {
if (!this->makeParentDirectory(mocFileAbs)) {
this->RunMocFailed = true;
return false;
}
......@@ -1148,7 +1152,7 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile,
command.push_back("-DWIN32");
#endif
command.push_back("-o");
command.push_back(mocFilePath);
command.push_back(mocFileAbs);
command.push_back(sourceFile);
if (this->Verbose) {
......@@ -1162,12 +1166,11 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile,
if (!result || retVal) {
{
std::ostringstream err;
err << "AUTOGEN: error: moc process for " << mocFilePath
<< " failed:\n"
err << "AUTOGEN: error: moc process for " << mocFileRel << " failed:\n"
<< output << std::endl;
this->LogError(err.str());
}
cmSystemTools::RemoveFile(mocFilePath);
cmSystemTools::RemoveFile(mocFileAbs);
this->RunMocFailed = true;
return false;
}
......@@ -1242,20 +1245,19 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& realName,
const std::string& uiInputFile,
const std::string& uiOutputFile)
{
const std::string uiBuildFile = this->Builddir + uiOutputFile;
const std::string uicFileRel =
this->TargetBuildSubDir + "include/" + uiOutputFile;
const std::string uicFileAbs = this->Builddir + uicFileRel;
int sourceNewerThanUi = 0;
bool success = cmsys::SystemTools::FileTimeCompare(uiInputFile, uiBuildFile,
bool success = cmsys::SystemTools::FileTimeCompare(uiInputFile, uicFileAbs,
&sourceNewerThanUi);
if (this->GenerateAll || !success || sourceNewerThanUi >= 0) {
{
std::string msg = "Generating UIC header ";
msg += uiOutputFile;
this->LogBold(msg);
}
// Log
this->LogBold("Generating UIC header " + uicFileRel);
// Make sure the parent directory exists
if (!this->makeParentDirectory(uiBuildFile)) {
if (!this->makeParentDirectory(uicFileAbs)) {
this->RunUicFailed = true;
return false;
}
......@@ -1275,7 +1277,7 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& realName,
command.insert(command.end(), opts.begin(), opts.end());
command.push_back("-o");
command.push_back(uiBuildFile);
command.push_back(uicFileAbs);
command.push_back(uiInputFile);
if (this->Verbose) {
......@@ -1288,12 +1290,12 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& realName,
if (!result || retVal) {
{
std::ostringstream err;
err << "AUTOUIC: error: uic process for " << uiOutputFile
err << "AUTOUIC: error: uic process for " << uicFileRel
<< " needed by\n \"" << realName << "\"\nfailed:\n"
<< output << std::endl;
this->LogError(err.str());
}
cmSystemTools::RemoveFile(uiOutputFile);
cmSystemTools::RemoveFile(uicFileAbs);
this->RunUicFailed = true;
return false;
}
......
......@@ -31,15 +31,19 @@ private:
std::string MakeCompileSettingsString(cmMakefile* makefile);
bool RunAutogen(cmMakefile* makefile);
bool GenerateMocFiles(
const std::map<std::string, std::string>& includedMocs,
const std::map<std::string, std::string>& notIncludedMocs);
bool GenerateMoc(const std::string& sourceFile,
const std::string& mocFileName);
const std::string& mocFileName,
const std::string& subDirPrefix);
bool GenerateUiFiles(
const std::map<std::string, std::vector<std::string> >& includedUis);
bool GenerateUi(const std::string& realName, const std::string& uiInputFile,
const std::string& uiOutputFile);
bool GenerateQrcFiles();
bool GenerateQrc(const std::string& qrcInputFile,
const std::string& qrcOutputFile, bool unique_n);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment