diff options
author | Juan Ramos <juan.ramos@kitware.com> | 2024-05-28 03:19:05 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-07-01 16:02:49 (GMT) |
commit | 197cb419d13d5dbb704be97bd3ee04ce514fa58f (patch) | |
tree | 7fae6062e544659541c9dd97946ada61fe1c7310 /Source | |
parent | 033713530a077893be93e52ef577205cb8466b9d (diff) | |
download | CMake-197cb419d13d5dbb704be97bd3ee04ce514fa58f.zip CMake-197cb419d13d5dbb704be97bd3ee04ce514fa58f.tar.gz CMake-197cb419d13d5dbb704be97bd3ee04ce514fa58f.tar.bz2 |
add_custom_command: Add CODEGEN support
By specifying CODEGEN as an argument to add_custom_command the
custom command will be added to a codegen build target.
The intent is to provide a convenient way for users to get
their generated files without having to build the whole project.
This can be helpful for code analysis tools which can be useful
for IDEs and CI.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmAddCustomCommandCommand.cxx | 30 | ||||
-rw-r--r-- | Source/cmAddDependenciesCommand.cxx | 1 | ||||
-rw-r--r-- | Source/cmCustomCommand.h | 5 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 49 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 5 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 86 | ||||
-rw-r--r-- | Source/cmGlobalUnixMakefileGenerator3.cxx | 39 | ||||
-rw-r--r-- | Source/cmGlobalUnixMakefileGenerator3.h | 3 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 6 | ||||
-rw-r--r-- | Source/cmLocalUnixMakefileGenerator3.cxx | 15 | ||||
-rw-r--r-- | Source/cmMakefileTargetGenerator.cxx | 29 | ||||
-rw-r--r-- | Source/cmPolicies.h | 4 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 11 | ||||
-rw-r--r-- | Source/cmTarget.h | 5 | ||||
-rw-r--r-- | Source/cmTargetTraceDependencies.cxx | 11 |
15 files changed, 297 insertions, 2 deletions
diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index d943011..d5adba7 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -53,6 +53,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, bool command_expand_lists = false; bool depends_explicit_only = mf.IsOn("CMAKE_ADD_CUSTOM_COMMAND_DEPENDS_EXPLICIT_ONLY"); + bool codegen = false; std::string implicit_depends_lang; cmImplicitDependsList implicit_depends; @@ -111,6 +112,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, MAKE_STATIC_KEYWORD(VERBATIM); MAKE_STATIC_KEYWORD(WORKING_DIRECTORY); MAKE_STATIC_KEYWORD(DEPENDS_EXPLICIT_ONLY); + MAKE_STATIC_KEYWORD(CODEGEN); #undef MAKE_STATIC_KEYWORD static std::unordered_set<std::string> const keywords{ keyAPPEND, @@ -135,7 +137,8 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, keyUSES_TERMINAL, keyVERBATIM, keyWORKING_DIRECTORY, - keyDEPENDS_EXPLICIT_ONLY + keyDEPENDS_EXPLICIT_ONLY, + keyCODEGEN }; for (std::string const& copy : args) { @@ -166,6 +169,8 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, command_expand_lists = true; } else if (copy == keyDEPENDS_EXPLICIT_ONLY) { depends_explicit_only = true; + } else if (copy == keyCODEGEN) { + codegen = true; } else if (copy == keyTARGET) { doing = doing_target; } else if (copy == keyARGS) { @@ -322,6 +327,28 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, return false; } + if (codegen) { + if (output.empty()) { + status.SetError("CODEGEN requires at least 1 OUTPUT."); + return false; + } + + if (append) { + status.SetError("CODEGEN may not be used with APPEND."); + return false; + } + + if (!implicit_depends.empty()) { + status.SetError("CODEGEN is not compatible with IMPLICIT_DEPENDS."); + return false; + } + + if (mf.GetPolicyStatus(cmPolicies::CMP0171) != cmPolicies::NEW) { + status.SetError("CODEGEN option requires policy CMP0171 be set to NEW!"); + return false; + } + } + // Check for an append request. if (append) { mf.AppendCustomCommandToOutput(output[0], depends, implicit_depends, @@ -355,6 +382,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, cc->SetOutputs(output); cc->SetMainDependency(main_dependency); cc->SetDepends(depends); + cc->SetCodegen(codegen); cc->SetImplicitDepends(implicit_depends); mf.AddCustomCommandToOutput(std::move(cc)); } else { diff --git a/Source/cmAddDependenciesCommand.cxx b/Source/cmAddDependenciesCommand.cxx index 2d55a5a..aa04018 100644 --- a/Source/cmAddDependenciesCommand.cxx +++ b/Source/cmAddDependenciesCommand.cxx @@ -30,6 +30,7 @@ bool cmAddDependenciesCommand(std::vector<std::string> const& args, // skip over target_name for (std::string const& arg : cmMakeRange(args).advance(1)) { target->AddUtility(arg, false, &mf); + target->AddCodegenDependency(arg); } } else { mf.IssueMessage( diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h index 167e601..6f63d0a 100644 --- a/Source/cmCustomCommand.h +++ b/Source/cmCustomCommand.h @@ -132,6 +132,10 @@ public: const std::string& GetTarget() const; void SetTarget(const std::string& target); + /** Record if the custom command can be used for code generation. */ + bool GetCodegen() const { return Codegen; } + void SetCodegen(bool b) { Codegen = b; } + private: std::vector<std::string> Outputs; std::vector<std::string> Byproducts; @@ -153,6 +157,7 @@ private: bool StdPipesUTF8 = false; bool HasMainDependency_ = false; bool DependsExplicitOnly = false; + bool Codegen = false; // Policies are NEW for synthesized custom commands, and set by cmMakefile for // user-created custom commands. diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 019271b..bf2f0fc 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1398,6 +1398,8 @@ void cmGlobalGenerator::Configure() } } + this->ReserveGlobalTargetCodegen(); + // update the cache entry for the number of local generators, this is used // for progress this->GetCMakeInstance()->AddCacheEntry( @@ -2914,6 +2916,53 @@ void cmGlobalGenerator::AddGlobalTarget_Test( targets.push_back(std::move(gti)); } +void cmGlobalGenerator::ReserveGlobalTargetCodegen() +{ + // Read the policy value at the end of the top-level CMakeLists.txt file + // since it's a global policy that affects the whole project. + auto& mf = this->Makefiles[0]; + const auto policyStatus = mf->GetPolicyStatus(cmPolicies::CMP0171); + + this->AllowGlobalTargetCodegen = (policyStatus == cmPolicies::NEW); + + cmTarget* tgt = this->FindTarget("codegen"); + if (!tgt) { + return; + } + + MessageType messageType = MessageType::AUTHOR_WARNING; + std::ostringstream e; + bool issueMessage = false; + switch (policyStatus) { + case cmPolicies::WARN: + e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0171) << "\n"; + issueMessage = true; + CM_FALLTHROUGH; + case cmPolicies::OLD: + break; + case cmPolicies::NEW: + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + issueMessage = true; + messageType = MessageType::FATAL_ERROR; + break; + } + if (issueMessage) { + e << "The target name \"codegen\" is reserved."; + this->GetCMakeInstance()->IssueMessage(messageType, e.str(), + tgt->GetBacktrace()); + if (messageType == MessageType::FATAL_ERROR) { + cmSystemTools::SetFatalErrorOccurred(); + return; + } + } +} + +bool cmGlobalGenerator::CheckCMP0171() const +{ + return this->AllowGlobalTargetCodegen; +} + void cmGlobalGenerator::AddGlobalTarget_EditCache( std::vector<GlobalTargetInfo>& targets) const { diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 1ca02d9..33c9889 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -653,6 +653,8 @@ public: virtual std::string& EncodeLiteral(std::string& lit) { return lit; } + bool CheckCMP0171() const; + protected: // for a project collect all its targets by following depend // information, and also collect all the targets @@ -719,6 +721,8 @@ protected: void AddGlobalTarget_Install(std::vector<GlobalTargetInfo>& targets); void CreateGlobalTarget(GlobalTargetInfo const& gti, cmMakefile* mf); + void ReserveGlobalTargetCodegen(); + std::string FindMakeProgramFile; std::string ConfiguredFilesPath; cmake* CMakeInstance; @@ -891,4 +895,5 @@ protected: bool ToolSupportsColor; bool InstallTargetEnabled; bool ConfigureDoneCMP0026AndCMP0024; + bool AllowGlobalTargetCodegen; }; diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 96c8f25..7d62fa8 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -25,6 +25,7 @@ #include "cmsys/FStream.hxx" +#include "cmCustomCommand.h" #include "cmCxxModuleMapper.h" #include "cmDyndepCollation.h" #include "cmFortranParser.h" @@ -43,6 +44,7 @@ #include "cmOutputConverter.h" #include "cmRange.h" #include "cmScanDepFormat.h" +#include "cmSourceFile.h" #include "cmState.h" #include "cmStateDirectory.h" #include "cmStateSnapshot.h" @@ -1627,6 +1629,90 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os) std::map<std::string, DirectoryTarget> dirTargets = this->ComputeDirectoryTargets(); + // Codegen target + if (this->CheckCMP0171()) { + for (auto const& it : dirTargets) { + cmNinjaBuild build("phony"); + cmGlobalNinjaGenerator::WriteDivider(os); + std::string const& currentBinaryDir = it.first; + DirectoryTarget const& dt = it.second; + std::vector<std::string> configs = + dt.LG->GetMakefile()->GetGeneratorConfigs( + cmMakefile::IncludeEmptyConfig); + + // Setup target + cmNinjaDeps configDeps; + build.Comment = cmStrCat("Folder: ", currentBinaryDir); + build.Outputs.emplace_back(); + std::string const buildDirAllTarget = + this->ConvertToNinjaPath(cmStrCat(currentBinaryDir, "/codegen")); + + cmNinjaDeps& explicitDeps = build.ExplicitDeps; + + for (auto const& config : configs) { + explicitDeps.clear(); + + for (DirectoryTarget::Target const& t : dt.Targets) { + if (this->IsExcludedFromAllInConfig(t, config)) { + continue; + } + + std::vector<cmSourceFile const*> customCommandSources; + t.GT->GetCustomCommands(customCommandSources, config); + for (cmSourceFile const* sf : customCommandSources) { + cmCustomCommand const* cc = sf->GetCustomCommand(); + if (cc->GetCodegen()) { + auto const& outputs = cc->GetOutputs(); + + std::transform(outputs.begin(), outputs.end(), + std::back_inserter(explicitDeps), + this->MapToNinjaPath()); + } + } + } + + build.Outputs.front() = this->BuildAlias(buildDirAllTarget, config); + // Write target + this->WriteBuild(this->EnableCrossConfigBuild() && + this->CrossConfigs.count(config) + ? os + : *this->GetImplFileStream(config), + build); + } + + // Add shortcut target + if (this->IsMultiConfig()) { + for (auto const& config : configs) { + build.ExplicitDeps = { this->BuildAlias(buildDirAllTarget, config) }; + build.Outputs.front() = buildDirAllTarget; + this->WriteBuild(*this->GetConfigFileStream(config), build); + } + + if (!this->DefaultFileConfig.empty()) { + build.ExplicitDeps.clear(); + for (auto const& config : this->DefaultConfigs) { + build.ExplicitDeps.push_back( + this->BuildAlias(buildDirAllTarget, config)); + } + build.Outputs.front() = buildDirAllTarget; + this->WriteBuild(*this->GetDefaultFileStream(), build); + } + } + + // Add target for all configs + if (this->EnableCrossConfigBuild()) { + build.ExplicitDeps.clear(); + for (auto const& config : this->CrossConfigs) { + build.ExplicitDeps.push_back( + this->BuildAlias(buildDirAllTarget, config)); + } + build.Outputs.front() = this->BuildAlias(buildDirAllTarget, "codegen"); + this->WriteBuild(os, build); + } + } + } + + // All target for (auto const& it : dirTargets) { cmNinjaBuild build("phony"); cmGlobalNinjaGenerator::WriteDivider(os); diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 56748a5..38cc4f6 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -23,6 +23,7 @@ #include "cmStateTypes.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" +#include "cmTarget.h" #include "cmTargetDepend.h" #include "cmValue.h" #include "cmake.h" @@ -438,6 +439,10 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRules2( // Write directory-level rules for "all". this->WriteDirectoryRule2(ruleFileStream, rootLG, dt, "all", true, false); + // Write directory-level rules for "codegen". + this->WriteDirectoryRule2(ruleFileStream, rootLG, dt, "codegen", true, + false); + // Write directory-level rules for "preinstall". this->WriteDirectoryRule2(ruleFileStream, rootLG, dt, "preinstall", true, true); @@ -765,6 +770,17 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2( depends, commands, true); } + // add the codegen rule + localName = lg.GetRelativeTargetDirectory(gtarget.get()); + depends.clear(); + commands.clear(); + makeTargetName = cmStrCat(localName, "/codegen"); + commands.push_back( + lg.GetRecursiveMakeCall(makefileName, makeTargetName)); + this->AppendCodegenTargetDepends(depends, gtarget.get()); + rootLG.WriteMakeRule(ruleFileStream, "codegen rule for target.", + makeTargetName, depends, commands, true); + // add the clean rule localName = lg.GetRelativeTargetDirectory(gtarget.get()); makeTargetName = cmStrCat(localName, "/clean"); @@ -893,6 +909,29 @@ void cmGlobalUnixMakefileGenerator3::AppendGlobalTargetDepends( } } +void cmGlobalUnixMakefileGenerator3::AppendCodegenTargetDepends( + std::vector<std::string>& depends, cmGeneratorTarget* target) +{ + const std::set<std::string>& codegen_depends = + target->Target->GetCodegenDeps(); + + for (cmTargetDepend const& i : this->GetTargetDirectDepends(target)) { + // Create the target-level dependency. + cmGeneratorTarget const* dep = i; + if (!dep->IsInBuildSystem()) { + continue; + } + if (codegen_depends.find(dep->GetName()) != codegen_depends.end()) { + cmLocalUnixMakefileGenerator3* lg3 = + static_cast<cmLocalUnixMakefileGenerator3*>(dep->GetLocalGenerator()); + std::string tgtName = cmStrCat( + lg3->GetRelativeTargetDirectory(const_cast<cmGeneratorTarget*>(dep)), + "/all"); + depends.push_back(tgtName); + } + } +} + void cmGlobalUnixMakefileGenerator3::WriteHelpRule( std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3* lg) { diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index ee78351..d4fcf88 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -223,6 +223,9 @@ protected: void AppendGlobalTargetDepends(std::vector<std::string>& depends, cmGeneratorTarget* target); + void AppendCodegenTargetDepends(std::vector<std::string>& depends, + cmGeneratorTarget* target); + // Target name hooks for superclass. const char* GetAllTargetName() const override { return "all"; } const char* GetInstallTargetName() const override { return "install"; } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index aa3f28e..e6d56d3 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -4626,6 +4626,12 @@ void AppendCustomCommandToOutput(cmLocalGenerator& lg, if (cmCustomCommand* cc = sf->GetCustomCommand()) { cc->AppendCommands(commandLines); cc->AppendDepends(depends); + if (cc->GetCodegen() && !implicit_depends.empty()) { + lg.GetCMakeInstance()->IssueMessage( + MessageType::FATAL_ERROR, + "Cannot append IMPLICIT_DEPENDS to existing CODEGEN custom " + "command."); + } cc->AppendImplicitDepends(implicit_depends); return; } diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 7def1fe..4a776b4 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1763,6 +1763,21 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules( this->WriteMakeRule(ruleFileStream, "The main all target", "all", depends, commands, true); + // Write the codegen rule. + if (this->GetGlobalGenerator()->CheckCMP0171()) { + recursiveTarget = cmStrCat(this->GetCurrentBinaryDirectory(), "/codegen"); + depends.clear(); + commands.clear(); + if (regenerate) { + depends.emplace_back("cmake_check_build_system"); + } + commands.push_back(this->GetRecursiveMakeCall(mf2Dir, recursiveTarget)); + AppendEcho(commands, "Finished generating code", + cmLocalUnixMakefileGenerator3::EchoColor::EchoGenerate); + this->WriteMakeRule(ruleFileStream, "The main codegen target", "codegen", + depends, commands, true); + } + // Write the clean rule. recursiveTarget = cmStrCat(this->GetCurrentBinaryDirectory(), "/clean"); commands.clear(); diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index d5c50bc..9ff0a4a 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -251,6 +251,8 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() std::vector<cmSourceFile const*> customCommands; this->GeneratorTarget->GetCustomCommands(customCommands, this->GetConfigName()); + std::vector<std::string> codegen_depends; + codegen_depends.reserve(customCommands.size()); for (cmSourceFile const* sf : customCommands) { if (this->CMP0113New && !this->LocalGenerator->GetCommandsVisited(this->GeneratorTarget) @@ -273,6 +275,33 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() this->LocalGenerator->MaybeRelativeToCurBinDir(byproduct)); } } + + if (ccg.GetCC().GetCodegen()) { + std::string const& output = ccg.GetOutputs().front(); + + // We always attach the actual commands to the first output. + codegen_depends.emplace_back(output); + } + } + + // Some make tools need a special dependency for an empty rule. + if (codegen_depends.empty()) { + std::string hack = this->GlobalGenerator->GetEmptyRuleHackDepends(); + if (!hack.empty()) { + codegen_depends.emplace_back(std::move(hack)); + } + } + + // Construct the codegen target. + { + std::string const codegenTarget = cmStrCat( + this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget), + "/codegen"); + + // Write the rule. + this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr, + codegenTarget, codegen_depends, {}, + true); } // Add byproducts from build events to the clean rules diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index d893c44..85f3293 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -525,7 +525,9 @@ class cmMakefile; 3, 30, 0, cmPolicies::WARN) \ SELECT(POLICY, CMP0170, \ "FETCHCONTENT_FULLY_DISCONNECTED requirements are enforced.", 3, 30, \ - 0, cmPolicies::WARN) + 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0171, "'codegen' is a reserved target name.", 3, 31, 0, \ + cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 1284130..a6e6984 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -657,6 +657,7 @@ public: bool PerConfig; cmTarget::Visibility TargetVisibility; std::set<BT<std::pair<std::string, bool>>> Utilities; + std::set<std::string> CodegenDependencies; std::vector<cmCustomCommand> PreBuildCommands; std::vector<cmCustomCommand> PreLinkCommands; std::vector<cmCustomCommand> PostBuildCommands; @@ -1238,6 +1239,16 @@ void cmTarget::AddUtility(BT<std::pair<std::string, bool>> util) this->impl->Utilities.emplace(std::move(util)); } +void cmTarget::AddCodegenDependency(std::string const& name) +{ + this->impl->CodegenDependencies.emplace(name); +} + +std::set<std::string> const& cmTarget::GetCodegenDeps() const +{ + return this->impl->CodegenDependencies; +} + std::set<BT<std::pair<std::string, bool>>> const& cmTarget::GetUtilities() const { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 385dfe7..220ac13 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -173,6 +173,11 @@ public: void AddUtility(std::string const& name, bool cross, cmMakefile const* mf = nullptr); void AddUtility(BT<std::pair<std::string, bool>> util); + + void AddCodegenDependency(std::string const& name); + + std::set<std::string> const& GetCodegenDeps() const; + //! Get the utilities used by this target std::set<BT<std::pair<std::string, bool>>> const& GetUtilities() const; diff --git a/Source/cmTargetTraceDependencies.cxx b/Source/cmTargetTraceDependencies.cxx index cc91a42..f14cfbf 100644 --- a/Source/cmTargetTraceDependencies.cxx +++ b/Source/cmTargetTraceDependencies.cxx @@ -7,10 +7,12 @@ #include <cmext/algorithm> +#include "cmCustomCommand.h" #include "cmCustomCommandGenerator.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" #include "cmList.h" +#include "cmListFileCache.h" #include "cmMakefile.h" #include "cmMessageType.h" #include "cmSourceFile.h" @@ -132,6 +134,8 @@ void cmTargetTraceDependencies::FollowName(std::string const& name) // The name is a byproduct of a utility target or a PRE_BUILD, PRE_LINK, or // POST_BUILD command. this->GeneratorTarget->Target->AddUtility(t->GetName(), false); + + this->GeneratorTarget->Target->AddCodegenDependency(t->GetName()); } if (cmSourceFile* sf = i->second.Source) { // For now only follow the dependency if the source file is not a @@ -213,6 +217,11 @@ void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc) // Collect target-level dependencies referenced in command lines. for (auto const& util : ccg.GetUtilities()) { this->GeneratorTarget->Target->AddUtility(util); + + if (ccg.GetCC().GetCodegen()) { + this->GeneratorTarget->Target->AddCodegenDependency( + util.Value.first); + } } // Collect file-level dependencies referenced in DEPENDS. @@ -226,6 +235,8 @@ void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc) // The dependency does not name a target and may be a file we // know how to generate. Queue it. this->FollowName(dep); + } else { + this->GeneratorTarget->Target->AddCodegenDependency(dep); } } } |