From 2c9667e897f0342c40afa5db5947d87f89e557b1 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 11:12:14 +0100 Subject: QtAutogen: Use util prefix for static function name --- Source/cmQtAutoGeneratorInitializer.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 8afd532..27e9737 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -404,9 +404,9 @@ static void MergeRccOptions(std::vector& opts, opts.insert(opts.end(), extraOpts.begin(), extraOpts.end()); } -static void copyTargetProperty(cmTarget* destinationTarget, - cmTarget* sourceTarget, - const std::string& propertyName) +static void utilCopyTargetProperty(cmTarget* destinationTarget, + cmTarget* sourceTarget, + const std::string& propertyName) { const char* propertyValue = sourceTarget->GetProperty(propertyName); if (propertyValue) { @@ -828,7 +828,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( autogenTarget->SetProperty("FOLDER", autogenFolder); } else { // inherit FOLDER property from target (#13688) - copyTargetProperty(gt->Target, target->Target, "FOLDER"); + utilCopyTargetProperty(gt->Target, target->Target, "FOLDER"); } target->Target->AddUtility(autogenTargetName); -- cgit v0.12 From d0283dc1859d61dc2cbdec0c8ee0b00214976c06 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 10:17:41 +0100 Subject: QtAutogen: Use shorter name for static function --- Source/cmQtAutoGeneratorInitializer.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 27e9737..fb94e90 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -414,7 +414,7 @@ static void utilCopyTargetProperty(cmTarget* destinationTarget, } } -static std::string cmQtAutoGeneratorsStripCR(std::string const& line) +static std::string utilStripCR(std::string const& line) { // Strip CR characters rcc may have printed (possibly more than one!). std::string::size_type cr = line.find('\r'); @@ -486,7 +486,7 @@ static bool ListQt5RccInputs(cmSourceFile* sf, cmGeneratorTarget const* target, std::istringstream ostr(rccStdOut); std::string oline; while (std::getline(ostr, oline)) { - oline = cmQtAutoGeneratorsStripCR(oline); + oline = utilStripCR(oline); if (!oline.empty()) { depends.push_back(oline); } @@ -497,7 +497,7 @@ static bool ListQt5RccInputs(cmSourceFile* sf, cmGeneratorTarget const* target, std::istringstream estr(rccStdErr); std::string eline; while (std::getline(estr, eline)) { - eline = cmQtAutoGeneratorsStripCR(eline); + eline = utilStripCR(eline); if (cmHasLiteralPrefix(eline, "RCC: Error in")) { static std::string searchString = "Cannot find file '"; -- cgit v0.12 From 8de8d3b191b020c499fdfdd8df237af95da946cd Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 10:04:19 +0100 Subject: QtAutogen: Remove and inline ReadAll function The function was only used once. --- Source/cmQtAutoGeneratorInitializer.cxx | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index fb94e90..fd7bb53 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -424,15 +424,6 @@ static std::string utilStripCR(std::string const& line) return line; } -static std::string ReadAll(const std::string& filename) -{ - cmsys::ifstream file(filename.c_str()); - std::ostringstream stream; - stream << file.rdbuf(); - file.close(); - return stream.str(); -} - /// @brief Reads the resource files list from from a .qrc file - Qt5 version /// @return True if the .qrc file was successfully parsed static bool ListQt5RccInputs(cmSourceFile* sf, cmGeneratorTarget const* target, @@ -524,7 +515,13 @@ static bool ListQt5RccInputs(cmSourceFile* sf, cmGeneratorTarget const* target, static bool ListQt4RccInputs(cmSourceFile* sf, std::vector& depends) { - const std::string qrcContents = ReadAll(sf->GetFullPath()); + // Read file into string + std::string qrcContents; + { + std::ostringstream stream; + stream << cmsys::ifstream(sf->GetFullPath().c_str()).rdbuf(); + qrcContents = stream.str(); + } cmsys::RegularExpression fileMatchRegex("( Date: Wed, 30 Nov 2016 10:54:07 +0100 Subject: QtAutogen: Rcc related setup function rename --- Source/cmQtAutoGeneratorInitializer.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index fd7bb53..c97bfbc 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -558,7 +558,7 @@ static bool ListQtRccInputs(const std::string& qtMajorVersion, return ListQt4RccInputs(sf, depends); } -static void SetupAutoRccTarget(cmGeneratorTarget const* target) +static void RccSetupAutoTarget(cmGeneratorTarget const* target) { std::string _rcc_files; const char* sepRccFiles = ""; @@ -890,7 +890,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( SetupAutoUicTarget(target, skipUic, configUicOptions); } if (target->GetPropertyAsBool("AUTORCC")) { - SetupAutoRccTarget(target); + RccSetupAutoTarget(target); } std::string inputFile = cmSystemTools::GetCMakeRoot(); -- cgit v0.12 From 693d85f8d62d63ddf860637c69b8b239e7f22ad8 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 10:13:26 +0100 Subject: QtAutogen: Rcc related list function rename --- Source/cmQtAutoGeneratorInitializer.cxx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index c97bfbc..a1ad8d2 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -426,7 +426,7 @@ static std::string utilStripCR(std::string const& line) /// @brief Reads the resource files list from from a .qrc file - Qt5 version /// @return True if the .qrc file was successfully parsed -static bool ListQt5RccInputs(cmSourceFile* sf, cmGeneratorTarget const* target, +static bool RccListInputsQt5(cmSourceFile* sf, cmGeneratorTarget const* target, std::vector& depends) { std::string rccCommand = GetRccExecutable(target); @@ -512,7 +512,7 @@ static bool ListQt5RccInputs(cmSourceFile* sf, cmGeneratorTarget const* target, /// @brief Reads the resource files list from from a .qrc file - Qt4 version /// @return True if the .qrc file was successfully parsed -static bool ListQt4RccInputs(cmSourceFile* sf, +static bool RccListInputsQt4(cmSourceFile* sf, std::vector& depends) { // Read file into string @@ -548,14 +548,14 @@ static bool ListQt4RccInputs(cmSourceFile* sf, /// @brief Reads the resource files list from from a .qrc file /// @return True if the rcc file was successfully parsed -static bool ListQtRccInputs(const std::string& qtMajorVersion, - cmSourceFile* sf, cmGeneratorTarget const* target, - std::vector& depends) +static bool RccListInputs(const std::string& qtMajorVersion, cmSourceFile* sf, + cmGeneratorTarget const* target, + std::vector& depends) { if (qtMajorVersion == "5") { - return ListQt5RccInputs(sf, target, depends); + return RccListInputsQt5(sf, target, depends); } - return ListQt4RccInputs(sf, depends); + return RccListInputsQt4(sf, depends); } static void RccSetupAutoTarget(cmGeneratorTarget const* target) @@ -621,7 +621,7 @@ static void RccSetupAutoTarget(cmGeneratorTarget const* target) std::string entriesList; if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"))) { std::vector depends; - if (ListQtRccInputs(qtMajorVersion, sf, target, depends)) { + if (RccListInputs(qtMajorVersion, sf, target, depends)) { entriesList = cmJoin(depends, "@list_sep@"); } else { return; @@ -777,7 +777,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( rcc_output.push_back(rcc_output_file); } if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"))) { - ListQtRccInputs(qtMajorVersion, sf, target, depends); + RccListInputs(qtMajorVersion, sf, target, depends); #if defined(_WIN32) && !defined(__CYGWIN__) // Cannot use PRE_BUILD because the resource files themselves // may not be sources within the target so VS may not know the -- cgit v0.12 From 9eba41479bc9f60cd810fa1786cb3baf3d570266 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 10:19:33 +0100 Subject: QtAutogen: Rcc related function rename --- Source/cmQtAutoGeneratorInitializer.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index a1ad8d2..3de9159 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -372,7 +372,7 @@ static std::string GetRccExecutable(cmGeneratorTarget const* target) return std::string(); } -static void MergeRccOptions(std::vector& opts, +static void RccMergeOptions(std::vector& opts, const std::vector& fileOpts, bool isQt5) { @@ -601,7 +601,7 @@ static void RccSetupAutoTarget(cmGeneratorTarget const* target) if (const char* prop = sf->GetProperty("AUTORCC_OPTIONS")) { std::vector optsVec; cmSystemTools::ExpandListArgument(prop, optsVec); - MergeRccOptions(rccOptions, optsVec, strcmp(qtVersion, "5") == 0); + RccMergeOptions(rccOptions, optsVec, strcmp(qtVersion, "5") == 0); } if (!rccOptions.empty()) { -- cgit v0.12 From fc055c04e1ebab4b3e1f8209f8e4697ccee5a58f Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 10:24:19 +0100 Subject: QtAutogen: Rcc related function rename --- Source/cmQtAutoGeneratorInitializer.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 3de9159..340e9c3 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -331,7 +331,7 @@ static void SetupAutoUicTarget( } } -static std::string GetRccExecutable(cmGeneratorTarget const* target) +static std::string RccGetExecutable(cmGeneratorTarget const* target) { cmLocalGenerator* lg = target->GetLocalGenerator(); cmMakefile* makefile = target->Target->GetMakefile(); @@ -429,7 +429,7 @@ static std::string utilStripCR(std::string const& line) static bool RccListInputsQt5(cmSourceFile* sf, cmGeneratorTarget const* target, std::vector& depends) { - std::string rccCommand = GetRccExecutable(target); + std::string rccCommand = RccGetExecutable(target); bool hasDashDashList = false; // Read rcc features @@ -648,7 +648,7 @@ static void RccSetupAutoTarget(cmGeneratorTarget const* target) cmOutputConverter::EscapeForCMake(rccFileOptions).c_str()); makefile->AddDefinition("_qt_rcc_executable", - GetRccExecutable(target).c_str()); + RccGetExecutable(target).c_str()); } void cmQtAutoGeneratorInitializer::InitializeAutogenSources( -- cgit v0.12 From 26505dfcb7afd993d0e0622c0904d355f9b2da3f Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 11:04:58 +0100 Subject: QtAutogen: Uic related setup function rename --- Source/cmQtAutoGeneratorInitializer.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 340e9c3..406a026 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -237,7 +237,7 @@ static void GetUicOpts(cmGeneratorTarget const* target, optString = cmJoin(opts, ";"); } -static void SetupAutoUicTarget( +static void UicSetupAutoTarget( cmGeneratorTarget const* target, std::vector const& skipUic, std::map& configUicOptions) { @@ -887,7 +887,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( configIncludes, configDefines); } if (target->GetPropertyAsBool("AUTOUIC")) { - SetupAutoUicTarget(target, skipUic, configUicOptions); + UicSetupAutoTarget(target, skipUic, configUicOptions); } if (target->GetPropertyAsBool("AUTORCC")) { RccSetupAutoTarget(target); -- cgit v0.12 From c9e220827810d693eefc7a2053bdb7b7de09ccf0 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 10:23:20 +0100 Subject: QtAutogen: Uic related function rename --- Source/cmQtAutoGeneratorInitializer.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 406a026..be10d1a 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -229,7 +229,7 @@ static void SetupAutoMocTarget( } } -static void GetUicOpts(cmGeneratorTarget const* target, +static void UicGetOpts(cmGeneratorTarget const* target, const std::string& config, std::string& optString) { std::vector opts; @@ -259,7 +259,7 @@ static void UicSetupAutoTarget( std::string _uic_opts; std::vector configs; const std::string& config = makefile->GetConfigurations(configs); - GetUicOpts(target, config, _uic_opts); + UicGetOpts(target, config, _uic_opts); if (!_uic_opts.empty()) { _uic_opts = cmOutputConverter::EscapeForCMake(_uic_opts); @@ -268,7 +268,7 @@ static void UicSetupAutoTarget( for (std::vector::const_iterator li = configs.begin(); li != configs.end(); ++li) { std::string config_uic_opts; - GetUicOpts(target, *li, config_uic_opts); + UicGetOpts(target, *li, config_uic_opts); if (config_uic_opts != _uic_opts) { configUicOptions[*li] = cmOutputConverter::EscapeForCMake(config_uic_opts); -- cgit v0.12 From 048aac2cf99061c5fc13a67fb707b064db5c8660 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 11:04:06 +0100 Subject: QtAutogen: Moc related setup function rename --- Source/cmQtAutoGeneratorInitializer.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index be10d1a..df15920 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -146,7 +146,7 @@ static void GetCompileDefinitionsAndDirectories( defs += cmJoin(defines, ";"); } -static void SetupAutoMocTarget( +static void MocSetupAutoTarget( cmGeneratorTarget const* target, const std::string& autogenTargetName, std::vector const& skipMoc, std::vector const& mocHeaders, @@ -883,7 +883,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( "_cpp_files", cmOutputConverter::EscapeForCMake(cmJoin(mocSources, ";")).c_str()); if (target->GetPropertyAsBool("AUTOMOC")) { - SetupAutoMocTarget(target, autogenTargetName, skipMoc, mocHeaders, + MocSetupAutoTarget(target, autogenTargetName, skipMoc, mocHeaders, configIncludes, configDefines); } if (target->GetPropertyAsBool("AUTOUIC")) { -- cgit v0.12 From 2e18801a1bf4e313fc2ec25d9a8842312728e1be Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 11:19:28 +0100 Subject: QtAutogen: Move util functions to file begin --- Source/cmQtAutoGeneratorInitializer.cxx | 40 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index df15920..d444039 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -35,6 +35,26 @@ #include #include +static void utilCopyTargetProperty(cmTarget* destinationTarget, + cmTarget* sourceTarget, + const std::string& propertyName) +{ + const char* propertyValue = sourceTarget->GetProperty(propertyName); + if (propertyValue) { + destinationTarget->SetProperty(propertyName, propertyValue); + } +} + +static std::string utilStripCR(std::string const& line) +{ + // Strip CR characters rcc may have printed (possibly more than one!). + std::string::size_type cr = line.find('\r'); + if (cr != line.npos) { + return line.substr(0, cr); + } + return line; +} + static std::string GetAutogenTargetName(cmGeneratorTarget const* target) { std::string autogenTargetName = target->GetName(); @@ -404,26 +424,6 @@ static void RccMergeOptions(std::vector& opts, opts.insert(opts.end(), extraOpts.begin(), extraOpts.end()); } -static void utilCopyTargetProperty(cmTarget* destinationTarget, - cmTarget* sourceTarget, - const std::string& propertyName) -{ - const char* propertyValue = sourceTarget->GetProperty(propertyName); - if (propertyValue) { - destinationTarget->SetProperty(propertyName, propertyValue); - } -} - -static std::string utilStripCR(std::string const& line) -{ - // Strip CR characters rcc may have printed (possibly more than one!). - std::string::size_type cr = line.find('\r'); - if (cr != line.npos) { - return line.substr(0, cr); - } - return line; -} - /// @brief Reads the resource files list from from a .qrc file - Qt5 version /// @return True if the .qrc file was successfully parsed static bool RccListInputsQt5(cmSourceFile* sf, cmGeneratorTarget const* target, -- cgit v0.12 From 4eadf2ce3f90431fa3ae8a791fde432c6c60b5a1 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 11:25:57 +0100 Subject: QtAutogen: Target directory name function rename --- Source/cmQtAutoGeneratorInitializer.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index d444039..7aa7118 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -62,7 +62,7 @@ static std::string GetAutogenTargetName(cmGeneratorTarget const* target) return autogenTargetName; } -static std::string GetAutogenTargetDir(cmGeneratorTarget const* target) +static std::string GetAutogenTargetFilesDir(cmGeneratorTarget const* target) { cmMakefile* makefile = target->Target->GetMakefile(); std::string targetDir = makefile->GetCurrentBinaryDirectory(); @@ -683,7 +683,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( // create a custom target for running generators at buildtime: std::string autogenTargetName = GetAutogenTargetName(target); - std::string targetDir = GetAutogenTargetDir(target); + std::string targetDir = GetAutogenTargetFilesDir(target); cmCustomCommandLine currentLine; currentLine.push_back(cmSystemTools::GetCMakeCommand()); @@ -851,7 +851,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( "_origin_target_name", cmOutputConverter::EscapeForCMake(target->GetName()).c_str()); - std::string targetDir = GetAutogenTargetDir(target); + std::string targetDir = GetAutogenTargetFilesDir(target); const char* qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR"); if (!qtVersion) { -- cgit v0.12 From f448364de8cd2cd97933020fe0607d2fef3e1bcd Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 12:17:39 +0100 Subject: QtAutogen: Moc related variable renamed --- Source/cmQtAutoGeneratorInitializer.cxx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 7aa7118..4240914 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -870,7 +870,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( std::vector skipMoc; std::vector mocSources; std::vector mocHeaders; - std::map configIncludes; + std::map configMocIncludes; std::map configDefines; std::map configUicOptions; @@ -884,7 +884,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( cmOutputConverter::EscapeForCMake(cmJoin(mocSources, ";")).c_str()); if (target->GetPropertyAsBool("AUTOMOC")) { MocSetupAutoTarget(target, autogenTargetName, skipMoc, mocHeaders, - configIncludes, configDefines); + configMocIncludes, configDefines); } if (target->GetPropertyAsBool("AUTOUIC")) { UicSetupAutoTarget(target, skipUic, configUicOptions); @@ -914,7 +914,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( if (!(perm & mode_write)) { cmSystemTools::SetPermissions(outputFile, perm | mode_write); } - if (!configDefines.empty() || !configIncludes.empty() || + if (!configDefines.empty() || !configMocIncludes.empty() || !configUicOptions.empty()) { cmsys::ofstream infoFile(outputFile.c_str(), std::ios::app); if (!infoFile) { @@ -933,10 +933,10 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( << it->second << ")\n"; } } - if (!configIncludes.empty()) { + if (!configMocIncludes.empty()) { for (std::map::iterator - it = configIncludes.begin(), - end = configIncludes.end(); + it = configMocIncludes.begin(), + end = configMocIncludes.end(); it != end; ++it) { infoFile << "set(AM_MOC_INCLUDES_" << it->first << " " << it->second << ")\n"; -- cgit v0.12 From ff1a01b743dc70e555fb0fc61eb4d019eb25df76 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 12:18:47 +0100 Subject: QtAutogen: Moc related variable renamed --- Source/cmQtAutoGeneratorInitializer.cxx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 4240914..44323bc 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -871,7 +871,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( std::vector mocSources; std::vector mocHeaders; std::map configMocIncludes; - std::map configDefines; + std::map configMocDefines; std::map configUicOptions; if (target->GetPropertyAsBool("AUTOMOC") || @@ -884,7 +884,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( cmOutputConverter::EscapeForCMake(cmJoin(mocSources, ";")).c_str()); if (target->GetPropertyAsBool("AUTOMOC")) { MocSetupAutoTarget(target, autogenTargetName, skipMoc, mocHeaders, - configMocIncludes, configDefines); + configMocIncludes, configMocDefines); } if (target->GetPropertyAsBool("AUTOUIC")) { UicSetupAutoTarget(target, skipUic, configUicOptions); @@ -914,7 +914,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( if (!(perm & mode_write)) { cmSystemTools::SetPermissions(outputFile, perm | mode_write); } - if (!configDefines.empty() || !configMocIncludes.empty() || + if (!configMocDefines.empty() || !configMocIncludes.empty() || !configUicOptions.empty()) { cmsys::ofstream infoFile(outputFile.c_str(), std::ios::app); if (!infoFile) { @@ -924,10 +924,10 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( cmSystemTools::Error(error.c_str()); return; } - if (!configDefines.empty()) { + if (!configMocDefines.empty()) { for (std::map::iterator - it = configDefines.begin(), - end = configDefines.end(); + it = configMocDefines.begin(), + end = configMocDefines.end(); it != end; ++it) { infoFile << "set(AM_MOC_COMPILE_DEFINITIONS_" << it->first << " " << it->second << ")\n"; -- cgit v0.12 From 6f024008ce2bdf11bec1ff1174ee68f9a6da6fcb Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 12:23:04 +0100 Subject: QtAutogen: Remove unused intermediate definition in makefile --- Source/cmQtAutoGeneratorInitializer.cxx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 44323bc..1bdfe32 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -634,8 +634,7 @@ static void RccSetupAutoTarget(cmGeneratorTarget const* target) } } makefile->AddDefinition( - "_qt_rcc_inputs_" + target->GetName(), - cmOutputConverter::EscapeForCMake(qrcInputs).c_str()); + "_qt_rcc_inputs", cmOutputConverter::EscapeForCMake(qrcInputs).c_str()); makefile->AddDefinition( "_rcc_files", cmOutputConverter::EscapeForCMake(_rcc_files).c_str()); @@ -897,9 +896,6 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( inputFile += "/Modules/AutogenInfo.cmake.in"; std::string outputFile = targetDir; outputFile += "/AutogenInfo.cmake"; - makefile->AddDefinition( - "_qt_rcc_inputs", - makefile->GetDefinition("_qt_rcc_inputs_" + target->GetName())); makefile->ConfigureFile(inputFile.c_str(), outputFile.c_str(), false, true, false); -- cgit v0.12 From 273e481e48c855905bde4d91a986c06713df0183 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 12:44:47 +0100 Subject: QtAutogen: Inline single use variable --- Source/cmQtAutoGeneratorInitializer.cxx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 1bdfe32..576b2eb 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -682,13 +682,11 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( // create a custom target for running generators at buildtime: std::string autogenTargetName = GetAutogenTargetName(target); - std::string targetDir = GetAutogenTargetFilesDir(target); - cmCustomCommandLine currentLine; currentLine.push_back(cmSystemTools::GetCMakeCommand()); currentLine.push_back("-E"); currentLine.push_back("cmake_autogen"); - currentLine.push_back(targetDir); + currentLine.push_back(GetAutogenTargetFilesDir(target)); currentLine.push_back("$"); cmCustomCommandLines commandLines; @@ -850,8 +848,6 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( "_origin_target_name", cmOutputConverter::EscapeForCMake(target->GetName()).c_str()); - std::string targetDir = GetAutogenTargetFilesDir(target); - const char* qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR"); if (!qtVersion) { qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR"); @@ -894,7 +890,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( std::string inputFile = cmSystemTools::GetCMakeRoot(); inputFile += "/Modules/AutogenInfo.cmake.in"; - std::string outputFile = targetDir; + std::string outputFile = GetAutogenTargetFilesDir(target); outputFile += "/AutogenInfo.cmake"; makefile->ConfigureFile(inputFile.c_str(), outputFile.c_str(), false, true, false); -- cgit v0.12 From 4fa858ecb1b40e63c733047f07cc5049f7e2366a Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 13:04:52 +0100 Subject: QtAutogen: Change config file permissions only on demand --- Source/cmQtAutoGeneratorInitializer.cxx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 576b2eb..384c336 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -888,26 +888,31 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( RccSetupAutoTarget(target); } + // Generate config file std::string inputFile = cmSystemTools::GetCMakeRoot(); inputFile += "/Modules/AutogenInfo.cmake.in"; std::string outputFile = GetAutogenTargetFilesDir(target); outputFile += "/AutogenInfo.cmake"; + makefile->ConfigureFile(inputFile.c_str(), outputFile.c_str(), false, true, false); - // Ensure we have write permission in case .in was read-only. - mode_t perm = 0; + // Append custom definitions to config file + if (!configMocDefines.empty() || !configMocIncludes.empty() || + !configUicOptions.empty()) { + + // Ensure we have write permission in case .in was read-only. + mode_t perm = 0; #if defined(_WIN32) && !defined(__CYGWIN__) - mode_t mode_write = S_IWRITE; + mode_t mode_write = S_IWRITE; #else - mode_t mode_write = S_IWUSR; + mode_t mode_write = S_IWUSR; #endif - cmSystemTools::GetPermissions(outputFile, perm); - if (!(perm & mode_write)) { - cmSystemTools::SetPermissions(outputFile, perm | mode_write); - } - if (!configMocDefines.empty() || !configMocIncludes.empty() || - !configUicOptions.empty()) { + cmSystemTools::GetPermissions(outputFile, perm); + if (!(perm & mode_write)) { + cmSystemTools::SetPermissions(outputFile, perm | mode_write); + } + cmsys::ofstream infoFile(outputFile.c_str(), std::ios::app); if (!infoFile) { std::string error = "Internal CMake error when trying to open file: "; -- cgit v0.12 From 48180401d321e7fba19ac45e9e2e8a718c20d0b8 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 13:14:23 +0100 Subject: QtAutogen: Rename config AM_RELAXED_MODE to AM_MOC_RELAXED_MODE --- Modules/AutogenInfo.cmake.in | 2 +- Source/cmQtAutoGenerators.cxx | 4 ++-- Source/cmQtAutoGenerators.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/AutogenInfo.cmake.in b/Modules/AutogenInfo.cmake.in index 7d89420..355d6d8 100644 --- a/Modules/AutogenInfo.cmake.in +++ b/Modules/AutogenInfo.cmake.in @@ -7,6 +7,7 @@ set(AM_HEADERS @_moc_headers@ ) set(AM_MOC_COMPILE_DEFINITIONS @_moc_compile_defs@) set(AM_MOC_INCLUDES @_moc_incs@) set(AM_MOC_OPTIONS @_moc_options@) +set(AM_MOC_RELAXED_MODE "@_moc_relaxed_mode@") set(AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE "@CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE@") set(AM_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@/") set(AM_CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@/") @@ -18,7 +19,6 @@ set(AM_CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@/") set(AM_QT_VERSION_MAJOR "@_target_qt_version@") set(AM_TARGET_NAME @_moc_target_name@) set(AM_ORIGIN_TARGET_NAME @_origin_target_name@) -set(AM_RELAXED_MODE "@_moc_relaxed_mode@") set(AM_UIC_TARGET_OPTIONS @_uic_target_options@) set(AM_UIC_OPTIONS_FILES @_qt_uic_options_files@) set(AM_UIC_OPTIONS_OPTIONS @_qt_uic_options_options@) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index fa33cf2..c0a9b63 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -320,7 +320,7 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( } this->CurrentCompileSettingsStr = this->MakeCompileSettingsString(makefile); - this->RelaxedMode = makefile->IsOn("AM_RELAXED_MODE"); + this->MocRelaxedMode = makefile->IsOn("AM_MOC_RELAXED_MODE"); return true; } @@ -497,7 +497,7 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) err << "AUTOGEN: Checking " << absFilename << std::endl; this->LogInfo(err.str()); } - if (this->RelaxedMode) { + if (this->MocRelaxedMode) { this->ParseCppFile(absFilename, headerExtensions, includedMocs, uiFiles); } else { this->StrictParseCppFile(absFilename, headerExtensions, includedMocs, diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 08d7e03..b26b307 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -132,7 +132,7 @@ private: bool RunUicFailed; bool RunRccFailed; bool GenerateAll; - bool RelaxedMode; + bool MocRelaxedMode; }; #endif -- cgit v0.12 From bb8c96689fe692196e8f77df6d071656b161b47c Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 13:30:59 +0100 Subject: QtAutogen: Make strings const --- Source/cmQtAutoGeneratorInitializer.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 384c336..4a7e814 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -429,7 +429,7 @@ static void RccMergeOptions(std::vector& opts, static bool RccListInputsQt5(cmSourceFile* sf, cmGeneratorTarget const* target, std::vector& depends) { - std::string rccCommand = RccGetExecutable(target); + const std::string rccCommand = RccGetExecutable(target); bool hasDashDashList = false; // Read rcc features @@ -839,7 +839,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( static_cast(varScope); // create a custom target for running generators at buildtime: - std::string autogenTargetName = GetAutogenTargetName(target); + const std::string autogenTargetName = GetAutogenTargetName(target); makefile->AddDefinition( "_moc_target_name", -- cgit v0.12 From 9d9c68e21a09646816232fa849536ceaca106fc5 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 13:42:55 +0100 Subject: QtAutogen: Rename variable templates in config template --- Modules/AutogenInfo.cmake.in | 8 ++++---- Source/cmQtAutoGeneratorInitializer.cxx | 9 +++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Modules/AutogenInfo.cmake.in b/Modules/AutogenInfo.cmake.in index 355d6d8..84b0f4d 100644 --- a/Modules/AutogenInfo.cmake.in +++ b/Modules/AutogenInfo.cmake.in @@ -1,6 +1,4 @@ set(AM_SOURCES @_cpp_files@ ) -set(AM_RCC_SOURCES @_rcc_files@ ) -set(AM_RCC_INPUTS @_qt_rcc_inputs@) set(AM_SKIP_MOC @_skip_moc@ ) set(AM_SKIP_UIC @_skip_uic@ ) set(AM_HEADERS @_moc_headers@ ) @@ -22,5 +20,7 @@ set(AM_ORIGIN_TARGET_NAME @_origin_target_name@) set(AM_UIC_TARGET_OPTIONS @_uic_target_options@) set(AM_UIC_OPTIONS_FILES @_qt_uic_options_files@) set(AM_UIC_OPTIONS_OPTIONS @_qt_uic_options_options@) -set(AM_RCC_OPTIONS_FILES @_qt_rcc_options_files@) -set(AM_RCC_OPTIONS_OPTIONS @_qt_rcc_options_options@) +set(AM_RCC_SOURCES @_rcc_files@ ) +set(AM_RCC_INPUTS @_rcc_inputs@) +set(AM_RCC_OPTIONS_FILES @_rcc_options_files@) +set(AM_RCC_OPTIONS_OPTIONS @_rcc_options_options@) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 4a7e814..4f20e1b 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -634,18 +634,15 @@ static void RccSetupAutoTarget(cmGeneratorTarget const* target) } } makefile->AddDefinition( - "_qt_rcc_inputs", cmOutputConverter::EscapeForCMake(qrcInputs).c_str()); - + "_rcc_inputs", cmOutputConverter::EscapeForCMake(qrcInputs).c_str()); makefile->AddDefinition( "_rcc_files", cmOutputConverter::EscapeForCMake(_rcc_files).c_str()); - makefile->AddDefinition( - "_qt_rcc_options_files", + "_rcc_options_files", cmOutputConverter::EscapeForCMake(rccFileFiles).c_str()); makefile->AddDefinition( - "_qt_rcc_options_options", + "_rcc_options_options", cmOutputConverter::EscapeForCMake(rccFileOptions).c_str()); - makefile->AddDefinition("_qt_rcc_executable", RccGetExecutable(target).c_str()); } -- cgit v0.12 From 8548caa3ee9914f7bd25dba4dadbb1c3a6338253 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 16:38:31 +0100 Subject: QtAutogen: Variable scope optimizations --- Source/cmQtAutoGeneratorInitializer.cxx | 73 ++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 4f20e1b..7fbcff3 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -671,54 +671,59 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( { cmMakefile* makefile = target->Target->GetMakefile(); + // Create a custom target for running generators at buildtime + const std::string autogenTargetName = GetAutogenTargetName(target); + const std::string workingDirectory = + cmSystemTools::CollapseFullPath("", makefile->GetCurrentBinaryDirectory()); + std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR"); if (qtMajorVersion == "") { qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR"); } - // create a custom target for running generators at buildtime: - std::string autogenTargetName = GetAutogenTargetName(target); - - cmCustomCommandLine currentLine; - currentLine.push_back(cmSystemTools::GetCMakeCommand()); - currentLine.push_back("-E"); - currentLine.push_back("cmake_autogen"); - currentLine.push_back(GetAutogenTargetFilesDir(target)); - currentLine.push_back("$"); - - cmCustomCommandLines commandLines; - commandLines.push_back(currentLine); - - std::string workingDirectory = - cmSystemTools::CollapseFullPath("", makefile->GetCurrentBinaryDirectory()); - std::vector depends; if (const char* autogenDepends = target->GetProperty("AUTOGEN_TARGET_DEPENDS")) { cmSystemTools::ExpandListArgument(autogenDepends, depends); } - std::vector toolNames; - if (target->GetPropertyAsBool("AUTOMOC")) { - toolNames.push_back("moc"); - } - if (target->GetPropertyAsBool("AUTOUIC")) { - toolNames.push_back("uic"); - } - if (target->GetPropertyAsBool("AUTORCC")) { - toolNames.push_back("rcc"); + + // Compose command lines + cmCustomCommandLines commandLines; + { + cmCustomCommandLine currentLine; + currentLine.push_back(cmSystemTools::GetCMakeCommand()); + currentLine.push_back("-E"); + currentLine.push_back("cmake_autogen"); + currentLine.push_back(GetAutogenTargetFilesDir(target)); + currentLine.push_back("$"); + commandLines.push_back(currentLine); } - std::string tools = toolNames[0]; - toolNames.erase(toolNames.begin()); - while (toolNames.size() > 1) { - tools += ", " + toolNames[0]; + // Compose target comment + std::string autogenComment; + { + std::vector toolNames; + if (target->GetPropertyAsBool("AUTOMOC")) { + toolNames.push_back("moc"); + } + if (target->GetPropertyAsBool("AUTOUIC")) { + toolNames.push_back("uic"); + } + if (target->GetPropertyAsBool("AUTORCC")) { + toolNames.push_back("rcc"); + } + + std::string tools = toolNames[0]; toolNames.erase(toolNames.begin()); + while (toolNames.size() > 1) { + tools += ", " + toolNames[0]; + toolNames.erase(toolNames.begin()); + } + if (toolNames.size() == 1) { + tools += " and " + toolNames[0]; + } + autogenComment = "Automatic " + tools + " for target " + target->GetName(); } - if (toolNames.size() == 1) { - tools += " and " + toolNames[0]; - } - std::string autogenComment = "Automatic " + tools + " for target "; - autogenComment += target->GetName(); #if defined(_WIN32) && !defined(__CYGWIN__) bool usePRE_BUILD = false; -- cgit v0.12 From 9360e288168b850223285d1fbd695abd33cf26eb Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 17:09:32 +0100 Subject: QtAutogen: For loop feature test optimization --- Source/cmQtAutoGeneratorInitializer.cxx | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 7fbcff3..b150d88 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -755,20 +755,19 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( || usePRE_BUILD #endif ) { - std::vector srcFiles; - target->GetConfigCommonSourceFiles(srcFiles); - cmFilePathUuid fpathUuid(makefile); - for (std::vector::const_iterator fileIt = srcFiles.begin(); - fileIt != srcFiles.end(); ++fileIt) { - cmSourceFile* sf = *fileIt; - std::string absFile = cmsys::SystemTools::GetRealPath(sf->GetFullPath()); - - std::string ext = sf->GetExtension(); - - if (target->GetPropertyAsBool("AUTORCC")) { - if (ext == "qrc" && + if (target->GetPropertyAsBool("AUTORCC")) { + std::vector srcFiles; + target->GetConfigCommonSourceFiles(srcFiles); + cmFilePathUuid fpathUuid(makefile); + for (std::vector::const_iterator fileIt = + srcFiles.begin(); + fileIt != srcFiles.end(); ++fileIt) { + cmSourceFile* sf = *fileIt; + if (sf->GetExtension() == "qrc" && !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) { { + const std::string absFile = + cmsys::SystemTools::GetRealPath(sf->GetFullPath()); std::string rcc_output_file = GetAutogenTargetBuildDir(target); // Create output directory cmSystemTools::MakeDirectory(rcc_output_file.c_str()); -- cgit v0.12 From 69871e67e3b0612d7df8cc3ecf4a631850935e48 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 17:47:16 +0100 Subject: QtAutogen: Comments --- Source/cmQtAutoGeneratorInitializer.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index b150d88..76af466 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -681,6 +681,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR"); } + // Initialize autogen target dependencies std::vector depends; if (const char* autogenDepends = target->GetProperty("AUTOGEN_TARGET_DEPENDS")) { @@ -737,6 +738,8 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( // https://connect.microsoft.com/VisualStudio/feedback/details/769495 usePRE_BUILD = vsgg->GetVersion() >= cmGlobalVisualStudioGenerator::VS7; if (usePRE_BUILD) { + // If the autogen target depends on an other target + // don't use PRE_BUILD for (std::vector::iterator it = depends.begin(); it != depends.end(); ++it) { if (!makefile->FindTargetToUse(it->c_str())) { -- cgit v0.12 From 1c97d1df20bbf771568321020e84718b82788272 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 20:31:22 +0100 Subject: QtAutogen: Improved error recognition on config load --- Source/cmQtAutoGenerators.cxx | 60 +++++++++++++++++++++++++++---------------- Source/cmQtAutoGenerators.h | 4 +-- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index c0a9b63..eea9804 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -159,7 +158,6 @@ void cmQtAutoGenerators::MergeUicOptions( bool cmQtAutoGenerators::Run(const std::string& targetDirectory, const std::string& config) { - bool success = true; cmake cm; cm.SetHomeOutputDirectory(targetDirectory); cm.SetHomeDirectory(targetDirectory); @@ -173,18 +171,18 @@ bool cmQtAutoGenerators::Run(const std::string& targetDirectory, CM_AUTO_PTR mf(new cmMakefile(&gg, snapshot)); gg.SetCurrentMakefile(mf.get()); - this->ReadAutogenInfoFile(mf.get(), targetDirectory, config); + if (!this->ReadAutogenInfoFile(mf.get(), targetDirectory, config)) { + return false; + } this->ReadOldMocDefinitionsFile(mf.get(), targetDirectory); - this->Init(); if (this->QtMajorVersion == "4" || this->QtMajorVersion == "5") { - success = this->RunAutogen(mf.get()); + if (!this->RunAutogen(mf.get())) { + return false; + } } - - this->WriteOldMocDefinitionsFile(targetDirectory); - - return success; + return this->WriteOldMocDefinitionsFile(targetDirectory); } bool cmQtAutoGenerators::ReadAutogenInfoFile( @@ -196,7 +194,9 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( filename += "/AutogenInfo.cmake"; if (!makefile->ReadListFile(filename.c_str())) { - cmSystemTools::Error("Error processing file: ", filename.c_str()); + std::ostringstream err; + err << "AUTOGEN: Error processing file: " << filename << std::endl; + this->LogError(err.str()); return false; } @@ -303,8 +303,15 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( std::vector rccInputLists; cmSystemTools::ExpandListArgument(rccInputs, rccInputLists); + // qrc files in the end of the list may have been empty + if (rccInputLists.size() < this->RccSources.size()) { + rccInputLists.resize(this->RccSources.size()); + } if (this->RccSources.size() != rccInputLists.size()) { - cmSystemTools::Error("Error processing file: ", filename.c_str()); + std::ostringstream err; + err << "AUTOGEN: RCC sources lists size missmatch in: " << filename; + err << std::endl; + this->LogError(err.str()); return false; } @@ -341,7 +348,7 @@ std::string cmQtAutoGenerators::MakeCompileSettingsString(cmMakefile* makefile) return s; } -bool cmQtAutoGenerators::ReadOldMocDefinitionsFile( +void cmQtAutoGenerators::ReadOldMocDefinitionsFile( cmMakefile* makefile, const std::string& targetDirectory) { std::string filename(cmSystemTools::CollapseFullPath(targetDirectory)); @@ -352,23 +359,32 @@ bool cmQtAutoGenerators::ReadOldMocDefinitionsFile( this->OldCompileSettingsStr = makefile->GetSafeDefinition("AM_OLD_COMPILE_SETTINGS"); } - return true; } -void cmQtAutoGenerators::WriteOldMocDefinitionsFile( +bool cmQtAutoGenerators::WriteOldMocDefinitionsFile( const std::string& targetDirectory) { + bool success = true; + std::string filename(cmSystemTools::CollapseFullPath(targetDirectory)); cmSystemTools::ConvertToUnixSlashes(filename); filename += "/AutomocOldMocDefinitions.cmake"; - cmsys::ofstream outfile; - outfile.open(filename.c_str(), std::ios::trunc); - outfile << "set(AM_OLD_COMPILE_SETTINGS " - << cmOutputConverter::EscapeForCMake(this->CurrentCompileSettingsStr) - << ")\n"; + { + cmsys::ofstream outfile; + outfile.open(filename.c_str(), std::ios::trunc); + if (outfile.is_open()) { + outfile << "set(AM_OLD_COMPILE_SETTINGS " + << cmOutputConverter::EscapeForCMake( + this->CurrentCompileSettingsStr) + << ")\n"; + success = outfile.good(); + } else { + success = false; + } + } - outfile.close(); + return success; } void cmQtAutoGenerators::Init() @@ -1431,12 +1447,12 @@ void cmQtAutoGenerators::NameCollisionLog( void cmQtAutoGenerators::LogInfo(const std::string& message) { - std::cout << message; + cmSystemTools::Message(message.c_str()); } void cmQtAutoGenerators::LogError(const std::string& message) { - std::cerr << message; + cmSystemTools::Error(message.c_str()); } void cmQtAutoGenerators::LogCommand(const std::vector& command) diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index b26b307..47f3289 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -23,9 +23,9 @@ private: bool ReadAutogenInfoFile(cmMakefile* makefile, const std::string& targetDirectory, const std::string& config); - bool ReadOldMocDefinitionsFile(cmMakefile* makefile, + void ReadOldMocDefinitionsFile(cmMakefile* makefile, const std::string& targetDirectory); - void WriteOldMocDefinitionsFile(const std::string& targetDirectory); + bool WriteOldMocDefinitionsFile(const std::string& targetDirectory); std::string MakeCompileSettingsString(cmMakefile* makefile); -- cgit v0.12 From 708e44af5d445d25cc39e83da800ccc57f90a79a Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 20:47:54 +0100 Subject: QtAutogen: Improved error recognition --- Source/cmQtAutoGenerators.cxx | 90 +++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index eea9804..a0302cb 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -549,32 +549,19 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) this->ParseHeaders(headerFiles, includedMocs, notIncludedMocs, includedUis); if (!this->MocExecutable.empty()) { - this->GenerateMocFiles(includedMocs, notIncludedMocs); + if (!this->GenerateMocFiles(includedMocs, notIncludedMocs)) { + return false; + } } if (!this->UicExecutable.empty()) { - this->GenerateUiFiles(includedUis); + if (!this->GenerateUiFiles(includedUis)) { + return false; + } } if (!this->RccExecutable.empty()) { - this->GenerateQrcFiles(); - } - - if (this->RunMocFailed) { - std::ostringstream err; - err << "moc failed..." << std::endl; - this->LogError(err.str()); - return false; - } - if (this->RunUicFailed) { - std::ostringstream err; - err << "uic failed..." << std::endl; - this->LogError(err.str()); - return false; - } - if (this->RunRccFailed) { - std::ostringstream err; - err << "rcc failed..." << std::endl; - this->LogError(err.str()); - return false; + if (!this->GenerateQrcFiles()) { + return false; + } } return true; @@ -1011,7 +998,7 @@ bool cmQtAutoGenerators::GenerateMocFiles( << "- rename the source files or" << std::endl << "- do not include the (moc_NAME.cpp|NAME.moc) file" << std::endl; this->NameCollisionLog(err.str(), collisions); - ::exit(EXIT_FAILURE); + return false; } } @@ -1092,6 +1079,9 @@ bool cmQtAutoGenerators::GenerateMocFiles( return true; } +/** + * @return True if a moc file was created. False may indicate an error. + */ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile, const std::string& mocFileName) { @@ -1136,12 +1126,16 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile, bool result = cmSystemTools::RunSingleCommand(command, &output, &output, &retVal); if (!result || retVal) { - std::ostringstream err; - err << "AUTOGEN: error: process for " << mocFilePath << " failed:\n" - << output << std::endl; - this->LogError(err.str()); - this->RunMocFailed = true; + { + std::ostringstream err; + err << "AUTOGEN: error: moc process for " << mocFilePath + << " failed:\n" + << output << std::endl; + this->LogError(err.str()); + } cmSystemTools::RemoveFile(mocFilePath); + this->RunMocFailed = true; + return false; } return true; } @@ -1183,7 +1177,7 @@ bool cmQtAutoGenerators::GenerateUiFiles( << std::endl << "To avoid this error rename the source files." << std::endl; this->NameCollisionLog(err.str(), collisions); - ::exit(EXIT_FAILURE); + return false; } } testMap.clear(); @@ -1207,6 +1201,9 @@ bool cmQtAutoGenerators::GenerateUiFiles( return true; } +/** + * @return True if a uic file was created. False may indicate an error. + */ bool cmQtAutoGenerators::GenerateUi(const std::string& realName, const std::string& uiInputFile, const std::string& uiOutputFile) @@ -1253,13 +1250,15 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& realName, bool result = cmSystemTools::RunSingleCommand(command, &output, &output, &retVal); if (!result || retVal) { - std::ostringstream err; - err << "AUTOUIC: error: process for " << uiOutputFile - << " needed by\n \"" << realName << "\"\nfailed:\n" - << output << std::endl; - this->LogError(err.str()); - this->RunUicFailed = true; + { + std::ostringstream err; + err << "AUTOUIC: error: uic process for " << uiOutputFile + << " needed by\n \"" << realName << "\"\nfailed:\n" + << output << std::endl; + this->LogError(err.str()); + } cmSystemTools::RemoveFile(uiOutputFile); + this->RunUicFailed = true; return false; } return true; @@ -1312,7 +1311,7 @@ bool cmQtAutoGenerators::GenerateQrcFiles() << std::endl << "To avoid this error rename the source .qrc files." << std::endl; this->NameCollisionLog(err.str(), collisions); - ::exit(EXIT_FAILURE); + return false; } } @@ -1330,6 +1329,9 @@ bool cmQtAutoGenerators::GenerateQrcFiles() return true; } +/** + * @return True if a rcc file was created. False may indicate an error. + */ bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile, const std::string& qrcOutputFile, bool unique_n) @@ -1387,16 +1389,20 @@ bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile, bool result = cmSystemTools::RunSingleCommand(command, &output, &output, &retVal); if (!result || retVal) { - std::ostringstream err; - err << "AUTORCC: error: process for " << qrcOutputFile << " failed:\n" - << output << std::endl; - this->LogError(err.str()); - this->RunRccFailed = true; + { + std::ostringstream err; + err << "AUTORCC: error: rcc process for " << qrcOutputFile + << " failed:\n" + << output << std::endl; + this->LogError(err.str()); + } cmSystemTools::RemoveFile(qrcBuildFile); + this->RunRccFailed = true; return false; } + return true; } - return true; + return false; } /** -- cgit v0.12 From 00750ece6a5dbfd51a8dd789c4d7dc1246f63ec3 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 21:08:54 +0100 Subject: QtAutogen: Error and warning log method tweaks --- Source/cmQtAutoGenerators.cxx | 36 +++++++++++++++++++++++------------- Source/cmQtAutoGenerators.h | 6 ++++-- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index a0302cb..a6099fa 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -195,7 +196,7 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( if (!makefile->ReadListFile(filename.c_str())) { std::ostringstream err; - err << "AUTOGEN: Error processing file: " << filename << std::endl; + err << "AUTOGEN: error processing file: " << filename << std::endl; this->LogError(err.str()); return false; } @@ -582,7 +583,7 @@ void cmQtAutoGenerators::ParseCppFile( std::ostringstream err; err << "AUTOGEN: warning: " << absFilename << ": file is empty\n" << std::endl; - this->LogError(err.str()); + this->LogWarning(err.str()); return; } this->ParseForUic(absFilename, contentsString, includedUis); @@ -673,7 +674,7 @@ void cmQtAutoGenerators::ParseCppFile( << ".cpp\" for a compatibility with " "strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n" << std::endl; - this->LogError(err.str()); + this->LogWarning(err.str()); } else { std::ostringstream err; err << "AUTOGEN: warning: " << absFilename @@ -686,7 +687,7 @@ void cmQtAutoGenerators::ParseCppFile( << ".cpp\" for compatibility with " "strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n" << std::endl; - this->LogError(err.str()); + this->LogWarning(err.str()); } } else { std::ostringstream err; @@ -730,7 +731,7 @@ void cmQtAutoGenerators::ParseCppFile( << ".moc\" for compatibility with " "strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n" << std::endl; - this->LogError(err.str()); + this->LogWarning(err.str()); includedMocs[absFilename] = ownMocUnderscoreFile; includedMocs.erase(ownMocHeaderFile); @@ -764,7 +765,7 @@ void cmQtAutoGenerators::StrictParseCppFile( std::ostringstream err; err << "AUTOGEN: warning: " << absFilename << ": file is empty\n" << std::endl; - this->LogError(err.str()); + this->LogWarning(err.str()); return; } this->ParseForUic(absFilename, contentsString, includedUis); @@ -876,7 +877,7 @@ void cmQtAutoGenerators::ParseForUic( std::ostringstream err; err << "AUTOGEN: warning: " << absFilename << ": file is empty\n" << std::endl; - this->LogError(err.str()); + this->LogWarning(err.str()); return; } this->ParseForUic(absFilename, contentsString, includedUis); @@ -997,7 +998,7 @@ bool cmQtAutoGenerators::GenerateMocFiles( << "To avoid this error either" << std::endl << "- rename the source files or" << std::endl << "- do not include the (moc_NAME.cpp|NAME.moc) file" << std::endl; - this->NameCollisionLog(err.str(), collisions); + this->LogErrorNameCollision(err.str(), collisions); return false; } } @@ -1176,7 +1177,7 @@ bool cmQtAutoGenerators::GenerateUiFiles( "from different sources." << std::endl << "To avoid this error rename the source files." << std::endl; - this->NameCollisionLog(err.str(), collisions); + this->LogErrorNameCollision(err.str(), collisions); return false; } } @@ -1310,7 +1311,7 @@ bool cmQtAutoGenerators::GenerateQrcFiles() " will be generated from different sources." << std::endl << "To avoid this error rename the source .qrc files." << std::endl; - this->NameCollisionLog(err.str(), collisions); + this->LogErrorNameCollision(err.str(), collisions); return false; } } @@ -1435,7 +1436,7 @@ bool cmQtAutoGenerators::NameCollisionTest( return !collisions.empty(); } -void cmQtAutoGenerators::NameCollisionLog( +void cmQtAutoGenerators::LogErrorNameCollision( const std::string& message, const std::multimap& collisions) { @@ -1453,12 +1454,21 @@ void cmQtAutoGenerators::NameCollisionLog( void cmQtAutoGenerators::LogInfo(const std::string& message) { - cmSystemTools::Message(message.c_str()); + std::cout << message.c_str(); +} + +void cmQtAutoGenerators::LogWarning(const std::string& message) +{ + std::ostringstream ostr; + ostr << message << "\n"; + std::cout << message.c_str(); } void cmQtAutoGenerators::LogError(const std::string& message) { - cmSystemTools::Error(message.c_str()); + std::ostringstream ostr; + ostr << message << "\n\n"; + std::cerr << ostr.str(); } void cmQtAutoGenerators::LogCommand(const std::vector& command) diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 47f3289..816c380 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -76,13 +76,15 @@ private: bool NameCollisionTest(const std::map& genFiles, std::multimap& collisions); - void NameCollisionLog( + + void LogErrorNameCollision( const std::string& message, const std::multimap& collisions); - void LogInfo(const std::string& message); + void LogWarning(const std::string& message); void LogError(const std::string& message); void LogCommand(const std::vector& command); + std::string JoinExts(const std::vector& lst); static void MergeUicOptions(std::vector& opts, -- cgit v0.12 From 7731121d66dc2212c67eb9d49840ac846bd00ce7 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 21:17:38 +0100 Subject: QtAutogen: Improved error handling --- Source/cmQtAutoGenerators.cxx | 46 ++++++++++++++++++++++++++++--------------- Source/cmQtAutoGenerators.h | 4 ++-- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index a6099fa..c6781de 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -515,10 +515,15 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) this->LogInfo(err.str()); } if (this->MocRelaxedMode) { - this->ParseCppFile(absFilename, headerExtensions, includedMocs, uiFiles); + if (!this->ParseCppFile(absFilename, headerExtensions, includedMocs, + uiFiles)) { + return false; + } } else { - this->StrictParseCppFile(absFilename, headerExtensions, includedMocs, - uiFiles); + if (!this->StrictParseCppFile(absFilename, headerExtensions, + includedMocs, uiFiles)) { + return false; + } } this->SearchHeadersForCppFile(absFilename, headerExtensions, headerFiles); } @@ -568,7 +573,10 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) return true; } -void cmQtAutoGenerators::ParseCppFile( +/** + * @return True on success + */ +bool cmQtAutoGenerators::ParseCppFile( const std::string& absFilename, const std::vector& headerExtensions, std::map& includedMocs, @@ -584,11 +592,11 @@ void cmQtAutoGenerators::ParseCppFile( err << "AUTOGEN: warning: " << absFilename << ": file is empty\n" << std::endl; this->LogWarning(err.str()); - return; + return true; } this->ParseForUic(absFilename, contentsString, includedUis); if (this->MocExecutable.empty()) { - return; + return true; } const std::string absPath = cmsys::SystemTools::GetFilenamePath( @@ -652,7 +660,7 @@ void cmQtAutoGenerators::ParseCppFile( << std::endl; } this->LogError(err.str()); - ::exit(EXIT_FAILURE); + return false; } } else { std::string fileToMoc = absFilename; @@ -700,7 +708,7 @@ void cmQtAutoGenerators::ParseCppFile( "header.\n" << std::endl; this->LogError(err.str()); - ::exit(EXIT_FAILURE); + return false; } } else { dotMocIncluded = true; @@ -744,13 +752,17 @@ void cmQtAutoGenerators::ParseCppFile( << "\"" << scannedFileBasename << ".moc\" !\n" << std::endl; this->LogError(err.str()); - - ::exit(EXIT_FAILURE); + return false; } } + + return true; } -void cmQtAutoGenerators::StrictParseCppFile( +/** + * @return True on success + */ +bool cmQtAutoGenerators::StrictParseCppFile( const std::string& absFilename, const std::vector& headerExtensions, std::map& includedMocs, @@ -766,11 +778,11 @@ void cmQtAutoGenerators::StrictParseCppFile( err << "AUTOGEN: warning: " << absFilename << ": file is empty\n" << std::endl; this->LogWarning(err.str()); - return; + return true; } this->ParseForUic(absFilename, contentsString, includedUis); if (this->MocExecutable.empty()) { - return; + return true; } const std::string absPath = cmsys::SystemTools::GetFilenamePath( @@ -823,7 +835,7 @@ void cmQtAutoGenerators::StrictParseCppFile( << std::endl; } this->LogError(err.str()); - ::exit(EXIT_FAILURE); + return false; } } else { if (basename != scannedFileBasename) { @@ -839,7 +851,7 @@ void cmQtAutoGenerators::StrictParseCppFile( "moc on this source file.\n" << std::endl; this->LogError(err.str()); - ::exit(EXIT_FAILURE); + return false; } dotMocIncluded = true; includedMocs[absFilename] = currentMoc; @@ -861,8 +873,10 @@ void cmQtAutoGenerators::StrictParseCppFile( << "\"" << scannedFileBasename << ".moc\" !\n" << std::endl; this->LogError(err.str()); - ::exit(EXIT_FAILURE); + return false; } + + return true; } void cmQtAutoGenerators::ParseForUic( diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 816c380..99b1fbf 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -43,12 +43,12 @@ private: bool GenerateQrc(const std::string& qrcInputFile, const std::string& qrcOutputFile, bool unique_n); - void ParseCppFile( + bool ParseCppFile( const std::string& absFilename, const std::vector& headerExtensions, std::map& includedMocs, std::map >& includedUis); - void StrictParseCppFile( + bool StrictParseCppFile( const std::string& absFilename, const std::vector& headerExtensions, std::map& includedMocs, -- cgit v0.12 From 49f8687e1601bacd3386d8393dc831124691715e Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 22:02:32 +0100 Subject: QtAutogen: Make sure parent directory exists before writing files --- Source/cmQtAutoGenerators.cxx | 120 +++++++++++++++++++++++++++++------------- Source/cmQtAutoGenerators.h | 2 + 2 files changed, 85 insertions(+), 37 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index c6781de..23424c4 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -374,14 +374,13 @@ bool cmQtAutoGenerators::WriteOldMocDefinitionsFile( { cmsys::ofstream outfile; outfile.open(filename.c_str(), std::ios::trunc); - if (outfile.is_open()) { + success = outfile.is_open(); + if (success) { outfile << "set(AM_OLD_COMPILE_SETTINGS " << cmOutputConverter::EscapeForCMake( this->CurrentCompileSettingsStr) << ")\n"; success = outfile.good(); - } else { - success = false; } } @@ -1084,14 +1083,28 @@ bool cmQtAutoGenerators::GenerateMocFiles( cmsysTerminal_Color_ForegroundBold, msg.c_str(), true, this->ColorOutput); } - { + // Make sure the parent directory exists + bool success = this->makeParentDirectory(this->OutMocCppFilenameAbs); + if (success) { cmsys::ofstream outfile; outfile.open(this->OutMocCppFilenameAbs.c_str(), std::ios::trunc); - outfile << automocSource; - outfile.close(); + if (!outfile.is_open()) { + success = false; + std::ostringstream err; + err << "AUTOGEN: error opening " << this->OutMocCppFilenameAbs << "\n"; + this->LogError(err.str()); + } else { + outfile << automocSource; + // Check for write errors + if (!outfile.good()) { + success = false; + std::ostringstream err; + err << "AUTOGEN: error writing " << this->OutMocCppFilenameAbs << "\n"; + this->LogError(err.str()); + } + } } - - return true; + return success; } /** @@ -1105,17 +1118,19 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile, bool success = cmsys::SystemTools::FileTimeCompare(sourceFile, mocFilePath, &sourceNewerThanMoc); if (this->GenerateAll || !success || sourceNewerThanMoc >= 0) { - // make sure the directory for the resulting moc file exists - std::string mocDir = mocFilePath.substr(0, mocFilePath.rfind('/')); - if (!cmsys::SystemTools::FileExists(mocDir.c_str(), false)) { - cmsys::SystemTools::MakeDirectory(mocDir.c_str()); + { + std::string msg = "Generating moc source "; + msg += mocFileName; + cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue | + cmsysTerminal_Color_ForegroundBold, + msg.c_str(), true, this->ColorOutput); } - std::string msg = "Generating moc source "; - msg += mocFileName; - cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue | - cmsysTerminal_Color_ForegroundBold, - msg.c_str(), true, this->ColorOutput); + // Make sure the parent directory exists + if (!this->makeParentDirectory(mocFilePath)) { + this->RunMocFailed = true; + return false; + } std::vector command; command.push_back(this->MocExecutable); @@ -1223,21 +1238,25 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& realName, const std::string& uiInputFile, const std::string& uiOutputFile) { - if (!cmsys::SystemTools::FileExists(this->Builddir.c_str(), false)) { - cmsys::SystemTools::MakeDirectory(this->Builddir.c_str()); - } - const std::string uiBuildFile = this->Builddir + uiOutputFile; int sourceNewerThanUi = 0; bool success = cmsys::SystemTools::FileTimeCompare(uiInputFile, uiBuildFile, &sourceNewerThanUi); if (this->GenerateAll || !success || sourceNewerThanUi >= 0) { - std::string msg = "Generating ui header "; - msg += uiOutputFile; - cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue | - cmsysTerminal_Color_ForegroundBold, - msg.c_str(), true, this->ColorOutput); + { + std::string msg = "Generating ui header "; + msg += uiOutputFile; + cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue | + cmsysTerminal_Color_ForegroundBold, + msg.c_str(), true, this->ColorOutput); + } + + // Make sure the parent directory exists + if (!this->makeParentDirectory(uiBuildFile)) { + this->RunUicFailed = true; + return false; + } std::vector command; command.push_back(this->UicExecutable); @@ -1375,21 +1394,29 @@ bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile, generateQrc || this->InputFilesNewerThanQrc(qrcInputFile, qrcBuildFile); if (this->GenerateAll || generateQrc) { - std::string msg = "Generating qrc source "; - msg += qrcOutputFile; - cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue | - cmsysTerminal_Color_ForegroundBold, - msg.c_str(), true, this->ColorOutput); + { + std::string msg = "Generating qrc source "; + msg += qrcOutputFile; + cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue | + cmsysTerminal_Color_ForegroundBold, + msg.c_str(), true, this->ColorOutput); + } + + // Make sure the parent directory exists + if (!this->makeParentDirectory(qrcOutputFile)) { + this->RunRccFailed = true; + return false; + } std::vector command; command.push_back(this->RccExecutable); - - std::map::const_iterator optionIt = - this->RccOptions.find(qrcInputFile); - if (optionIt != this->RccOptions.end()) { - cmSystemTools::ExpandListArgument(optionIt->second, command); + { + std::map::const_iterator optionIt = + this->RccOptions.find(qrcInputFile); + if (optionIt != this->RccOptions.end()) { + cmSystemTools::ExpandListArgument(optionIt->second, command); + } } - command.push_back("-name"); command.push_back(symbolName); command.push_back("-o"); @@ -1501,6 +1528,25 @@ void cmQtAutoGenerators::LogCommand(const std::vector& command) } } +/** + * @brief Generates the parent directory of the given file on demand + * @return True on success + */ +bool cmQtAutoGenerators::makeParentDirectory(const std::string& filename) +{ + bool success = true; + const std::string dirName = cmSystemTools::GetFilenamePath(filename); + if (!dirName.empty()) { + success = cmsys::SystemTools::MakeDirectory(dirName); + if (!success) { + std::ostringstream err; + err << "AUTOGEN: Directory creation failed: " << dirName << std::endl; + this->LogError(err.str()); + } + } + return success; +} + std::string cmQtAutoGenerators::JoinExts(const std::vector& lst) { if (lst.empty()) { diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 99b1fbf..7cba1ea 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -85,6 +85,8 @@ private: void LogError(const std::string& message); void LogCommand(const std::vector& command); + bool makeParentDirectory(const std::string& filename); + std::string JoinExts(const std::vector& lst); static void MergeUicOptions(std::vector& opts, -- cgit v0.12 From 8c6f990fb600d042ebb7a21996280ef31798bc79 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 22:08:41 +0100 Subject: QtAutogen: New common bold logging method --- Source/cmQtAutoGenerators.cxx | 31 +++++++++++++++---------------- Source/cmQtAutoGenerators.h | 1 + 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 23424c4..b497fb0 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -1077,11 +1077,9 @@ bool cmQtAutoGenerators::GenerateMocFiles( // actually write _automoc.cpp { - std::string msg = "Generating moc compilation "; + std::string msg = "Generating MOC compilation "; msg += this->OutMocCppFilenameRel; - cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue | - cmsysTerminal_Color_ForegroundBold, - msg.c_str(), true, this->ColorOutput); + this->LogBold(msg); } // Make sure the parent directory exists bool success = this->makeParentDirectory(this->OutMocCppFilenameAbs); @@ -1119,11 +1117,9 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile, &sourceNewerThanMoc); if (this->GenerateAll || !success || sourceNewerThanMoc >= 0) { { - std::string msg = "Generating moc source "; + std::string msg = "Generating MOC source "; msg += mocFileName; - cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue | - cmsysTerminal_Color_ForegroundBold, - msg.c_str(), true, this->ColorOutput); + this->LogBold(msg); } // Make sure the parent directory exists @@ -1245,11 +1241,9 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& realName, &sourceNewerThanUi); if (this->GenerateAll || !success || sourceNewerThanUi >= 0) { { - std::string msg = "Generating ui header "; + std::string msg = "Generating UIC header "; msg += uiOutputFile; - cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue | - cmsysTerminal_Color_ForegroundBold, - msg.c_str(), true, this->ColorOutput); + this->LogBold(msg); } // Make sure the parent directory exists @@ -1395,11 +1389,9 @@ bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile, if (this->GenerateAll || generateQrc) { { - std::string msg = "Generating qrc source "; + std::string msg = "Generating QRC source "; msg += qrcOutputFile; - cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue | - cmsysTerminal_Color_ForegroundBold, - msg.c_str(), true, this->ColorOutput); + this->LogBold(msg); } // Make sure the parent directory exists @@ -1493,6 +1485,13 @@ void cmQtAutoGenerators::LogErrorNameCollision( this->LogError(err.str()); } +void cmQtAutoGenerators::LogBold(const std::string& message) +{ + cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue | + cmsysTerminal_Color_ForegroundBold, + message.c_str(), true, this->ColorOutput); +} + void cmQtAutoGenerators::LogInfo(const std::string& message) { std::cout << message.c_str(); diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 7cba1ea..466acb2 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -80,6 +80,7 @@ private: void LogErrorNameCollision( const std::string& message, const std::multimap& collisions); + void LogBold(const std::string& message); void LogInfo(const std::string& message); void LogWarning(const std::string& message); void LogError(const std::string& message); -- cgit v0.12 From 39e07d7a175d5da0c1a2ebc905689705571d2084 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 22:12:50 +0100 Subject: QtAutogen: Use upper case for MOC, UIC and RCC in messages --- Source/cmQtAutoGeneratorInitializer.cxx | 6 +++--- Source/cmQtAutoGenerators.cxx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 76af466..de70d34 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -705,13 +705,13 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( { std::vector toolNames; if (target->GetPropertyAsBool("AUTOMOC")) { - toolNames.push_back("moc"); + toolNames.push_back("MOC"); } if (target->GetPropertyAsBool("AUTOUIC")) { - toolNames.push_back("uic"); + toolNames.push_back("UIC"); } if (target->GetPropertyAsBool("AUTORCC")) { - toolNames.push_back("rcc"); + toolNames.push_back("RCC"); } std::string tools = toolNames[0]; diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index b497fb0..f90f0d5 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -1389,7 +1389,7 @@ bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile, if (this->GenerateAll || generateQrc) { { - std::string msg = "Generating QRC source "; + std::string msg = "Generating RCC source "; msg += qrcOutputFile; this->LogBold(msg); } -- cgit v0.12 From 6f53b1ab642ca1e5977121ec60779f248cf8ee88 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 22:51:00 +0100 Subject: QtAutogen: Generate moc compilation in _automoc.dir/moc_compilation.cpp --- Help/prop_tgt/AUTOMOC.rst | 2 +- Source/cmQtAutoGeneratorInitializer.cxx | 10 +++------- Source/cmQtAutoGenerators.cxx | 28 ++++++++++++++++------------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Help/prop_tgt/AUTOMOC.rst b/Help/prop_tgt/AUTOMOC.rst index 8143ba9..eea57e3 100644 --- a/Help/prop_tgt/AUTOMOC.rst +++ b/Help/prop_tgt/AUTOMOC.rst @@ -30,7 +30,7 @@ source files at build time and invoke moc accordingly. alternative extensions, such as ``hpp``, ``hxx`` etc when searching for headers. The resulting moc files, which are not included as shown above in any of the source files are included in a generated - ``_automoc.cpp`` file, which is compiled as part of the + ``moc_compilation.cpp`` file, which is compiled as part of the target. This property is initialized by the value of the :variable:`CMAKE_AUTOMOC` diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index de70d34..a443934 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -650,14 +650,10 @@ static void RccSetupAutoTarget(cmGeneratorTarget const* target) void cmQtAutoGeneratorInitializer::InitializeAutogenSources( cmGeneratorTarget* target) { - cmMakefile* makefile = target->Target->GetMakefile(); - if (target->GetPropertyAsBool("AUTOMOC")) { - std::string automocTargetName = GetAutogenTargetName(target); - std::string mocCppFile = makefile->GetCurrentBinaryDirectory(); - mocCppFile += "/"; - mocCppFile += automocTargetName; - mocCppFile += ".cpp"; + cmMakefile* makefile = target->Target->GetMakefile(); + std::string mocCppFile = GetAutogenTargetBuildDir(target); + mocCppFile += "moc_compilation.cpp"; makefile->GetOrCreateSource(mocCppFile, true); makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", mocCppFile.c_str(), false); diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index f90f0d5..e5d7b57 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -392,8 +392,8 @@ void cmQtAutoGenerators::Init() this->TargetBuildSubDir = this->TargetName; this->TargetBuildSubDir += ".dir/"; - this->OutMocCppFilenameRel = this->TargetName; - this->OutMocCppFilenameRel += ".cpp"; + this->OutMocCppFilenameRel = this->TargetBuildSubDir; + this->OutMocCppFilenameRel += "moc_compilation.cpp"; this->OutMocCppFilenameAbs = this->Builddir + this->OutMocCppFilenameRel; @@ -480,10 +480,10 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) // the program goes through all .cpp files to see which moc files are // included. It is not really interesting how the moc file is named, but // what file the moc is created from. Once a moc is included the same moc - // may not be included in the _automoc.cpp file anymore. OTOH if there's a - // header containing Q_OBJECT where no corresponding moc file is included - // anywhere a moc_.cpp file is created and included in - // the _automoc.cpp file. + // may not be included in the moc_compilation.cpp file anymore. OTOH if + // there's a header containing Q_OBJECT where no corresponding moc file + // is included anywhere a moc_.cpp file is created and included in + // the moc_compilation.cpp file. // key = moc source filepath, value = moc output filepath std::map includedMocs; @@ -1041,30 +1041,34 @@ bool cmQtAutoGenerators::GenerateMocFiles( } } - // compose _automoc.cpp content + // Compose moc_compilation.cpp content std::string automocSource; { std::ostringstream outStream; outStream << "/* This file is autogenerated, do not edit*/\n"; if (notIncludedMocs.empty()) { + // Dummy content outStream << "enum some_compilers { need_more_than_nothing };\n"; } else { + // Includes content for (std::map::const_iterator it = notIncludedMocs.begin(); it != notIncludedMocs.end(); ++it) { - outStream << "#include \"" << it->second << "\"\n"; + outStream << "#include \"" + << it->second.substr(this->TargetBuildSubDir.size()) + << "\"\n"; } } outStream.flush(); automocSource = outStream.str(); } - // check if we even need to update _automoc.cpp + // Check if we even need to update moc_compilation.cpp if (!automocCppChanged) { - // compare contents of the _automoc.cpp file + // compare contents of the moc_compilation.cpp file const std::string oldContents = ReadAll(this->OutMocCppFilenameAbs); if (oldContents == automocSource) { - // nothing changed: don't touch the _automoc.cpp file + // nothing changed: don't touch the moc_compilation.cpp file if (this->Verbose) { std::ostringstream err; err << "AUTOGEN: " << this->OutMocCppFilenameRel << " still up to date" @@ -1075,7 +1079,7 @@ bool cmQtAutoGenerators::GenerateMocFiles( } } - // actually write _automoc.cpp + // Actually write moc_compilation.cpp { std::string msg = "Generating MOC compilation "; msg += this->OutMocCppFilenameRel; -- cgit v0.12 From d3afe4070b9c5ba08a11ce3b4b30d2c1ad4c591d Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 22:56:50 +0100 Subject: QtAutogen: Remove .dir suffix from automoc build directory --- Source/cmQtAutoGeneratorInitializer.cxx | 2 +- Source/cmQtAutoGenerators.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index a443934..e589a5a 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -79,7 +79,7 @@ static std::string GetAutogenTargetBuildDir(cmGeneratorTarget const* target) std::string targetDir = makefile->GetCurrentBinaryDirectory(); targetDir += "/"; targetDir += GetAutogenTargetName(target); - targetDir += ".dir/"; + targetDir += "/"; return targetDir; } diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index e5d7b57..bd01d50 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -390,7 +390,7 @@ bool cmQtAutoGenerators::WriteOldMocDefinitionsFile( void cmQtAutoGenerators::Init() { this->TargetBuildSubDir = this->TargetName; - this->TargetBuildSubDir += ".dir/"; + this->TargetBuildSubDir += "/"; this->OutMocCppFilenameRel = this->TargetBuildSubDir; this->OutMocCppFilenameRel += "moc_compilation.cpp"; -- cgit v0.12 From 057ac11bfbc5501c8037b173a73a55466163774d Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Thu, 1 Dec 2016 09:24:48 +0100 Subject: QtAutogen: Use checksum based subdirectories to avoid name collisions --- Source/CMakeLists.txt | 4 +- Source/cmFilePathChecksum.cxx | 88 ++++++++++++++++++++++++ Source/cmFilePathChecksum.h | 65 ++++++++++++++++++ Source/cmFilePathUuid.cxx | 118 -------------------------------- Source/cmFilePathUuid.h | 69 ------------------- Source/cmQtAutoGeneratorInitializer.cxx | 40 +++++++---- Source/cmQtAutoGenerators.cxx | 47 ++++++------- Source/cmQtAutoGenerators.h | 3 + 8 files changed, 205 insertions(+), 229 deletions(-) create mode 100644 Source/cmFilePathChecksum.cxx create mode 100644 Source/cmFilePathChecksum.h delete mode 100644 Source/cmFilePathUuid.cxx delete mode 100644 Source/cmFilePathUuid.h diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 5b381b4..d15fdbe 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -243,8 +243,8 @@ set(SRCS cmFileLockPool.h cmFileLockResult.cxx cmFileLockResult.h - cmFilePathUuid.cxx - cmFilePathUuid.h + cmFilePathChecksum.cxx + cmFilePathChecksum.h cmFileTimeComparison.cxx cmFileTimeComparison.h cmFortranLexer.cxx diff --git a/Source/cmFilePathChecksum.cxx b/Source/cmFilePathChecksum.cxx new file mode 100644 index 0000000..3d8b695 --- /dev/null +++ b/Source/cmFilePathChecksum.cxx @@ -0,0 +1,88 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmFilePathChecksum.h" + +#include "cmBase32.h" +#include "cmCryptoHash.h" +#include "cmMakefile.h" +#include "cmSystemTools.h" + +#include + +cmFilePathChecksum::cmFilePathChecksum() +{ +} + +cmFilePathChecksum::cmFilePathChecksum(const std::string& currentSrcDir, + const std::string& currentBinDir, + const std::string& projectSrcDir, + const std::string& projectBinDir) +{ + setupParentDirs(currentSrcDir, currentBinDir, projectSrcDir, projectBinDir); +} + +cmFilePathChecksum::cmFilePathChecksum(cmMakefile* makefile) +{ + setupParentDirs(makefile->GetCurrentSourceDirectory(), + makefile->GetCurrentBinaryDirectory(), + makefile->GetHomeDirectory(), + makefile->GetHomeOutputDirectory()); +} + +void cmFilePathChecksum::setupParentDirs(const std::string& currentSrcDir, + const std::string& currentBinDir, + const std::string& projectSrcDir, + const std::string& projectBinDir) +{ + parentDirs[0].first = cmsys::SystemTools::GetRealPath(currentSrcDir); + parentDirs[1].first = cmsys::SystemTools::GetRealPath(currentBinDir); + parentDirs[2].first = cmsys::SystemTools::GetRealPath(projectSrcDir); + parentDirs[3].first = cmsys::SystemTools::GetRealPath(projectBinDir); + + parentDirs[0].second = "CurrentSource"; + parentDirs[1].second = "CurrentBinary"; + parentDirs[2].second = "ProjectSource"; + parentDirs[3].second = "ProjectBinary"; +} + +std::string cmFilePathChecksum::get(const std::string& filePath) +{ + std::string relPath; + std::string relSeed; + { + const std::string fileReal = cmsys::SystemTools::GetRealPath(filePath); + std::string parentDir; + // Find closest project parent directory + for (size_t ii = 0; ii != numParentDirs; ++ii) { + const std::string& pDir = parentDirs[ii].first; + if (!pDir.empty() && + cmsys::SystemTools::IsSubDirectory(fileReal, pDir)) { + relSeed = parentDirs[ii].second; + parentDir = pDir; + break; + } + } + // Use file system root as fallback parent directory + if (parentDir.empty()) { + relSeed = "FileSystemRoot"; + cmsys::SystemTools::SplitPathRootComponent(fileReal, &parentDir); + } + // Calculate relative path from project parent directory + relPath = cmsys::SystemTools::RelativePath( + parentDir, cmsys::SystemTools::GetParentDirectory(fileReal)); + } + + // Calculate the file ( seed + relative path ) binary checksum + std::vector hashBytes = + cmCryptoHash(cmCryptoHash::AlgoSHA256).ByteHashString(relSeed + relPath); + + // Convert binary checksum to string + return cmBase32Encoder().encodeString(&hashBytes[0], hashBytes.size(), + false); +} + +std::string cmFilePathChecksum::getPart(const std::string& filePath, + size_t length) +{ + return get(filePath).substr(0, length); +} diff --git a/Source/cmFilePathChecksum.h b/Source/cmFilePathChecksum.h new file mode 100644 index 0000000..df19053 --- /dev/null +++ b/Source/cmFilePathChecksum.h @@ -0,0 +1,65 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmFilePathChecksum_h +#define cmFilePathChecksum_h + +#include // IWYU pragma: keep + +#include +#include +#include + +class cmMakefile; + +/** \class cmFilePathChecksum + * @brief Generates a checksum for the parent directory of a file + * + * The checksum is calculated from the relative file path to the + * closest known project directory. This guarantees reproducibility + * when source and build directory differ e.g. for different project + * build directories. + */ +class cmFilePathChecksum +{ +public: + /// Maximum number of characters to use from the path checksum + static const size_t partLengthDefault = 10; + + /// @brief Parent directories are empty + cmFilePathChecksum(); + + /// @brief Initilizes the parent directories manually + cmFilePathChecksum(const std::string& currentSrcDir, + const std::string& currentBinDir, + const std::string& projectSrcDir, + const std::string& projectBinDir); + + /// @brief Initilizes the parent directories from a makefile + cmFilePathChecksum(cmMakefile* makefile); + + /// @brief Allows parent directories setup after construction + /// + void setupParentDirs(const std::string& currentSrcDir, + const std::string& currentBinDir, + const std::string& projectSrcDir, + const std::string& projectBinDir); + + /* @brief Calculates the path checksum for the parent directory of a file + * + */ + std::string get(const std::string& filePath); + + /* @brief Same as get() but returns only the first length characters + * + */ + std::string getPart(const std::string& filePath, + size_t length = partLengthDefault); + +private: + /// Size of the parent directory list + static const size_t numParentDirs = 4; + /// List of (directory name, seed name) pairs + std::pair parentDirs[numParentDirs]; +}; + +#endif diff --git a/Source/cmFilePathUuid.cxx b/Source/cmFilePathUuid.cxx deleted file mode 100644 index 03d2524..0000000 --- a/Source/cmFilePathUuid.cxx +++ /dev/null @@ -1,118 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#include "cmFilePathUuid.h" - -#include "cmBase32.h" -#include "cmCryptoHash.h" -#include "cmMakefile.h" -#include "cmSystemTools.h" - -#include - -cmFilePathUuid::cmFilePathUuid(cmMakefile* makefile) -{ - initParentDirs(makefile->GetCurrentSourceDirectory(), - makefile->GetCurrentBinaryDirectory(), - makefile->GetHomeDirectory(), - makefile->GetHomeOutputDirectory()); -} - -cmFilePathUuid::cmFilePathUuid(const std::string& currentSrcDir, - const std::string& currentBinDir, - const std::string& projectSrcDir, - const std::string& projectBinDir) -{ - initParentDirs(currentSrcDir, currentBinDir, projectSrcDir, projectBinDir); -} - -void cmFilePathUuid::initParentDirs(const std::string& currentSrcDir, - const std::string& currentBinDir, - const std::string& projectSrcDir, - const std::string& projectBinDir) -{ - parentDirs[0].first = cmsys::SystemTools::GetRealPath(currentSrcDir); - parentDirs[1].first = cmsys::SystemTools::GetRealPath(currentBinDir); - parentDirs[2].first = cmsys::SystemTools::GetRealPath(projectSrcDir); - parentDirs[3].first = cmsys::SystemTools::GetRealPath(projectBinDir); - - parentDirs[0].second = "CurrentSource"; - parentDirs[1].second = "CurrentBinary"; - parentDirs[2].second = "ProjectSource"; - parentDirs[3].second = "ProjectBinary"; -} - -std::string cmFilePathUuid::get(const std::string& filePath, - const char* outputPrefix, - const char* outputSuffix) -{ - std::string sourceFilename = cmsys::SystemTools::GetFilenameName(filePath); - std::string sourceBasename = - cmsys::SystemTools::GetFilenameWithoutLastExtension(sourceFilename); - - // Acquire checksum string - std::string checksum; - { - std::string sourceRelPath; - std::string sourceRelSeed; - GetRelPathSeed(filePath, sourceRelPath, sourceRelSeed); - checksum = GetChecksumString(sourceFilename, sourceRelPath, sourceRelSeed); - } - - // Compose the file name - std::string uuid; - if (outputPrefix) { - uuid += outputPrefix; - } - uuid += sourceBasename.substr(0, partLengthName); - uuid += "_"; - uuid += checksum.substr(0, partLengthCheckSum); - if (outputSuffix) { - uuid += outputSuffix; - } - return uuid; -} - -void cmFilePathUuid::GetRelPathSeed(const std::string& filePath, - std::string& sourceRelPath, - std::string& sourceRelSeed) -{ - const std::string sourceNameReal = cmsys::SystemTools::GetRealPath(filePath); - std::string parentDirectory; - // Find closest project parent directory - for (size_t ii = 0; ii != numParentDirs; ++ii) { - const std::string& pDir = parentDirs[ii].first; - if (!pDir.empty() && - cmsys::SystemTools::IsSubDirectory(sourceNameReal, pDir)) { - sourceRelSeed = parentDirs[ii].second; - parentDirectory = pDir; - break; - } - } - // Check if the file path is below a known project directory - if (parentDirectory.empty()) { - // Use file syste root as fallback parent directory - sourceRelSeed = "FileSystemRoot"; - cmsys::SystemTools::SplitPathRootComponent(sourceNameReal, - &parentDirectory); - } - sourceRelPath = cmsys::SystemTools::RelativePath( - parentDirectory, cmsys::SystemTools::GetParentDirectory(sourceNameReal)); -} - -std::string cmFilePathUuid::GetChecksumString( - const std::string& sourceFilename, const std::string& sourceRelPath, - const std::string& sourceRelSeed) -{ - std::string checksumBase32; - { - // Calculate the file ( seed + relative path + name ) checksum - std::vector hashBytes = - cmCryptoHash(cmCryptoHash::AlgoSHA256) - .ByteHashString(sourceRelSeed + sourceRelPath + sourceFilename); - - checksumBase32 = - cmBase32Encoder().encodeString(&hashBytes[0], hashBytes.size(), false); - } - - return checksumBase32; -} diff --git a/Source/cmFilePathUuid.h b/Source/cmFilePathUuid.h deleted file mode 100644 index a450526..0000000 --- a/Source/cmFilePathUuid.h +++ /dev/null @@ -1,69 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#ifndef cmFilePathUuid_h -#define cmFilePathUuid_h - -#include // IWYU pragma: keep - -#include -#include -#include - -class cmMakefile; - -/** \class cmFilePathUuid - * @brief Generates a unique pathless file name with a checksum component - * calculated from the file path. - * - * The checksum is calculated from the relative file path to the - * closest known project directory. This guarantees reproducibility - * when source and build directory differ e.g. for different project - * build directories. - */ -class cmFilePathUuid -{ -public: - /// Maximum number of characters to use from the file name - static const size_t partLengthName = 14; - /// Maximum number of characters to use from the path checksum - static const size_t partLengthCheckSum = 14; - - /// @brief Initilizes the parent directories from a makefile - cmFilePathUuid(cmMakefile* makefile); - - /// @brief Initilizes the parent directories manually - cmFilePathUuid(const std::string& currentSrcDir, - const std::string& currentBinDir, - const std::string& projectSrcDir, - const std::string& projectBinDir); - - /* @brief Calculates and returns the uuid for a file path - * - * @arg outputPrefix optional string to prepend to the result - * @arg outputSuffix optional string to append to the result - */ - std::string get(const std::string& filePath, - const char* outputPrefix = CM_NULLPTR, - const char* outputSuffix = CM_NULLPTR); - -private: - void initParentDirs(const std::string& currentSrcDir, - const std::string& currentBinDir, - const std::string& projectSrcDir, - const std::string& projectBinDir); - - /// Returns the relative path and the parent directory key string (seed) - void GetRelPathSeed(const std::string& filePath, std::string& sourceRelPath, - std::string& sourceRelSeed); - - std::string GetChecksumString(const std::string& sourceFilename, - const std::string& sourceRelPath, - const std::string& sourceRelSeed); - - /// Size of the parent directory list - static const size_t numParentDirs = 4; - /// List of (directory name, seed name) pairs - std::pair parentDirs[numParentDirs]; -}; - -#endif diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index e589a5a..9766a5a 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -4,7 +4,7 @@ #include "cmAlgorithms.h" #include "cmCustomCommandLines.h" -#include "cmFilePathUuid.h" +#include "cmFilePathChecksum.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" #include "cmLocalGenerator.h" @@ -96,7 +96,7 @@ static void SetupSourceFiles(cmGeneratorTarget const* target, std::vector newRccFiles; - cmFilePathUuid fpathUuid(makefile); + cmFilePathChecksum fpathCheckSum(makefile); for (std::vector::const_iterator fileIt = srcFiles.begin(); fileIt != srcFiles.end(); ++fileIt) { cmSourceFile* sf = *fileIt; @@ -115,15 +115,21 @@ static void SetupSourceFiles(cmGeneratorTarget const* target, if (ext == "qrc" && !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) { - std::string rcc_output_file = GetAutogenTargetBuildDir(target); - // Create output directory - cmSystemTools::MakeDirectory(rcc_output_file.c_str()); - rcc_output_file += fpathUuid.get(absFile, "qrc_", ".cpp"); + std::string rccOutputFile = GetAutogenTargetBuildDir(target); + rccOutputFile += fpathCheckSum.getPart(absFile); + rccOutputFile += "/qrc_"; + rccOutputFile += + cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile); + rccOutputFile += ".cpp"; makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", - rcc_output_file.c_str(), false); - makefile->GetOrCreateSource(rcc_output_file, true); - newRccFiles.push_back(rcc_output_file); + rccOutputFile.c_str(), false); + makefile->GetOrCreateSource(rccOutputFile, true); + newRccFiles.push_back(rccOutputFile); + + // Create output directory + cmSystemTools::MakeDirectory( + cmsys::SystemTools::GetFilenamePath(rccOutputFile)); } } @@ -755,9 +761,9 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( #endif ) { if (target->GetPropertyAsBool("AUTORCC")) { + cmFilePathChecksum fpathCheckSum(makefile); std::vector srcFiles; target->GetConfigCommonSourceFiles(srcFiles); - cmFilePathUuid fpathUuid(makefile); for (std::vector::const_iterator fileIt = srcFiles.begin(); fileIt != srcFiles.end(); ++fileIt) { @@ -767,11 +773,17 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( { const std::string absFile = cmsys::SystemTools::GetRealPath(sf->GetFullPath()); - std::string rcc_output_file = GetAutogenTargetBuildDir(target); + + std::string rccOutputFile = GetAutogenTargetBuildDir(target); + rccOutputFile += fpathCheckSum.getPart(absFile); + rccOutputFile += "/qrc_"; + rccOutputFile += + cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile); + rccOutputFile += ".cpp"; + rcc_output.push_back(rccOutputFile); // Create output directory - cmSystemTools::MakeDirectory(rcc_output_file.c_str()); - rcc_output_file += fpathUuid.get(absFile, "qrc_", ".cpp"); - rcc_output.push_back(rcc_output_file); + cmSystemTools::MakeDirectory( + cmsys::SystemTools::GetFilenamePath(rccOutputFile)); } if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"))) { RccListInputs(qtMajorVersion, sf, target, depends); diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index bd01d50..bb18e2e 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -15,7 +15,6 @@ #include #include "cmAlgorithms.h" -#include "cmFilePathUuid.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmOutputConverter.h" @@ -397,6 +396,11 @@ void cmQtAutoGenerators::Init() this->OutMocCppFilenameAbs = this->Builddir + this->OutMocCppFilenameRel; + // Init file path checksum generator + fpathCheckSum.setupParentDirs(this->Srcdir, this->Builddir, + this->ProjectSourceDir, + this->ProjectBinaryDir); + std::vector cdefList; cmSystemTools::ExpandListArgument(this->MocCompileDefinitionsStr, cdefList); for (std::vector::const_iterator it = cdefList.begin(); @@ -967,8 +971,6 @@ void cmQtAutoGenerators::ParseHeaders( std::map& notIncludedMocs, std::map >& includedUis) { - cmFilePathUuid fpathUuid(this->Srcdir, this->Builddir, - this->ProjectSourceDir, this->ProjectBinaryDir); for (std::set::const_iterator hIt = absHeaders.begin(); hIt != absHeaders.end(); ++hIt) { const std::string& headerName = *hIt; @@ -984,8 +986,10 @@ void cmQtAutoGenerators::ParseHeaders( std::string macroName; if (requiresMocing(contents, macroName)) { - notIncludedMocs[headerName] = - this->TargetBuildSubDir + fpathUuid.get(headerName, "moc_", ".cpp"); + notIncludedMocs[headerName] = this->TargetBuildSubDir + + fpathCheckSum.getPart(headerName) + "/moc_" + + cmsys::SystemTools::GetFilenameWithoutLastExtension(headerName) + + ".cpp"; } } this->ParseForUic(headerName, contents, includedUis); @@ -1318,18 +1322,13 @@ bool cmQtAutoGenerators::GenerateQrcFiles() { // generate single map with input / output names std::map qrcGenMap; - { - cmFilePathUuid fpathUuid(this->Srcdir, this->Builddir, - this->ProjectSourceDir, this->ProjectBinaryDir); - for (std::vector::const_iterator si = - this->RccSources.begin(); - si != this->RccSources.end(); ++si) { - const std::string ext = - cmsys::SystemTools::GetFilenameLastExtension(*si); - if (ext == ".qrc") { - qrcGenMap[*si] = - (this->TargetBuildSubDir + fpathUuid.get(*si, "qrc_", ".cpp")); - } + for (std::vector::const_iterator si = this->RccSources.begin(); + si != this->RccSources.end(); ++si) { + const std::string ext = cmsys::SystemTools::GetFilenameLastExtension(*si); + if (ext == ".qrc") { + qrcGenMap[*si] = this->TargetBuildSubDir + fpathCheckSum.getPart(*si) + + "/qrc_" + cmsys::SystemTools::GetFilenameWithoutLastExtension(*si) + + ".cpp"; } } @@ -1368,15 +1367,11 @@ bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile, const std::string& qrcOutputFile, bool unique_n) { - std::string symbolName; - if (unique_n) { - symbolName = - cmsys::SystemTools::GetFilenameWithoutLastExtension(qrcInputFile); - } else { - symbolName = - cmsys::SystemTools::GetFilenameWithoutLastExtension(qrcOutputFile); - // Remove "qrc_" at string begin - symbolName.erase(0, 4); + std::string symbolName = + cmsys::SystemTools::GetFilenameWithoutLastExtension(qrcInputFile); + if (!unique_n) { + symbolName += "_"; + symbolName += fpathCheckSum.getPart(qrcInputFile); } // Replace '-' with '_'. The former is valid for // file names but not for symbol names. diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 466acb2..302c9be 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -4,6 +4,7 @@ #define cmQtAutoGenerators_h #include // IWYU pragma: keep +#include #include #include @@ -130,6 +131,8 @@ private: std::map RccOptions; std::map > RccInputs; + cmFilePathChecksum fpathCheckSum; + bool IncludeProjectDirsBefore; bool Verbose; bool ColorOutput; -- cgit v0.12 From 8f47a5f16aa685e15e6b49c0b90a58b18ea38d0a Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Thu, 1 Dec 2016 18:15:32 +0100 Subject: cmGeneratorTarget: Add AddIncludeDirectory method (experimental) --- Source/cmGeneratorTarget.cxx | 15 +++++++++++++++ Source/cmGeneratorTarget.h | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 903bcec..6ee2c14 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -533,6 +533,21 @@ void cmGeneratorTarget::AddTracedSources(std::vector const& srcs) } } +void cmGeneratorTarget::AddIncludeDirectory(const std::string& src, + bool before) +{ + this->Target->InsertInclude(src, this->Makefile->GetBacktrace(), before); + cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); + cmGeneratorExpression ge(lfbt); + CM_AUTO_PTR cge = ge.Parse(src); + cge->SetEvaluateForBuildsystem(true); + // Insert before begin/end + std::vector::iterator pos = before + ? this->IncludeDirectoriesEntries.begin() + : this->IncludeDirectoriesEntries.end(); + this->IncludeDirectoriesEntries.insert(pos, new TargetPropertyEntry(cge)); +} + std::vector const* cmGeneratorTarget::GetSourceDepends( cmSourceFile const* sf) const { diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 4c3c14b..f568699 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -396,6 +396,12 @@ public: void AddTracedSources(std::vector const& srcs); /** + * Adds an entry to the INCLUDE_DIRECTORIES list. + * If before is true the entry is pushed at the front. + */ + void AddIncludeDirectory(const std::string& src, bool before = false); + + /** * Flags for a given source file as used in this target. Typically assigned * via SET_TARGET_PROPERTIES when the property is a list of source files. */ -- cgit v0.12 From 8c9358386b0b2826ffc3da4385474a4227477eef Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 2 Dec 2016 11:21:52 +0100 Subject: 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. --- Source/cmQtAutoGeneratorInitializer.cxx | 17 ++++++- Source/cmQtAutoGenerators.cxx | 90 +++++++++++++++++---------------- Source/cmQtAutoGenerators.h | 6 ++- 3 files changed, 66 insertions(+), 47 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 9766a5a..bc75c59 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -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 depends; if (const char* autogenDepends = diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index bb18e2e..ee5eb11 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -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::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::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::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::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::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; } diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 302c9be..5fbaf87 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -31,15 +31,19 @@ private: std::string MakeCompileSettingsString(cmMakefile* makefile); bool RunAutogen(cmMakefile* makefile); + bool GenerateMocFiles( const std::map& includedMocs, const std::map& notIncludedMocs); bool GenerateMoc(const std::string& sourceFile, - const std::string& mocFileName); + const std::string& mocFileName, + const std::string& subDirPrefix); + bool GenerateUiFiles( const std::map >& 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); -- cgit v0.12 From 5c3dc7460ea6644bd658131ec474e6ddce825b1a Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 2 Dec 2016 11:32:12 +0100 Subject: QtAutogen: Clean removes autogen build directory Cleaning removes the entire autogen build directory instead of single files. --- Source/cmQtAutoGeneratorInitializer.cxx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index bc75c59..b12045c 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -122,8 +122,6 @@ static void SetupSourceFiles(cmGeneratorTarget const* target, cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile); rccOutputFile += ".cpp"; - makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", - rccOutputFile.c_str(), false); makefile->GetOrCreateSource(rccOutputFile, true); newRccFiles.push_back(rccOutputFile); @@ -661,9 +659,6 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenSources( const std::string mocCppFile = GetAutogenTargetBuildDir(target) + "moc_compilation.cpp"; makefile->GetOrCreateSource(mocCppFile, true); - makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", mocCppFile.c_str(), - false); - target->AddSource(mocCppFile); } } @@ -686,6 +681,9 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( // Create autogen target build directory cmSystemTools::MakeDirectory(autogenBuildDir); + // Remove entire autogen build directory on clean + makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", + autogenBuildDir.c_str(), false); // Create autogen target includes directory and // add it to the origin target INCLUDE_DIRECTORIES -- cgit v0.12 From b770b85d6c05fd36462172e33c8b700b22b801e9 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 2 Dec 2016 12:10:51 +0100 Subject: QtAutogen: Determine the Qt major version in only one way --- Source/cmQtAutoGeneratorInitializer.cxx | 79 ++++++++++++++------------------- 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index b12045c..ca7ca8e 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -83,6 +83,21 @@ static std::string GetAutogenTargetBuildDir(cmGeneratorTarget const* target) return targetDir; } +static std::string GetQtMajorVersion(cmGeneratorTarget const* target) +{ + cmMakefile* makefile = target->Target->GetMakefile(); + std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR"); + if (qtMajorVersion.empty()) { + qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR"); + } + const char* targetQtVersion = + target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", ""); + if (targetQtVersion != CM_NULLPTR) { + qtMajorVersion = targetQtVersion; + } + return qtMajorVersion; +} + static void SetupSourceFiles(cmGeneratorTarget const* target, std::vector& skipMoc, std::vector& mocSources, @@ -355,25 +370,13 @@ static void UicSetupAutoTarget( } } -static std::string RccGetExecutable(cmGeneratorTarget const* target) +static std::string RccGetExecutable(cmGeneratorTarget const* target, + const std::string& qtMajorVersion) { cmLocalGenerator* lg = target->GetLocalGenerator(); - cmMakefile* makefile = target->Target->GetMakefile(); - const char* qtVersion = makefile->GetDefinition("_target_qt_version"); - if (!qtVersion) { - qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR"); - if (!qtVersion) { - qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR"); - } - if (const char* targetQtVersion = - target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", - "")) { - qtVersion = targetQtVersion; - } - } - std::string targetName = target->GetName(); - if (strcmp(qtVersion, "5") == 0) { + std::string const& targetName = target->GetName(); + if (qtMajorVersion == "5") { cmGeneratorTarget* qt5Rcc = lg->FindGeneratorTargetToUse("Qt5::rcc"); if (!qt5Rcc) { cmSystemTools::Error("Qt5::rcc target not found ", targetName.c_str()); @@ -381,7 +384,7 @@ static std::string RccGetExecutable(cmGeneratorTarget const* target) } return qt5Rcc->ImportedGetLocation(""); } - if (strcmp(qtVersion, "4") == 0) { + if (qtMajorVersion == "4") { cmGeneratorTarget* qt4Rcc = lg->FindGeneratorTargetToUse("Qt4::rcc"); if (!qt4Rcc) { cmSystemTools::Error("Qt4::rcc target not found ", targetName.c_str()); @@ -433,7 +436,11 @@ static void RccMergeOptions(std::vector& opts, static bool RccListInputsQt5(cmSourceFile* sf, cmGeneratorTarget const* target, std::vector& depends) { - const std::string rccCommand = RccGetExecutable(target); + const std::string rccCommand = RccGetExecutable(target, "5"); + if (rccCommand.empty()) { + cmSystemTools::Error("AUTOGEN: error: rcc executable not available\n"); + return false; + } bool hasDashDashList = false; // Read rcc features @@ -562,7 +569,8 @@ static bool RccListInputs(const std::string& qtMajorVersion, cmSourceFile* sf, return RccListInputsQt4(sf, depends); } -static void RccSetupAutoTarget(cmGeneratorTarget const* target) +static void RccSetupAutoTarget(cmGeneratorTarget const* target, + const std::string& qtMajorVersion) { std::string _rcc_files; const char* sepRccFiles = ""; @@ -578,16 +586,12 @@ static void RccSetupAutoTarget(cmGeneratorTarget const* target) std::string rccFileOptions; const char* optionSep = ""; - const char* qtVersion = makefile->GetDefinition("_target_qt_version"); + const bool qtMajorVersion5 = (qtMajorVersion == "5"); std::vector rccOptions; if (const char* opts = target->GetProperty("AUTORCC_OPTIONS")) { cmSystemTools::ExpandListArgument(opts, rccOptions); } - std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR"); - if (qtMajorVersion == "") { - qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR"); - } for (std::vector::const_iterator fileIt = srcFiles.begin(); fileIt != srcFiles.end(); ++fileIt) { @@ -605,7 +609,7 @@ static void RccSetupAutoTarget(cmGeneratorTarget const* target) if (const char* prop = sf->GetProperty("AUTORCC_OPTIONS")) { std::vector optsVec; cmSystemTools::ExpandListArgument(prop, optsVec); - RccMergeOptions(rccOptions, optsVec, strcmp(qtVersion, "5") == 0); + RccMergeOptions(rccOptions, optsVec, qtMajorVersion5); } if (!rccOptions.empty()) { @@ -648,7 +652,7 @@ static void RccSetupAutoTarget(cmGeneratorTarget const* target) "_rcc_options_options", cmOutputConverter::EscapeForCMake(rccFileOptions).c_str()); makefile->AddDefinition("_qt_rcc_executable", - RccGetExecutable(target).c_str()); + RccGetExecutable(target, qtMajorVersion).c_str()); } void cmQtAutoGeneratorInitializer::InitializeAutogenSources( @@ -673,11 +677,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( const std::string autogenBuildDir = GetAutogenTargetBuildDir(target); const std::string workingDirectory = cmSystemTools::CollapseFullPath("", makefile->GetCurrentBinaryDirectory()); - - std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR"); - if (qtMajorVersion == "") { - qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR"); - } + const std::string qtMajorVersion = GetQtMajorVersion(target); // Create autogen target build directory cmSystemTools::MakeDirectory(autogenBuildDir); @@ -863,6 +863,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( // create a custom target for running generators at buildtime: const std::string autogenTargetName = GetAutogenTargetName(target); + const std::string qtMajorVersion = GetQtMajorVersion(target); makefile->AddDefinition( "_moc_target_name", @@ -870,19 +871,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( makefile->AddDefinition( "_origin_target_name", cmOutputConverter::EscapeForCMake(target->GetName()).c_str()); - - const char* qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR"); - if (!qtVersion) { - qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR"); - } - if (const char* targetQtVersion = - target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", - "")) { - qtVersion = targetQtVersion; - } - if (qtVersion) { - makefile->AddDefinition("_target_qt_version", qtVersion); - } + makefile->AddDefinition("_target_qt_version", qtMajorVersion.c_str()); std::vector skipUic; std::vector skipMoc; @@ -908,7 +897,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( UicSetupAutoTarget(target, skipUic, configUicOptions); } if (target->GetPropertyAsBool("AUTORCC")) { - RccSetupAutoTarget(target); + RccSetupAutoTarget(target, qtMajorVersion); } // Generate config file -- cgit v0.12 From d9996aab74836bb830e106bea0b0064a4c74cb1c Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 2 Dec 2016 12:13:59 +0100 Subject: QtAutogen: Inline single use variable definitions --- Source/cmQtAutoGeneratorInitializer.cxx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index ca7ca8e..7448ec2 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -115,17 +115,14 @@ static void SetupSourceFiles(cmGeneratorTarget const* target, for (std::vector::const_iterator fileIt = srcFiles.begin(); fileIt != srcFiles.end(); ++fileIt) { cmSourceFile* sf = *fileIt; - std::string absFile = cmsys::SystemTools::GetRealPath(sf->GetFullPath()); - bool skipFileForMoc = - cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC")); - bool generated = cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED")); + const std::string absFile = + cmsys::SystemTools::GetRealPath(sf->GetFullPath()); + const std::string ext = sf->GetExtension(); if (cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOUIC"))) { skipUic.push_back(absFile); } - std::string ext = sf->GetExtension(); - if (target->GetPropertyAsBool("AUTORCC")) { if (ext == "qrc" && !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) { @@ -146,8 +143,8 @@ static void SetupSourceFiles(cmGeneratorTarget const* target, } } - if (!generated) { - if (skipFileForMoc) { + if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"))) { + if (cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC"))) { skipMoc.push_back(absFile); } else { cmSystemTools::FileFormat fileType = -- cgit v0.12 From b5409d04f1c1309deb7e45163a106c8cb4daf38c Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 2 Dec 2016 13:03:38 +0100 Subject: QtAutogen: Rename autogen target to *_autogen from *_automoc --- Help/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst | 2 +- Help/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst | 2 +- Help/prop_tgt/AUTOGEN_TARGET_DEPENDS.rst | 8 ++++---- Source/cmQtAutoGeneratorInitializer.cxx | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Help/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst b/Help/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst index 5a69ef3..fae5626 100644 --- a/Help/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst +++ b/Help/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst @@ -1,7 +1,7 @@ AUTOGEN_TARGETS_FOLDER ---------------------- -Name of :prop_tgt:`FOLDER` for ``*_automoc`` targets that are added automatically by +Name of :prop_tgt:`FOLDER` for ``*_autogen`` targets that are added automatically by CMake for targets for which :prop_tgt:`AUTOMOC` is enabled. If not set, CMake uses the :prop_tgt:`FOLDER` property of the parent target as a diff --git a/Help/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst b/Help/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst index 671f86a..17666e4 100644 --- a/Help/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst +++ b/Help/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst @@ -1,7 +1,7 @@ AUTOMOC_TARGETS_FOLDER ---------------------- -Name of :prop_tgt:`FOLDER` for ``*_automoc`` targets that are added automatically by +Name of :prop_tgt:`FOLDER` for ``*_autogen`` targets that are added automatically by CMake for targets for which :prop_tgt:`AUTOMOC` is enabled. This property is obsolete. Use :prop_gbl:`AUTOGEN_TARGETS_FOLDER` instead. diff --git a/Help/prop_tgt/AUTOGEN_TARGET_DEPENDS.rst b/Help/prop_tgt/AUTOGEN_TARGET_DEPENDS.rst index 5063244..f522c6b 100644 --- a/Help/prop_tgt/AUTOGEN_TARGET_DEPENDS.rst +++ b/Help/prop_tgt/AUTOGEN_TARGET_DEPENDS.rst @@ -1,16 +1,16 @@ AUTOGEN_TARGET_DEPENDS ---------------------- -Target dependencies of the corresponding ``_automoc`` target. +Target dependencies of the corresponding ``_autogen`` target. Targets which have their :prop_tgt:`AUTOMOC` target ``ON`` have a -corresponding ``_automoc`` target which is used to autogenerate generate moc -files. As this ``_automoc`` target is created at generate-time, it is not +corresponding ``_autogen`` target which is used to autogenerate generate moc +files. As this ``_autogen`` target is created at generate-time, it is not possible to define dependencies of it, such as to create inputs for the ``moc`` executable. The ``AUTOGEN_TARGET_DEPENDS`` target property can be set instead to a list of -dependencies for the ``_automoc`` target. The buildsystem will be generated to +dependencies for the ``_autogen`` target. The buildsystem will be generated to depend on its contents. See the :manual:`cmake-qt(7)` manual for more information on using CMake diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 7448ec2..889c61d 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -58,7 +58,7 @@ static std::string utilStripCR(std::string const& line) static std::string GetAutogenTargetName(cmGeneratorTarget const* target) { std::string autogenTargetName = target->GetName(); - autogenTargetName += "_automoc"; + autogenTargetName += "_autogen"; return autogenTargetName; } -- cgit v0.12 From 360c3427117312548358fddce906a346f17b8f5f Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 2 Dec 2016 16:24:51 +0100 Subject: QtAutogen: Reconfigure when .qrc file changes Add .qrc files to the CMake depends. When the .qrc file changes the build system gets reconfigured and the resource files watch list gets updated. --- Source/cmQtAutoGeneratorInitializer.cxx | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 889c61d..76fb8e5 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -109,7 +109,7 @@ static void SetupSourceFiles(cmGeneratorTarget const* target, std::vector srcFiles; target->GetConfigCommonSourceFiles(srcFiles); - std::vector newRccFiles; + std::vector rccOutput; cmFilePathChecksum fpathCheckSum(makefile); for (std::vector::const_iterator fileIt = srcFiles.begin(); @@ -127,19 +127,16 @@ static void SetupSourceFiles(cmGeneratorTarget const* target, if (ext == "qrc" && !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) { + // Run cmake again when .qrc file changes + makefile->AddCMakeDependFile ( absFile ); + std::string rccOutputFile = GetAutogenTargetBuildDir(target); rccOutputFile += fpathCheckSum.getPart(absFile); rccOutputFile += "/qrc_"; rccOutputFile += cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile); rccOutputFile += ".cpp"; - - makefile->GetOrCreateSource(rccOutputFile, true); - newRccFiles.push_back(rccOutputFile); - - // Create output directory - cmSystemTools::MakeDirectory( - cmsys::SystemTools::GetFilenamePath(rccOutputFile)); + rccOutput.push_back(rccOutputFile); } } @@ -158,9 +155,16 @@ static void SetupSourceFiles(cmGeneratorTarget const* target, } } - for (std::vector::const_iterator fileIt = newRccFiles.begin(); - fileIt != newRccFiles.end(); ++fileIt) { - const_cast(target)->AddSource(*fileIt); + // Add rcc output files as sources + for (std::vector::const_iterator fileIt = rccOutput.begin(); + fileIt != rccOutput.end(); ++fileIt) { + const std::string& rccOutputFile = *fileIt; + // Add source + makefile->GetOrCreateSource(rccOutputFile, true); + const_cast(target)->AddSource(rccOutputFile); + // Create output directory + cmSystemTools::MakeDirectory( + cmsys::SystemTools::GetFilenamePath(rccOutputFile)); } } -- cgit v0.12 From 8f437f3c35ae13c147e0d022a84774750d4a0a7a Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 2 Dec 2016 17:20:25 +0100 Subject: QtAutogen: Add moc compilation file to autogen target byproducts Closes: #16389 --- Source/cmQtAutoGeneratorInitializer.cxx | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 76fb8e5..3a46ab0 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -679,22 +679,27 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( const std::string workingDirectory = cmSystemTools::CollapseFullPath("", makefile->GetCurrentBinaryDirectory()); const std::string qtMajorVersion = GetQtMajorVersion(target); + std::vector autogenOutputFiles; - // Create autogen target build directory + // Create autogen target build directory and add it to the clean files cmSystemTools::MakeDirectory(autogenBuildDir); - // Remove entire autogen build directory on clean makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", autogenBuildDir.c_str(), false); - // Create autogen target includes directory and - // add it to the origin target INCLUDE_DIRECTORIES if (target->GetPropertyAsBool("AUTOMOC") || target->GetPropertyAsBool("AUTOUIC")) { + // Create autogen target includes directory and + // add it to the origin target INCLUDE_DIRECTORIES const std::string incsDir = autogenBuildDir + "include"; cmSystemTools::MakeDirectory(incsDir); target->AddIncludeDirectory(incsDir, true); } + if (target->GetPropertyAsBool("AUTOMOC")) { + // Register moc compilation file as generated + autogenOutputFiles.push_back ( autogenBuildDir + "moc_compilation.cpp" ); + } + // Initialize autogen target dependencies std::vector depends; if (const char* autogenDepends = @@ -765,7 +770,6 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( } #endif - std::vector rcc_output; bool const isNinja = lg->GetGlobalGenerator()->GetName() == "Ninja"; if (isNinja #if defined(_WIN32) && !defined(__CYGWIN__) @@ -792,10 +796,8 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( rccOutputFile += cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile); rccOutputFile += ".cpp"; - rcc_output.push_back(rccOutputFile); - // Create output directory - cmSystemTools::MakeDirectory( - cmsys::SystemTools::GetFilenamePath(rccOutputFile)); + // Register rcc output file as generated + autogenOutputFiles.push_back(rccOutputFile); } if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"))) { RccListInputs(qtMajorVersion, sf, target, depends); @@ -829,7 +831,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( { cmTarget* autogenTarget = makefile->AddUtilityCommand( autogenTargetName, true, workingDirectory.c_str(), - /*byproducts=*/rcc_output, depends, commandLines, false, + /*byproducts=*/autogenOutputFiles, depends, commandLines, false, autogenComment.c_str()); cmGeneratorTarget* gt = new cmGeneratorTarget(autogenTarget, lg); -- cgit v0.12 From bafbeaf19076f9ae94be2b8cdb845617674aaf99 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 2 Dec 2016 17:21:40 +0100 Subject: QtAutogen: Add rcc output files to autogen target byproducts --- Source/cmQtAutoGeneratorInitializer.cxx | 56 ++++++++++++++++----------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 3a46ab0..8ddf5b6 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -128,7 +128,7 @@ static void SetupSourceFiles(cmGeneratorTarget const* target, !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) { // Run cmake again when .qrc file changes - makefile->AddCMakeDependFile ( absFile ); + makefile->AddCMakeDependFile(absFile); std::string rccOutputFile = GetAutogenTargetBuildDir(target); rccOutputFile += fpathCheckSum.getPart(absFile); @@ -697,7 +697,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( if (target->GetPropertyAsBool("AUTOMOC")) { // Register moc compilation file as generated - autogenOutputFiles.push_back ( autogenBuildDir + "moc_compilation.cpp" ); + autogenOutputFiles.push_back(autogenBuildDir + "moc_compilation.cpp"); } // Initialize autogen target dependencies @@ -770,35 +770,33 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( } #endif - bool const isNinja = lg->GetGlobalGenerator()->GetName() == "Ninja"; - if (isNinja + if (target->GetPropertyAsBool("AUTORCC")) { + cmFilePathChecksum fpathCheckSum(makefile); + std::vector srcFiles; + target->GetConfigCommonSourceFiles(srcFiles); + for (std::vector::const_iterator fileIt = srcFiles.begin(); + fileIt != srcFiles.end(); ++fileIt) { + cmSourceFile* sf = *fileIt; + if (sf->GetExtension() == "qrc" && + !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) { + { + const std::string absFile = + cmsys::SystemTools::GetRealPath(sf->GetFullPath()); + + std::string rccOutputFile = autogenBuildDir; + rccOutputFile += fpathCheckSum.getPart(absFile); + rccOutputFile += "/qrc_"; + rccOutputFile += + cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile); + rccOutputFile += ".cpp"; + // Register rcc output file as generated + autogenOutputFiles.push_back(rccOutputFile); + } + if (lg->GetGlobalGenerator()->GetName() == "Ninja" #if defined(_WIN32) && !defined(__CYGWIN__) - || usePRE_BUILD + || usePRE_BUILD #endif - ) { - if (target->GetPropertyAsBool("AUTORCC")) { - cmFilePathChecksum fpathCheckSum(makefile); - std::vector srcFiles; - target->GetConfigCommonSourceFiles(srcFiles); - for (std::vector::const_iterator fileIt = - srcFiles.begin(); - fileIt != srcFiles.end(); ++fileIt) { - cmSourceFile* sf = *fileIt; - if (sf->GetExtension() == "qrc" && - !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) { - { - const std::string absFile = - cmsys::SystemTools::GetRealPath(sf->GetFullPath()); - - std::string rccOutputFile = GetAutogenTargetBuildDir(target); - rccOutputFile += fpathCheckSum.getPart(absFile); - rccOutputFile += "/qrc_"; - rccOutputFile += - cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile); - rccOutputFile += ".cpp"; - // Register rcc output file as generated - autogenOutputFiles.push_back(rccOutputFile); - } + ) { if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"))) { RccListInputs(qtMajorVersion, sf, target, depends); #if defined(_WIN32) && !defined(__CYGWIN__) -- cgit v0.12 From df74f3ff834cacdd46aff7366a479d8317315a7c Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 2 Dec 2016 17:39:59 +0100 Subject: QtAutogen: Generate rcc output file names in one place only --- Source/cmQtAutoGeneratorInitializer.cxx | 38 ++++++--------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 8ddf5b6..f0847b1 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -109,8 +109,6 @@ static void SetupSourceFiles(cmGeneratorTarget const* target, std::vector srcFiles; target->GetConfigCommonSourceFiles(srcFiles); - std::vector rccOutput; - cmFilePathChecksum fpathCheckSum(makefile); for (std::vector::const_iterator fileIt = srcFiles.begin(); fileIt != srcFiles.end(); ++fileIt) { @@ -123,23 +121,6 @@ static void SetupSourceFiles(cmGeneratorTarget const* target, skipUic.push_back(absFile); } - if (target->GetPropertyAsBool("AUTORCC")) { - if (ext == "qrc" && - !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) { - - // Run cmake again when .qrc file changes - makefile->AddCMakeDependFile(absFile); - - std::string rccOutputFile = GetAutogenTargetBuildDir(target); - rccOutputFile += fpathCheckSum.getPart(absFile); - rccOutputFile += "/qrc_"; - rccOutputFile += - cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile); - rccOutputFile += ".cpp"; - rccOutput.push_back(rccOutputFile); - } - } - if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"))) { if (cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC"))) { skipMoc.push_back(absFile); @@ -154,18 +135,6 @@ static void SetupSourceFiles(cmGeneratorTarget const* target, } } } - - // Add rcc output files as sources - for (std::vector::const_iterator fileIt = rccOutput.begin(); - fileIt != rccOutput.end(); ++fileIt) { - const std::string& rccOutputFile = *fileIt; - // Add source - makefile->GetOrCreateSource(rccOutputFile, true); - const_cast(target)->AddSource(rccOutputFile); - // Create output directory - cmSystemTools::MakeDirectory( - cmsys::SystemTools::GetFilenamePath(rccOutputFile)); - } } static void GetCompileDefinitionsAndDirectories( @@ -783,12 +752,19 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( const std::string absFile = cmsys::SystemTools::GetRealPath(sf->GetFullPath()); + // Run cmake again when .qrc file changes + makefile->AddCMakeDependFile(absFile); + std::string rccOutputFile = autogenBuildDir; rccOutputFile += fpathCheckSum.getPart(absFile); rccOutputFile += "/qrc_"; rccOutputFile += cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile); rccOutputFile += ".cpp"; + + // Add rcc output file to origin target sources + makefile->GetOrCreateSource(rccOutputFile, true); + target->AddSource(rccOutputFile); // Register rcc output file as generated autogenOutputFiles.push_back(rccOutputFile); } -- cgit v0.12 From 98665c35199fffb66ff92f5f15da0e1580625cc0 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Sun, 4 Dec 2016 11:38:31 +0100 Subject: QtAutogen: Rename and sort variables --- Source/cmQtAutoGenerators.cxx | 74 +++++++++++++++++++++++++++---------------- Source/cmQtAutoGenerators.h | 42 +++++++++++++----------- 2 files changed, 70 insertions(+), 46 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index ee5eb11..506c820 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -200,26 +200,35 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( return false; } + // - Target names + this->OriginTargetName = + makefile->GetSafeDefinition("AM_ORIGIN_TARGET_NAME"); + this->AutogenTargetName = makefile->GetSafeDefinition("AM_TARGET_NAME"); + + // - Directories + this->ProjectSourceDir = makefile->GetSafeDefinition("AM_CMAKE_SOURCE_DIR"); + this->ProjectBinaryDir = makefile->GetSafeDefinition("AM_CMAKE_BINARY_DIR"); + this->CurrentSourceDir = + makefile->GetSafeDefinition("AM_CMAKE_CURRENT_SOURCE_DIR"); + this->CurrentBinaryDir = + makefile->GetSafeDefinition("AM_CMAKE_CURRENT_BINARY_DIR"); + + // - Qt environment this->QtMajorVersion = makefile->GetSafeDefinition("AM_QT_VERSION_MAJOR"); if (this->QtMajorVersion == "") { this->QtMajorVersion = makefile->GetSafeDefinition("AM_Qt5Core_VERSION_MAJOR"); } - this->Sources = makefile->GetSafeDefinition("AM_SOURCES"); - { - std::string rccSources = makefile->GetSafeDefinition("AM_RCC_SOURCES"); - cmSystemTools::ExpandListArgument(rccSources, this->RccSources); - } - this->SkipMoc = makefile->GetSafeDefinition("AM_SKIP_MOC"); - this->SkipUic = makefile->GetSafeDefinition("AM_SKIP_UIC"); - this->Headers = makefile->GetSafeDefinition("AM_HEADERS"); - this->IncludeProjectDirsBefore = - makefile->IsOn("AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"); - this->Srcdir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_SOURCE_DIR"); - this->Builddir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_BINARY_DIR"); this->MocExecutable = makefile->GetSafeDefinition("AM_QT_MOC_EXECUTABLE"); this->UicExecutable = makefile->GetSafeDefinition("AM_QT_UIC_EXECUTABLE"); this->RccExecutable = makefile->GetSafeDefinition("AM_QT_RCC_EXECUTABLE"); + + // - File Lists + this->Sources = makefile->GetSafeDefinition("AM_SOURCES"); + this->Headers = makefile->GetSafeDefinition("AM_HEADERS"); + + // - Moc + this->SkipMoc = makefile->GetSafeDefinition("AM_SKIP_MOC"); { std::string compileDefsPropOrig = "AM_MOC_COMPILE_DEFINITIONS"; std::string compileDefsProp = compileDefsPropOrig; @@ -244,12 +253,9 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( includes ? includes : makefile->GetSafeDefinition(includesPropOrig); } this->MocOptionsStr = makefile->GetSafeDefinition("AM_MOC_OPTIONS"); - this->ProjectBinaryDir = makefile->GetSafeDefinition("AM_CMAKE_BINARY_DIR"); - this->ProjectSourceDir = makefile->GetSafeDefinition("AM_CMAKE_SOURCE_DIR"); - this->TargetName = makefile->GetSafeDefinition("AM_TARGET_NAME"); - this->OriginTargetName = - makefile->GetSafeDefinition("AM_ORIGIN_TARGET_NAME"); + // - Uic + this->SkipUic = makefile->GetSafeDefinition("AM_SKIP_UIC"); { const char* uicOptionsFiles = makefile->GetSafeDefinition("AM_UIC_OPTIONS_FILES"); @@ -280,6 +286,12 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( this->UicOptions[*fileIt] = *optionIt; } } + + // - Rcc + { + std::string rccSources = makefile->GetSafeDefinition("AM_RCC_SOURCES"); + cmSystemTools::ExpandListArgument(rccSources, this->RccSources); + } { const char* rccOptionsFiles = makefile->GetSafeDefinition("AM_RCC_OPTIONS_FILES"); @@ -325,8 +337,13 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( this->RccInputs[*fileIt] = rccInputFiles; } } + + // - Settings this->CurrentCompileSettingsStr = this->MakeCompileSettingsString(makefile); + // - Flags + this->IncludeProjectDirsBefore = + makefile->IsOn("AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"); this->MocRelaxedMode = makefile->IsOn("AM_MOC_RELAXED_MODE"); return true; @@ -388,16 +405,17 @@ bool cmQtAutoGenerators::WriteOldMocDefinitionsFile( void cmQtAutoGenerators::Init() { - this->TargetBuildSubDir = this->TargetName; - this->TargetBuildSubDir += "/"; + this->AutogenBuildSubDir = this->AutogenTargetName; + this->AutogenBuildSubDir += "/"; - this->OutMocCppFilenameRel = this->TargetBuildSubDir; + this->OutMocCppFilenameRel = this->AutogenBuildSubDir; this->OutMocCppFilenameRel += "moc_compilation.cpp"; - this->OutMocCppFilenameAbs = this->Builddir + this->OutMocCppFilenameRel; + this->OutMocCppFilenameAbs = + this->CurrentBinaryDir + this->OutMocCppFilenameRel; // Init file path checksum generator - fpathCheckSum.setupParentDirs(this->Srcdir, this->Builddir, + fpathCheckSum.setupParentDirs(this->CurrentSourceDir, this->CurrentBinaryDir, this->ProjectSourceDir, this->ProjectBinaryDir); @@ -1125,8 +1143,8 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile, const std::string& subDirPrefix) { const std::string mocFileRel = - this->TargetBuildSubDir + subDirPrefix + mocFileName; - const std::string mocFileAbs = this->Builddir + mocFileRel; + this->AutogenBuildSubDir + subDirPrefix + mocFileName; + const std::string mocFileAbs = this->CurrentBinaryDir + mocFileRel; int sourceNewerThanMoc = 0; bool success = cmsys::SystemTools::FileTimeCompare(sourceFile, mocFileAbs, &sourceNewerThanMoc); @@ -1246,8 +1264,8 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& realName, const std::string& uiOutputFile) { const std::string uicFileRel = - this->TargetBuildSubDir + "include/" + uiOutputFile; - const std::string uicFileAbs = this->Builddir + uicFileRel; + this->AutogenBuildSubDir + "include/" + uiOutputFile; + const std::string uicFileAbs = this->CurrentBinaryDir + uicFileRel; int sourceNewerThanUi = 0; bool success = cmsys::SystemTools::FileTimeCompare(uiInputFile, uicFileAbs, @@ -1328,7 +1346,7 @@ bool cmQtAutoGenerators::GenerateQrcFiles() si != this->RccSources.end(); ++si) { const std::string ext = cmsys::SystemTools::GetFilenameLastExtension(*si); if (ext == ".qrc") { - qrcGenMap[*si] = this->TargetBuildSubDir + fpathCheckSum.getPart(*si) + + qrcGenMap[*si] = this->AutogenBuildSubDir + fpathCheckSum.getPart(*si) + "/qrc_" + cmsys::SystemTools::GetFilenameWithoutLastExtension(*si) + ".cpp"; } @@ -1379,7 +1397,7 @@ bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile, // file names but not for symbol names. std::replace(symbolName.begin(), symbolName.end(), '-', '_'); - const std::string qrcBuildFile = this->Builddir + qrcOutputFile; + const std::string qrcBuildFile = this->CurrentBinaryDir + qrcOutputFile; int sourceNewerThanQrc = 0; bool generateQrc = !cmsys::SystemTools::FileTimeCompare( diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 5fbaf87..c241579 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -102,41 +102,47 @@ private: bool InputFilesNewerThanQrc(const std::string& qrcFile, const std::string& rccOutput); + // - Target names + std::string OriginTargetName; + std::string AutogenTargetName; + // - Directories + std::string ProjectSourceDir; + std::string ProjectBinaryDir; + std::string CurrentSourceDir; + std::string CurrentBinaryDir; + std::string AutogenBuildSubDir; + // - Qt environment std::string QtMajorVersion; - std::string Sources; - std::vector RccSources; - std::string SkipMoc; - std::string SkipUic; - std::string Headers; - std::string Srcdir; - std::string Builddir; std::string MocExecutable; std::string UicExecutable; std::string RccExecutable; + // - File lists + std::string Sources; + std::string Headers; + // - Moc + std::string SkipMoc; std::string MocCompileDefinitionsStr; std::string MocIncludesStr; std::string MocOptionsStr; - std::string ProjectBinaryDir; - std::string ProjectSourceDir; - std::string TargetName; - std::string OriginTargetName; - - std::string CurrentCompileSettingsStr; - std::string OldCompileSettingsStr; - - std::string TargetBuildSubDir; std::string OutMocCppFilenameRel; std::string OutMocCppFilenameAbs; std::list MocIncludes; std::list MocDefinitions; std::vector MocOptions; + // - Uic + std::string SkipUic; std::vector UicTargetOptions; std::map UicOptions; + // - Rcc + std::vector RccSources; std::map RccOptions; std::map > RccInputs; - + // - Settings + std::string CurrentCompileSettingsStr; + std::string OldCompileSettingsStr; + // - Utility cmFilePathChecksum fpathCheckSum; - + // - Flags bool IncludeProjectDirsBefore; bool Verbose; bool ColorOutput; -- cgit v0.12 From 43d77e1dadab06f9b49ebb6cbfdaffcc4b708f1a Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Tue, 6 Dec 2016 17:33:10 +0100 Subject: QtAutogen: Don't use std::i/ofstream::is_open() --- Source/cmQtAutoGenerators.cxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 506c820..eb513e5 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -390,13 +390,14 @@ bool cmQtAutoGenerators::WriteOldMocDefinitionsFile( { cmsys::ofstream outfile; outfile.open(filename.c_str(), std::ios::trunc); - success = outfile.is_open(); - if (success) { + if (outfile) { outfile << "set(AM_OLD_COMPILE_SETTINGS " << cmOutputConverter::EscapeForCMake( this->CurrentCompileSettingsStr) << ")\n"; success = outfile.good(); + } else { + success = false; } } @@ -1116,7 +1117,7 @@ bool cmQtAutoGenerators::GenerateMocFiles( if (success) { cmsys::ofstream outfile; outfile.open(this->OutMocCppFilenameAbs.c_str(), std::ios::trunc); - if (!outfile.is_open()) { + if (!outfile) { success = false; std::ostringstream err; err << "AUTOGEN: error opening " << this->OutMocCppFilenameAbs << "\n"; -- cgit v0.12 From 6731025211bb300f762ac4d4984de124dc38c95a Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 2 Dec 2016 12:34:37 +0100 Subject: QtAutogen: Tests: Don't include CMAKE_CURRENT_BINARY_DIR --- Tests/QtAutogen/CMakeLists.txt | 1 - Tests/QtAutogen/complex/Bdir/CMakeLists.txt | 1 - Tests/QtAutogen/complex/CMakeLists.txt | 3 ++- Tests/QtAutogen/defines_test/CMakeLists.txt | 2 -- Tests/QtAutogen/sameName/CMakeLists.txt | 3 +-- 5 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Tests/QtAutogen/CMakeLists.txt b/Tests/QtAutogen/CMakeLists.txt index c4d0567..fdc766b 100644 --- a/Tests/QtAutogen/CMakeLists.txt +++ b/Tests/QtAutogen/CMakeLists.txt @@ -45,7 +45,6 @@ else() endif() get_property(QT_COMPILE_FEATURES TARGET ${QT_QTCORE_TARGET} PROPERTY INTERFACE_COMPILE_FEATURES) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) # -- Test: AUTORCC # RCC only diff --git a/Tests/QtAutogen/complex/Bdir/CMakeLists.txt b/Tests/QtAutogen/complex/Bdir/CMakeLists.txt index d9d4aa7..d338763 100644 --- a/Tests/QtAutogen/complex/Bdir/CMakeLists.txt +++ b/Tests/QtAutogen/complex/Bdir/CMakeLists.txt @@ -6,5 +6,4 @@ set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) add_library(libB SHARED libB.cpp) generate_export_header(libB) -# set_property(TARGET libB APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) target_link_libraries(libB LINK_PUBLIC libA) diff --git a/Tests/QtAutogen/complex/CMakeLists.txt b/Tests/QtAutogen/complex/CMakeLists.txt index 0d44f50..30d2708 100644 --- a/Tests/QtAutogen/complex/CMakeLists.txt +++ b/Tests/QtAutogen/complex/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 3.1) # -- Test: AUTOMOC AUTORCC AUTOUIC -include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_definitions(-DFOO -DSomeDefine="Barx") # enable relaxed mode so automoc can handle all the special cases: @@ -77,5 +76,7 @@ add_library(libC SHARED libC.cpp) set_target_properties(libC PROPERTIES AUTOMOC TRUE) generate_export_header(libC) target_link_libraries(libC LINK_PUBLIC libB) +target_include_directories(libC PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +set_property(TARGET libC APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR} ) target_link_libraries(QtAutogen codeeditorLib ${QT_LIBRARIES} libC) diff --git a/Tests/QtAutogen/defines_test/CMakeLists.txt b/Tests/QtAutogen/defines_test/CMakeLists.txt index ad4e684..9ee9a22 100644 --- a/Tests/QtAutogen/defines_test/CMakeLists.txt +++ b/Tests/QtAutogen/defines_test/CMakeLists.txt @@ -1,6 +1,4 @@ -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - add_executable(defines_test defines_test.cpp) set_target_properties(defines_test PROPERTIES AUTOMOC TRUE) target_link_libraries(defines_test Qt4::QtGui) diff --git a/Tests/QtAutogen/sameName/CMakeLists.txt b/Tests/QtAutogen/sameName/CMakeLists.txt index ed045fb..9e47a3e 100644 --- a/Tests/QtAutogen/sameName/CMakeLists.txt +++ b/Tests/QtAutogen/sameName/CMakeLists.txt @@ -16,6 +16,5 @@ add_executable(sameName data.qrc main.cpp ) -target_include_directories(sameName PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(sameName ${QT_LIBRARIES}) -set_target_properties( sameName PROPERTIES AUTOMOC TRUE AUTORCC TRUE ) +set_target_properties(sameName PROPERTIES AUTOMOC TRUE AUTORCC TRUE) -- cgit v0.12 From 6d0a8af3687c66f95d7f787402f7aa82c8fae73a Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 2 Dec 2016 12:51:15 +0100 Subject: QtAutogen: Tests: Don't use std::auto_ptr --- Tests/QtAutogen/uicOnlySource/uiconly.cpp | 5 +++++ Tests/QtAutogen/uicOnlySource/uiconly.h | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Tests/QtAutogen/uicOnlySource/uiconly.cpp b/Tests/QtAutogen/uicOnlySource/uiconly.cpp index ac22789..7b91b25 100644 --- a/Tests/QtAutogen/uicOnlySource/uiconly.cpp +++ b/Tests/QtAutogen/uicOnlySource/uiconly.cpp @@ -7,6 +7,11 @@ UicOnly::UicOnly(QWidget* parent) { } +UicOnly::~UicOnly() +{ + delete ui; +} + int main() { return 0; diff --git a/Tests/QtAutogen/uicOnlySource/uiconly.h b/Tests/QtAutogen/uicOnlySource/uiconly.h index 9b0b1b4..8f4eebe 100644 --- a/Tests/QtAutogen/uicOnlySource/uiconly.h +++ b/Tests/QtAutogen/uicOnlySource/uiconly.h @@ -3,7 +3,6 @@ #define UIC_ONLY_H #include -#include #include "ui_uiconly.h" @@ -12,9 +11,10 @@ class UicOnly : public QWidget Q_OBJECT public: explicit UicOnly(QWidget* parent = 0); + ~UicOnly(); private: - const std::auto_ptr ui; + Ui::UicOnly* ui; }; #endif -- cgit v0.12 From 5961db41436081f0ff936ba56a7053f51551afc1 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 5 Dec 2016 18:44:13 +0100 Subject: QtAutogen: Tests: Increase minimum required CMake version --- Tests/QtAutogen/CMakeLists.txt | 2 +- Tests/QtAutogen/automoc_rerun/CMakeLists.txt | 2 +- Tests/QtAutogen/autorcc_depends/CMakeLists.txt | 2 +- Tests/QtAutogen/complex/CMakeLists.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/QtAutogen/CMakeLists.txt b/Tests/QtAutogen/CMakeLists.txt index fdc766b..6d4e2c4 100644 --- a/Tests/QtAutogen/CMakeLists.txt +++ b/Tests/QtAutogen/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.7) project(QtAutogen) diff --git a/Tests/QtAutogen/automoc_rerun/CMakeLists.txt b/Tests/QtAutogen/automoc_rerun/CMakeLists.txt index 17bc332..92a682b 100644 --- a/Tests/QtAutogen/automoc_rerun/CMakeLists.txt +++ b/Tests/QtAutogen/automoc_rerun/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.7) project(automoc_rerun CXX) if (QT_TEST_VERSION STREQUAL 4) diff --git a/Tests/QtAutogen/autorcc_depends/CMakeLists.txt b/Tests/QtAutogen/autorcc_depends/CMakeLists.txt index fbe71ad..7b51e11 100644 --- a/Tests/QtAutogen/autorcc_depends/CMakeLists.txt +++ b/Tests/QtAutogen/autorcc_depends/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.7) project(autorcc_depends) set(CMAKE_AUTORCC ON) diff --git a/Tests/QtAutogen/complex/CMakeLists.txt b/Tests/QtAutogen/complex/CMakeLists.txt index 30d2708..d48f6cc 100644 --- a/Tests/QtAutogen/complex/CMakeLists.txt +++ b/Tests/QtAutogen/complex/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.7) # -- Test: AUTOMOC AUTORCC AUTOUIC add_definitions(-DFOO -DSomeDefine="Barx") -- cgit v0.12 From 2da0875f3a8cc91a8355298cc8da0a34f98acf09 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Tue, 6 Dec 2016 16:42:24 +0100 Subject: QtAutogen: Tests: Update ui_ include lookup directory --- Tests/QtAutoUicInterface/CMakeLists.txt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Tests/QtAutoUicInterface/CMakeLists.txt b/Tests/QtAutoUicInterface/CMakeLists.txt index 555f016..70175fb 100644 --- a/Tests/QtAutoUicInterface/CMakeLists.txt +++ b/Tests/QtAutoUicInterface/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.7) project(QtAutoUicInterface) @@ -21,7 +21,6 @@ else() endif() set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) -set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) @@ -65,6 +64,6 @@ target_link_libraries(MyWidget KI18n ${QT_GUI_TARGET}) add_executable(QtAutoUicInterface main.cpp) target_compile_definitions(QtAutoUicInterface PRIVATE - UI_LIBWIDGET_H="${CMAKE_CURRENT_BINARY_DIR}/ui_libwidget.h" - UI_MYWIDGET_H="${CMAKE_CURRENT_BINARY_DIR}/ui_mywidget.h" + UI_LIBWIDGET_H="${CMAKE_CURRENT_BINARY_DIR}/LibWidget_autogen/include/ui_libwidget.h" + UI_MYWIDGET_H="${CMAKE_CURRENT_BINARY_DIR}/MyWidget_autogen/include/ui_mywidget.h" ) -- cgit v0.12 From c2211703d35de8fc24e818680c033503b96167ff Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Tue, 6 Dec 2016 16:46:16 +0100 Subject: QtAutogen: Tests: Don't use std::auto_ptr --- Tests/QtAutoUicInterface/libwidget.cpp | 5 +++++ Tests/QtAutoUicInterface/libwidget.h | 3 ++- Tests/QtAutoUicInterface/mywidget.cpp | 5 +++++ Tests/QtAutoUicInterface/mywidget.h | 3 ++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Tests/QtAutoUicInterface/libwidget.cpp b/Tests/QtAutoUicInterface/libwidget.cpp index b25f3d7..008c22a 100644 --- a/Tests/QtAutoUicInterface/libwidget.cpp +++ b/Tests/QtAutoUicInterface/libwidget.cpp @@ -7,3 +7,8 @@ LibWidget::LibWidget(QWidget* parent) { ui->setupUi(this); } + +LibWidget::~LibWidget() +{ + delete ui; +} diff --git a/Tests/QtAutoUicInterface/libwidget.h b/Tests/QtAutoUicInterface/libwidget.h index a4400d2..b6f3e82 100644 --- a/Tests/QtAutoUicInterface/libwidget.h +++ b/Tests/QtAutoUicInterface/libwidget.h @@ -16,9 +16,10 @@ class LibWidget : public QWidget Q_OBJECT public: explicit LibWidget(QWidget* parent = 0); + ~LibWidget(); private: - const std::auto_ptr ui; + Ui::LibWidget* ui; }; #endif diff --git a/Tests/QtAutoUicInterface/mywidget.cpp b/Tests/QtAutoUicInterface/mywidget.cpp index 885165b..7cf1a13 100644 --- a/Tests/QtAutoUicInterface/mywidget.cpp +++ b/Tests/QtAutoUicInterface/mywidget.cpp @@ -7,3 +7,8 @@ MyWidget::MyWidget(QWidget* parent) { ui->setupUi(this); } + +MyWidget::~MyWidget() +{ + delete ui; +} diff --git a/Tests/QtAutoUicInterface/mywidget.h b/Tests/QtAutoUicInterface/mywidget.h index fc49e80..c23e55d 100644 --- a/Tests/QtAutoUicInterface/mywidget.h +++ b/Tests/QtAutoUicInterface/mywidget.h @@ -16,9 +16,10 @@ class MyWidget : public QWidget Q_OBJECT public: explicit MyWidget(QWidget* parent = 0); + ~MyWidget(); private: - const std::auto_ptr ui; + Ui::MyWidget* ui; }; #endif -- cgit v0.12 From e324d70409b8f56c0d870916f81d8b848233c4e1 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 2 Dec 2016 22:22:50 +0100 Subject: QtAutogen: AUTOMOC documentation update --- Help/prop_tgt/AUTOMOC.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Help/prop_tgt/AUTOMOC.rst b/Help/prop_tgt/AUTOMOC.rst index eea57e3..30a39b1 100644 --- a/Help/prop_tgt/AUTOMOC.rst +++ b/Help/prop_tgt/AUTOMOC.rst @@ -15,11 +15,12 @@ source files at build time and invoke moc accordingly. the ``Q_OBJECT`` class declaration is expected in the header, and ``moc`` is run on the header file. A ``moc_foo.cpp`` file will be generated from the source's header into the - :variable:`CMAKE_CURRENT_BINARY_DIR` directory. This allows the - compiler to find the included ``moc_foo.cpp`` file regardless of the - location the original source. However, if multiple source files - in different directories do this then their generated moc files would - collide. In this case a diagnostic will be issued. + ``/_autogen/include`` + directory which is automatically added to the target's + :prop_tgt:`INCLUDE_DIRECTORIES`. This allows the compiler to find the + included ``moc_foo.cpp`` file regardless of the location the original source. + However, if multiple source files in different directories do this then their + generated moc files would collide. In this case a diagnostic will be issued. * If an ``#include`` statement like ``#include "foo.moc"`` is found, then a ``Q_OBJECT`` is expected in the current source file and ``moc`` -- cgit v0.12 From e1f571a98371ec99467502234671fb52f8f6cce9 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 5 Dec 2016 18:25:30 +0100 Subject: QtAutogen: CMake-Qt documentation update --- Help/manual/cmake-qt.7.rst | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Help/manual/cmake-qt.7.rst b/Help/manual/cmake-qt.7.rst index 7827065..80b0f49 100644 --- a/Help/manual/cmake-qt.7.rst +++ b/Help/manual/cmake-qt.7.rst @@ -22,12 +22,11 @@ Qt 4 and Qt 5 may be used together in the same .. code-block:: cmake - cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) + cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR) project(Qt4And5) set(CMAKE_AUTOMOC ON) - set(CMAKE_INCLUDE_CURRENT_DIR ON) find_package(Qt5 COMPONENTS Widgets DBus REQUIRED) add_executable(publisher publisher.cpp) @@ -73,9 +72,12 @@ The ``moc`` command line will consume the :prop_tgt:`COMPILE_DEFINITIONS` and :prop_tgt:`INCLUDE_DIRECTORIES` target properties from the target it is being invoked for, and for the appropriate build configuration. -Generated ``moc_*.cpp`` and ``*.moc`` files are placed in the build directory -so it is convenient to set the :variable:`CMAKE_INCLUDE_CURRENT_DIR` -variable. The :prop_tgt:`AUTOMOC` target property may be pre-set for all +The generated ``moc_*.cpp`` and ``*.moc`` files are placed in the +``/_autogen/include`` directory which is +automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`. +(This differs from CMake 3.7 and below; see their documentation for details.) + +The :prop_tgt:`AUTOMOC` target property may be pre-set for all following targets by setting the :variable:`CMAKE_AUTOMOC` variable. The :prop_tgt:`AUTOMOC_MOC_OPTIONS` target property may be populated to set options to pass to ``moc``. The :variable:`CMAKE_AUTOMOC_MOC_OPTIONS` @@ -94,10 +96,13 @@ If a preprocessor ``#include`` directive is found which matches ``ui_.h``, and a ``.ui`` file exists, then ``uic`` will be executed to generate the appropriate file. -Generated ``ui_*.h`` files are placed in the build directory so it is -convenient to set the :variable:`CMAKE_INCLUDE_CURRENT_DIR` variable. The -:prop_tgt:`AUTOUIC` target property may be pre-set for all following targets -by setting the :variable:`CMAKE_AUTOUIC` variable. The +The generated generated ``ui_*.h`` files are placed in the +``/_autogen/include`` directory which is +automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`. +(This differs from CMake 3.7 and below; see their documentation for details.) + +The :prop_tgt:`AUTOUIC` target property may be pre-set for all following +targets by setting the :variable:`CMAKE_AUTOUIC` variable. The :prop_tgt:`AUTOUIC_OPTIONS` target property may be populated to set options to pass to ``uic``. The :variable:`CMAKE_AUTOUIC_OPTIONS` variable may be populated to pre-set the options for all following targets. The -- cgit v0.12 From c8a4147a34d38ec6a96c51e750f70f76a90ff1dc Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 2 Dec 2016 22:53:00 +0100 Subject: QtAutogen: Release notes for the Contain branch --- Help/release/dev/QtAutogen_Contain.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Help/release/dev/QtAutogen_Contain.rst diff --git a/Help/release/dev/QtAutogen_Contain.rst b/Help/release/dev/QtAutogen_Contain.rst new file mode 100644 index 0000000..182233b --- /dev/null +++ b/Help/release/dev/QtAutogen_Contain.rst @@ -0,0 +1,10 @@ +QtAutogen_Contain +----------------- + +* When using AUTOMOC or AUTOUIC, generated + ``moc_*``, ``*.moc`` and ``ui_*`` are placed in the + ``/_autogen/include`` directory which + is automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`. + It is therefore not necessary anymore to have + :variable:`CMAKE_CURRENT_BINARY_DIR` in the target's + :prop_tgt:`INCLUDE_DIRECTORIES`. -- cgit v0.12