diff options
author | Orkun Tokdemir <ilhanorkuntokdemir@gmail.com> | 2023-10-13 17:14:10 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-10-13 18:16:26 (GMT) |
commit | c074f5c81e04c032c976862a379297b8ba3bf3f8 (patch) | |
tree | e8b3727f0ad440b604dc343da8e4a8ed19446189 /Source/cmQtAutoGenInitializer.cxx | |
parent | 06a9b25b17759d754e2b542b8464f01a90e92a8e (diff) | |
download | CMake-c074f5c81e04c032c976862a379297b8ba3bf3f8.zip CMake-c074f5c81e04c032c976862a379297b8ba3bf3f8.tar.gz CMake-c074f5c81e04c032c976862a379297b8ba3bf3f8.tar.bz2 |
Autogen: Revert "AUTO*_EXECUTABLE: add support for per-config values"
Changing the `timestamp` file to `timestamp_$<CONFIG>` causes some user
projects to break when using Qt versions older than 6.6.
Revert commit fddd0f0443 (Autogen: AUTO*_EXECUTABLE: add support for
per-config values, 2023-06-14, v3.28.0-rc1~96^2~1) pending further
investigation.
Issue: #20074
Diffstat (limited to 'Source/cmQtAutoGenInitializer.cxx')
-rw-r--r-- | Source/cmQtAutoGenInitializer.cxx | 367 |
1 files changed, 107 insertions, 260 deletions
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index a33c5db..81752a6 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmQtAutoGenInitializer.h" -#include <array> #include <cstddef> #include <deque> #include <initializer_list> @@ -18,7 +17,6 @@ #include <cm/algorithm> #include <cm/iterator> #include <cm/memory> -#include <cm/string_view> #include <cmext/algorithm> #include <cmext/string_view> @@ -303,22 +301,15 @@ bool InfoWriter::Save(std::string const& filename) return fileStream.Close(); } -cmQtAutoGen::ConfigStrings<std::vector<std::string>> generateListOptions( - cmQtAutoGen::ConfigStrings<cmQtAutoGen::CompilerFeaturesHandle> const& - executableFeatures, - bool IsMultiConfig) +void AddAutogenExecutableToDependencies( + cmQtAutoGenInitializer::GenVarsT const& genVars, + std::vector<std::string>& dependencies) { - cmQtAutoGen::ConfigStrings<std::vector<std::string>> tempListOptions; - if (IsMultiConfig) { - for (auto const& executableFeature : executableFeatures.Config) { - tempListOptions.Config[executableFeature.first] = - executableFeature.second->ListOptions; - } - } else { - tempListOptions.Default = executableFeatures.Default->ListOptions; + if (genVars.ExecutableTarget != nullptr) { + dependencies.push_back(genVars.ExecutableTarget->Target->GetName()); + } else if (!genVars.Executable.empty()) { + dependencies.push_back(genVars.Executable); } - - return tempListOptions; } } // End of unnamed namespace @@ -345,34 +336,6 @@ cmQtAutoGenInitializer::cmQtAutoGenInitializer( !this->Makefile->GetSafeDefinition("CMAKE_CROSS_CONFIGS").empty(); } -void cmQtAutoGenInitializer::AddAutogenExecutableToDependencies( - cmQtAutoGenInitializer::GenVarsT const& genVars, - std::vector<std::string>& dependencies) const -{ - if (genVars.ExecutableTarget != nullptr) { - dependencies.push_back(genVars.ExecutableTarget->Target->GetName()); - } else if (this->MultiConfig) { - cm::string_view const& configGenexWithCommandConfig = - "$<COMMAND_CONFIG:$<$<CONFIG:"; - cm::string_view const& configGenex = "$<$<CONFIG:"; - cm::string_view const& configGenexEnd = ">"; - cm::string_view const& configGenexEndWithCommandConfig = ">>"; - auto genexBegin = - this->CrossConfig ? configGenexWithCommandConfig : configGenex; - auto genexEnd = - this->CrossConfig ? configGenexEndWithCommandConfig : configGenexEnd; - for (auto const& config : genVars.Executable.Config) { - auto executableWithConfig = - cmStrCat(genexBegin, config.first, ">:", config.second, genexEnd); - dependencies.emplace_back(std::move(executableWithConfig)); - } - } else { - if (!genVars.Executable.Default.empty()) { - dependencies.push_back(genVars.Executable.Default); - } - } -} - bool cmQtAutoGenInitializer::InitCustomTargets() { // Configurations @@ -816,30 +779,18 @@ bool cmQtAutoGenInitializer::InitRcc() return false; } // Evaluate test output on demand - auto& features = this->Rcc.ExecutableFeatures; - auto checkAndAddOptions = [this](CompilerFeaturesHandle& feature) { - if (!feature->Evaluated) { - // Look for list options - if (this->QtVersion.Major == 5 || this->QtVersion.Major == 6) { - static std::array<std::string, 2> const listOptions{ { "--list", - "-list" } }; - for (std::string const& opt : listOptions) { - if (feature->HelpOutput.find(opt) != std::string::npos) { - feature->ListOptions.emplace_back(opt); - break; - } - } + CompilerFeatures& features = *this->Rcc.ExecutableFeatures; + if (!features.Evaluated) { + // Look for list options + if (this->QtVersion.Major == 5 || this->QtVersion.Major == 6) { + if (features.HelpOutput.find("--list") != std::string::npos) { + features.ListOptions.emplace_back("--list"); + } else if (features.HelpOutput.find("-list") != std::string::npos) { + features.ListOptions.emplace_back("-list"); } - // Evaluation finished - feature->Evaluated = true; - } - }; - if (this->MultiConfig) { - for (auto const& config : this->ConfigsList) { - checkAndAddOptions(features.Config[config]); } - } else { - checkAndAddOptions(features.Default); + // Evaluation finished + features.Evaluated = true; } } @@ -1175,13 +1126,8 @@ bool cmQtAutoGenInitializer::InitScanFiles() // Path checksum qrc.QrcPathChecksum = this->PathCheckSum.getPart(qrc.QrcFile); // Output file name - if (this->MultiConfig && !this->GlobalGen->IsXcode()) { - qrc.OutputFile = cmStrCat(this->Dir.Build, '/', qrc.QrcPathChecksum, - "_$<CONFIG>", "/qrc_", qrc.QrcName, ".cpp"); - } else { - qrc.OutputFile = cmStrCat(this->Dir.Build, '/', qrc.QrcPathChecksum, - "/qrc_", qrc.QrcName, ".cpp"); - } + qrc.OutputFile = cmStrCat(this->Dir.Build, '/', qrc.QrcPathChecksum, + "/qrc_", qrc.QrcName, ".cpp"); std::string const base = cmStrCat(this->Dir.Info, "/AutoRcc_", qrc.QrcName, '_', qrc.QrcPathChecksum); qrc.LockFile = cmStrCat(base, "_Lock.lock"); @@ -1213,25 +1159,11 @@ bool cmQtAutoGenInitializer::InitScanFiles() for (Qrc& qrc : this->Rcc.Qrcs) { if (!qrc.Generated) { std::string error; - if (this->MultiConfig) { - for (auto const& config : this->ConfigsList) { - RccLister const lister( - this->Rcc.Executable.Config[config], - this->Rcc.ExecutableFeatures.Config[config]->ListOptions); - if (!lister.list(qrc.QrcFile, qrc.Resources.Config[config], - error)) { - cmSystemTools::Error(error); - return false; - } - } - } else { - RccLister const lister( - this->Rcc.Executable.Default, - this->Rcc.ExecutableFeatures.Default->ListOptions); - if (!lister.list(qrc.QrcFile, qrc.Resources.Default, error)) { - cmSystemTools::Error(error); - return false; - } + RccLister const lister(this->Rcc.Executable, + this->Rcc.ExecutableFeatures->ListOptions); + if (!lister.list(qrc.QrcFile, qrc.Resources, error)) { + cmSystemTools::Error(error); + return false; } } } @@ -1259,7 +1191,18 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() if (this->Moc.Enabled) { this->AddGeneratedSource(this->Moc.CompilationFile, this->Moc, true); if (useDepfile) { - timestampByproducts.push_back(this->Moc.CompilationFileGenex); + if (this->MultiConfig && this->CrossConfig && + this->GlobalGen->GetName().find("Ninja") != std::string::npos) { + // Make all mocs_compilation_<CONFIG>.cpp files byproducts of the + // ${target}_autogen/timestamp custom command. + // We cannot just use Moc.CompilationFileGenex here, because that + // custom command runs cmake_autogen for each configuration. + for (const auto& p : this->Moc.CompilationFile.Config) { + timestampByproducts.push_back(p.second); + } + } else { + timestampByproducts.push_back(this->Moc.CompilationFileGenex); + } } else { autogenByproducts.push_back(this->Moc.CompilationFileGenex); } @@ -1292,11 +1235,28 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() // Compose command lines // FIXME: Take advantage of our per-config mocs_compilation_$<CONFIG>.cpp // instead of fiddling with the include directories - + std::vector<std::string> configs; + this->GlobalGen->GetQtAutoGenConfigs(configs); bool constexpr stdPipesUTF8 = true; cmCustomCommandLines commandLines; - AddCMakeProcessToCommandLines(this->AutogenTarget.InfoFile, "cmake_autogen", - commandLines); + if (!this->CrossConfig) { + std::string autogenInfoFileConfig; + if (this->MultiConfig) { + autogenInfoFileConfig = "$<CONFIG>"; + } else { + autogenInfoFileConfig = configs[0]; + } + commandLines.push_back(cmMakeCommandLine( + { cmSystemTools::GetCMakeCommand(), "-E", "cmake_autogen", + this->AutogenTarget.InfoFile, autogenInfoFileConfig })); + + } else { + for (auto const& config : configs) { + commandLines.push_back(cmMakeCommandLine( + { cmSystemTools::GetCMakeCommand(), "-E", "cmake_autogen", + this->AutogenTarget.InfoFile, config })); + } + } // Use PRE_BUILD on demand bool usePRE_BUILD = false; @@ -1464,47 +1424,18 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() AddAutogenExecutableToDependencies(this->Moc, dependencies); AddAutogenExecutableToDependencies(this->Uic, dependencies); - std::string outputFile; - std::string depFile; + // Create the custom command that outputs the timestamp file. - if (this->MultiConfig) { - // create timestamp file with $<CONFIG> in the name so that - // every cmake_autogen target has its own timestamp file - std::string const configView = "$<CONFIG>"; - std::string const timestampFileWithoutConfig = "timestamp_"; - std::string const depFileWithoutConfig = - cmStrCat(this->Dir.Build, "/deps_"); - std::string const timestampFileName = - timestampFileWithoutConfig + configView; - outputFile = cmStrCat(this->Dir.Build, "/", timestampFileName); - auto const depFileWithConfig = - cmStrCat(depFileWithoutConfig, configView); - depFile = depFileWithConfig; - commandLines.push_back(cmMakeCommandLine( - { cmSystemTools::GetCMakeCommand(), "-E", "touch", outputFile })); - - ConfigString outputFileWithConfig; - for (std::string const& config : this->ConfigsList) { - auto tempTimestampFileName = timestampFileWithoutConfig + config; - auto tempDepFile = depFileWithoutConfig + config; - outputFileWithConfig.Config[config] = tempTimestampFileName; - this->AutogenTarget.DepFileRuleName.Config[config] = - cmStrCat(this->Dir.RelativeBuild, "/", tempTimestampFileName); - this->AutogenTarget.DepFile.Config[config] = tempDepFile; - } - this->AddGeneratedSource(outputFileWithConfig, this->Moc); - } else { - cm::string_view const timestampFileName = "timestamp"; - outputFile = cmStrCat(this->Dir.Build, "/", timestampFileName); - this->AutogenTarget.DepFile.Default = - cmStrCat(this->Dir.Build, "/deps"); - depFile = this->AutogenTarget.DepFile.Default; - this->AutogenTarget.DepFileRuleName.Default = - cmStrCat(this->Dir.RelativeBuild, "/", timestampFileName); - commandLines.push_back(cmMakeCommandLine( - { cmSystemTools::GetCMakeCommand(), "-E", "touch", outputFile })); - this->AddGeneratedSource(outputFile, this->Moc); - } + const char timestampFileName[] = "timestamp"; + const std::string outputFile = + cmStrCat(this->Dir.Build, "/", timestampFileName); + this->AutogenTarget.DepFile = cmStrCat(this->Dir.Build, "/deps"); + this->AutogenTarget.DepFileRuleName = + cmStrCat(this->Dir.RelativeBuild, "/", timestampFileName); + commandLines.push_back(cmMakeCommandLine( + { cmSystemTools::GetCMakeCommand(), "-E", "touch", outputFile })); + + this->AddGeneratedSource(outputFile, this->Moc); cc = cm::make_unique<cmCustomCommand>(); cc->SetOutputs(outputFile); cc->SetByproducts(timestampByproducts); @@ -1513,11 +1444,14 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() cc->SetComment(autogenComment.c_str()); cc->SetWorkingDirectory(this->Dir.Work.c_str()); cc->SetEscapeOldStyle(false); - cc->SetDepfile(depFile); + cc->SetDepfile(this->AutogenTarget.DepFile); cc->SetStdPipesUTF8(stdPipesUTF8); this->LocalGen->AddCustomCommandToOutput(std::move(cc)); + + // Alter variables for the autogen target which now merely wraps the + // custom command dependencies.clear(); - dependencies.emplace_back(std::move(outputFile)); + dependencies.emplace_back(outputFile); commandLines.clear(); autogenComment.clear(); } @@ -1569,35 +1503,6 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() return true; } -void cmQtAutoGenInitializer::AddCMakeProcessToCommandLines( - std::string const& infoFile, std::string const& processName, - cmCustomCommandLines& commandLines) -{ - if (this->CrossConfig) { - commandLines.push_back(cmMakeCommandLine( - { cmSystemTools::GetCMakeCommand(), "-E", processName, infoFile, - "$<CONFIG>", "$<COMMAND_CONFIG:$<CONFIG>>" })); - } else if (this->MultiConfig && this->GlobalGen->IsXcode()) { - for (std::string const& config : this->ConfigsList) { - commandLines.push_back( - cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E", - processName, infoFile, config })); - } - } else { - std::string autoInfoFileConfig; - if (this->MultiConfig) { - autoInfoFileConfig = "$<CONFIG>"; - } else { - std::vector<std::string> configs; - this->GlobalGen->GetQtAutoGenConfigs(configs); - autoInfoFileConfig = configs[0]; - } - commandLines.push_back( - cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E", processName, - infoFile, autoInfoFileConfig })); - } -} - bool cmQtAutoGenInitializer::InitRccTargets() { for (Qrc const& qrc : this->Rcc.Qrcs) { @@ -1618,7 +1523,18 @@ bool cmQtAutoGenInitializer::InitRccTargets() ccDepends.push_back(qrc.InfoFile); cmCustomCommandLines commandLines; - AddCMakeProcessToCommandLines(qrc.InfoFile, "cmake_autorcc", commandLines); + if (this->MultiConfig) { + // Build for all configurations + for (std::string const& config : this->ConfigsList) { + commandLines.push_back( + cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E", + "cmake_autorcc", qrc.InfoFile, config })); + } + } else { + commandLines.push_back( + cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E", + "cmake_autorcc", qrc.InfoFile, "$<CONFIG>" })); + } std::string const ccComment = cmStrCat("Automatic RCC for ", @@ -1669,28 +1585,13 @@ bool cmQtAutoGenInitializer::InitRccTargets() // Create custom rcc command { // Add the resource files to the dependencies - if (this->MultiConfig) { - for (auto const& config : this->ConfigsList) { - // Add resource file to the custom command dependencies - auto resourceFilesWithConfig = cmStrCat( - "$<$<CONFIG:", config, - ">:", cmList{ qrc.Resources.Config.at(config) }.to_string(), - ">"); - ccDepends.emplace_back(std::move(resourceFilesWithConfig)); - } - } else { - for (std::string const& fileName : qrc.Resources.Default) { - // Add resource file to the custom command dependencies - ccDepends.push_back(fileName); - } + for (std::string const& fileName : qrc.Resources) { + // Add resource file to the custom command dependencies + ccDepends.push_back(fileName); } - if (!this->Rcc.ExecutableTargetName.empty()) { ccDepends.push_back(this->Rcc.ExecutableTargetName); } - - AddAutogenExecutableToDependencies(this->Rcc, ccDepends); - cc->SetOutputs(ccOutput); cc->SetDepends(ccDepends); this->LocalGen->AddCustomCommandToOutput(std::move(cc)); @@ -1790,7 +1691,6 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo() // General info.SetBool("MULTI_CONFIG", this->MultiConfig); - info.SetBool("CROSS_CONFIG", this->CrossConfig); info.SetUInt("PARALLEL", this->AutogenTarget.Parallel); info.SetUInt("VERBOSITY", this->Verbosity); @@ -1804,14 +1704,14 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo() info.SetUInt("QT_VERSION_MAJOR", this->QtVersion.Major); info.SetUInt("QT_VERSION_MINOR", this->QtVersion.Minor); - info.SetConfig("QT_MOC_EXECUTABLE", this->Moc.Executable); - info.SetConfig("QT_UIC_EXECUTABLE", this->Uic.Executable); + info.Set("QT_MOC_EXECUTABLE", this->Moc.Executable); + info.Set("QT_UIC_EXECUTABLE", this->Uic.Executable); info.Set("CMAKE_EXECUTABLE", cmSystemTools::GetCMakeCommand()); info.SetConfig("SETTINGS_FILE", this->AutogenTarget.SettingsFile); info.SetConfig("PARSE_CACHE_FILE", this->AutogenTarget.ParseCacheFile); - info.SetConfig("DEP_FILE", this->AutogenTarget.DepFile); - info.SetConfig("DEP_FILE_RULE_NAME", this->AutogenTarget.DepFileRuleName); + info.Set("DEP_FILE", this->AutogenTarget.DepFile); + info.Set("DEP_FILE_RULE_NAME", this->AutogenTarget.DepFileRuleName); info.SetArray("CMAKE_LIST_FILES", this->Makefile->GetListFiles()); info.SetArray("HEADER_EXTENSIONS", this->Makefile->GetCMakeInstance()->GetHeaderExtensions()); @@ -1938,7 +1838,6 @@ bool cmQtAutoGenInitializer::SetupWriteRccInfo() // General info.SetBool("MULTI_CONFIG", this->MultiConfig); - info.SetBool("CROSS_CONFIG", this->CrossConfig); info.SetUInt("VERBOSITY", this->Verbosity); info.Set("GENERATOR", this->GlobalGen->GetName()); @@ -1955,17 +1854,16 @@ bool cmQtAutoGenInitializer::SetupWriteRccInfo() info.SetConfig("INCLUDE_DIR", this->Dir.Include); // rcc executable - info.SetConfig("RCC_EXECUTABLE", this->Rcc.Executable); - info.SetConfigArray( - "RCC_LIST_OPTIONS", - generateListOptions(this->Rcc.ExecutableFeatures, this->MultiConfig)); + info.Set("RCC_EXECUTABLE", this->Rcc.Executable); + info.SetArray("RCC_LIST_OPTIONS", + this->Rcc.ExecutableFeatures->ListOptions); // qrc file info.Set("SOURCE", qrc.QrcFile); info.Set("OUTPUT_CHECKSUM", qrc.QrcPathChecksum); info.Set("OUTPUT_NAME", cmSystemTools::GetFilenameName(qrc.OutputFile)); info.SetArray("OPTIONS", qrc.Options); - info.SetConfigArray("INPUTS", qrc.Resources); + info.SetArray("INPUTS", qrc.Resources); info.Save(qrc.InfoFile); } @@ -2309,32 +2207,16 @@ bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars, cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); cmGeneratorExpression ge(*this->Makefile->GetCMakeInstance(), lfbt); std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(val); - if (this->MultiConfig) { - for (auto const& config : this->ConfigsList) { - genVars.Executable.Config[config] = - cge->Evaluate(this->LocalGen, config); - } - } else { - genVars.Executable.Default = cge->Evaluate(this->LocalGen, ""); - } + genVars.Executable = cge->Evaluate(this->LocalGen, ""); } - - if (genVars.Executable.Default.empty() && - genVars.Executable.Config.empty() && !ignoreMissingTarget) { + if (genVars.Executable.empty() && !ignoreMissingTarget) { print_err(prop + " evaluates to an empty value"); return false; } // Create empty compiler features. - if (this->MultiConfig) { - for (auto const& config : this->ConfigsList) { - genVars.ExecutableFeatures.Config[config] = - std::make_shared<cmQtAutoGen::CompilerFeatures>(); - } - } else { - genVars.ExecutableFeatures.Default = - std::make_shared<cmQtAutoGen::CompilerFeatures>(); - } + genVars.ExecutableFeatures = + std::make_shared<cmQtAutoGen::CompilerFeatures>(); return true; } } @@ -2359,39 +2241,15 @@ bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars, genVars.ExecutableTargetName = targetName; genVars.ExecutableTarget = genTarget; if (genTarget->IsImported()) { - if (this->MultiConfig) { - for (auto const& config : this->ConfigsList) { - genVars.Executable.Config[config] = - genTarget->ImportedGetLocation(config); - } - } else { - genVars.Executable.Default = - genTarget->ImportedGetLocation(this->ConfigDefault); - } - + genVars.Executable = genTarget->ImportedGetLocation(""); } else { - if (this->MultiConfig) { - for (auto const& config : this->ConfigsList) { - genVars.Executable.Config[config] = genTarget->GetLocation(config); - } - } else { - genVars.Executable.Default = - genTarget->GetLocation(this->ConfigDefault); - } + genVars.Executable = genTarget->GetLocation(""); } } else { if (ignoreMissingTarget) { // Create empty compiler features. - if (this->MultiConfig) { - for (auto const& config : this->ConfigsList) { - genVars.ExecutableFeatures.Config[config] = - std::make_shared<cmQtAutoGen::CompilerFeatures>(); - } - } else { - genVars.ExecutableFeatures.Default = - std::make_shared<cmQtAutoGen::CompilerFeatures>(); - } - + genVars.ExecutableFeatures = + std::make_shared<cmQtAutoGen::CompilerFeatures>(); return true; } print_err(cmStrCat("Could not find ", executable, " executable target ", @@ -2404,21 +2262,10 @@ bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars, { std::string err; genVars.ExecutableFeatures = this->GlobalInitializer->GetCompilerFeatures( - executable, genVars.Executable, err, this->MultiConfig); - if (this->MultiConfig) { - for (auto const& config : this->ConfigsList) { - if (!genVars.ExecutableFeatures.Config[config]) { - if (!genVars.ExecutableFeatures.Config[config]) { - print_err(err); - return false; - } - } - } - } else { - if (!genVars.ExecutableFeatures.Default) { - print_err(err); - return false; - } + executable, genVars.Executable, err); + if (!genVars.ExecutableFeatures) { + print_err(err); + return false; } } |