diff options
author | Abdelmaged Khalifa <abdelmaged.khalifa@gmail.com> | 2023-02-11 23:00:40 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-02-14 13:56:59 (GMT) |
commit | 082ccd75301cd02efd09bb9882bb9d2a8957193b (patch) | |
tree | 92611f898b4b3253c12687faa610f0bc8a0d0de8 /Source | |
parent | 48c69eeafe5e480b5baa0c6766d4d2e3c7f5a4ad (diff) | |
download | CMake-082ccd75301cd02efd09bb9882bb9d2a8957193b.zip CMake-082ccd75301cd02efd09bb9882bb9d2a8957193b.tar.gz CMake-082ccd75301cd02efd09bb9882bb9d2a8957193b.tar.bz2 |
add_custom_command: Add DEPENDS_EXPLICIT_ONLY option for Ninja
Add option `DEPENDS_EXPLICIT_ONLY` to `add_custom_command` to indicate
that implicit dependencies coming from users of the output are not
needed, and only consider dependencies explicitly specified in the
custom command.
Fixes: #17097
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmAddCustomCommandCommand.cxx | 8 | ||||
-rw-r--r-- | Source/cmCustomCommand.cxx | 10 | ||||
-rw-r--r-- | Source/cmCustomCommand.h | 6 | ||||
-rw-r--r-- | Source/cmLocalNinjaGenerator.cxx | 52 |
4 files changed, 50 insertions, 26 deletions
diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index 831e9c7..65a8eb5 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -49,6 +49,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, bool append = false; bool uses_terminal = false; bool command_expand_lists = false; + bool depends_explicit_only = false; std::string implicit_depends_lang; cmImplicitDependsList implicit_depends; @@ -104,6 +105,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, MAKE_STATIC_KEYWORD(USES_TERMINAL); MAKE_STATIC_KEYWORD(VERBATIM); MAKE_STATIC_KEYWORD(WORKING_DIRECTORY); + MAKE_STATIC_KEYWORD(DEPENDS_EXPLICIT_ONLY); #undef MAKE_STATIC_KEYWORD static std::unordered_set<std::string> const keywords{ keyAPPEND, @@ -126,7 +128,8 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, keyTARGET, keyUSES_TERMINAL, keyVERBATIM, - keyWORKING_DIRECTORY + keyWORKING_DIRECTORY, + keyDEPENDS_EXPLICIT_ONLY }; for (std::string const& copy : args) { @@ -155,6 +158,8 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, uses_terminal = true; } else if (copy == keyCOMMAND_EXPAND_LISTS) { command_expand_lists = true; + } else if (copy == keyDEPENDS_EXPLICIT_ONLY) { + depends_explicit_only = true; } else if (copy == keyTARGET) { doing = doing_target; } else if (copy == keyARGS) { @@ -329,6 +334,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, cc->SetDepfile(depfile); cc->SetJobPool(job_pool); cc->SetCommandExpandLists(command_expand_lists); + cc->SetDependsExplicitOnly(depends_explicit_only); if (source.empty() && output.empty()) { // Source is empty, use the target. mf.AddCustomCommandToTarget(target, cctype, std::move(cc)); diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index 5b63996..e12cf70 100644 --- a/Source/cmCustomCommand.cxx +++ b/Source/cmCustomCommand.cxx @@ -164,6 +164,16 @@ void cmCustomCommand::SetCommandExpandLists(bool b) this->CommandExpandLists = b; } +bool cmCustomCommand::GetDependsExplicitOnly() const +{ + return this->DependsExplicitOnly; +} + +void cmCustomCommand::SetDependsExplicitOnly(bool b) +{ + this->DependsExplicitOnly = b; +} + const std::string& cmCustomCommand::GetDepfile() const { return this->Depfile; diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h index 3671ad9..1e68dbf 100644 --- a/Source/cmCustomCommand.h +++ b/Source/cmCustomCommand.h @@ -102,6 +102,11 @@ public: bool GetCommandExpandLists() const; void SetCommandExpandLists(bool b); + /** Set/Get whether to use additional dependencies coming from + users of OUTPUT of the custom command. */ + bool GetDependsExplicitOnly() const; + void SetDependsExplicitOnly(bool b); + /** Set/Get the depfile (used by the Ninja generator) */ const std::string& GetDepfile() const; void SetDepfile(const std::string& depfile); @@ -141,6 +146,7 @@ private: bool CommandExpandLists = false; bool StdPipesUTF8 = false; bool HasMainDependency_ = false; + bool DependsExplicitOnly = false; // Policies are NEW for synthesized custom commands, and set by cmMakefile for // user-created custom commands. diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 1e2ea2a..f8027c0 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -586,32 +586,34 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement( cmNinjaDeps orderOnlyDeps; - // A custom command may appear on multiple targets. However, some build - // systems exist where the target dependencies on some of the targets are - // overspecified, leading to a dependency cycle. If we assume all target - // dependencies are a superset of the true target dependencies for this - // custom command, we can take the set intersection of all target - // dependencies to obtain a correct dependency list. - // - // FIXME: This won't work in certain obscure scenarios involving indirect - // dependencies. - auto j = targets.begin(); - assert(j != targets.end()); - this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure( - *j, orderOnlyDeps, ccg.GetOutputConfig(), fileConfig, ccgs.size() > 1); - std::sort(orderOnlyDeps.begin(), orderOnlyDeps.end()); - ++j; - - for (; j != targets.end(); ++j) { - std::vector<std::string> jDeps; - std::vector<std::string> depsIntersection; + if (!cc->GetDependsExplicitOnly()) { + // A custom command may appear on multiple targets. However, some build + // systems exist where the target dependencies on some of the targets are + // overspecified, leading to a dependency cycle. If we assume all target + // dependencies are a superset of the true target dependencies for this + // custom command, we can take the set intersection of all target + // dependencies to obtain a correct dependency list. + // + // FIXME: This won't work in certain obscure scenarios involving indirect + // dependencies. + auto j = targets.begin(); + assert(j != targets.end()); this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure( - *j, jDeps, ccg.GetOutputConfig(), fileConfig, ccgs.size() > 1); - std::sort(jDeps.begin(), jDeps.end()); - std::set_intersection(orderOnlyDeps.begin(), orderOnlyDeps.end(), - jDeps.begin(), jDeps.end(), - std::back_inserter(depsIntersection)); - orderOnlyDeps = depsIntersection; + *j, orderOnlyDeps, ccg.GetOutputConfig(), fileConfig, ccgs.size() > 1); + std::sort(orderOnlyDeps.begin(), orderOnlyDeps.end()); + ++j; + + for (; j != targets.end(); ++j) { + std::vector<std::string> jDeps; + std::vector<std::string> depsIntersection; + this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure( + *j, jDeps, ccg.GetOutputConfig(), fileConfig, ccgs.size() > 1); + std::sort(jDeps.begin(), jDeps.end()); + std::set_intersection(orderOnlyDeps.begin(), orderOnlyDeps.end(), + jDeps.begin(), jDeps.end(), + std::back_inserter(depsIntersection)); + orderOnlyDeps = depsIntersection; + } } const std::vector<std::string>& outputs = ccg.GetOutputs(); |