diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2020-07-16 08:15:04 (GMT) |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2020-07-21 15:16:26 (GMT) |
commit | 2cdaf43d966f8407f0fb75ceb131fdca16617915 (patch) | |
tree | 15e3284091c62ca73b22fa15ea1a93770c97305d /Source/cmGlobalGenerator.cxx | |
parent | c7b7547d8da6b9a4225d111440d0cf6c2f55914d (diff) | |
download | CMake-2cdaf43d966f8407f0fb75ceb131fdca16617915.zip CMake-2cdaf43d966f8407f0fb75ceb131fdca16617915.tar.gz CMake-2cdaf43d966f8407f0fb75ceb131fdca16617915.tar.bz2 |
Allow generator expressions in the EXCLUDE_FROM_ALL target property
This allows for setting EXCLUDE_FROM_ALL, conditional on the build
configuration. However, only the Ninja Multi-Config generator supports
different property values per config. All other multi-config
generators will yield an error in that situation.
Fixes: #20923
Diffstat (limited to 'Source/cmGlobalGenerator.cxx')
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 49b73a8..d39fefa 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2173,13 +2173,38 @@ bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root, } bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root, - cmGeneratorTarget* target) const + const cmGeneratorTarget* target) const { if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { return true; } - if (cmProp exclude = target->GetProperty("EXCLUDE_FROM_ALL")) { - return cmIsOn(*exclude); + cmMakefile* mf = root->GetMakefile(); + const std::string EXCLUDE_FROM_ALL = "EXCLUDE_FROM_ALL"; + if (cmProp exclude = target->GetProperty(EXCLUDE_FROM_ALL)) { + // Expand the property value per configuration. + unsigned int trueCount = 0; + unsigned int falseCount = 0; + const std::vector<std::string>& configs = + mf->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); + for (const std::string& config : configs) { + cmGeneratorExpressionInterpreter genexInterpreter(root, config, target); + if (cmIsOn(genexInterpreter.Evaluate(*exclude, EXCLUDE_FROM_ALL))) { + ++trueCount; + } else { + ++falseCount; + } + } + + // Check whether the genex expansion of the property agrees in all + // configurations. + if (trueCount && falseCount) { + std::ostringstream e; + e << "The EXCLUDED_FROM_ALL property of target \"" << target->GetName() + << "\" varies by configuration. This is not supported by the \"" + << root->GetGlobalGenerator()->GetName() << "\" generator."; + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); + } + return trueCount; } // This target is included in its directory. Check whether the // directory is excluded. |