cmGeneratorExpressionNode: implement COMPILE_ONLY genex

This generator expression is the inverse of `LINK_ONLY` and only coveys
usage requirements for the purposes of compilation. Its intended use is
to avoid needing to export targets that do not have link usage
requirements (e.g., header-only libraries) when used by another target.

See: #15415
This commit is contained in:
Robert Maynard
2023-04-11 15:49:52 -04:00
parent 0fb923c460
commit c42630ee62
10 changed files with 65 additions and 12 deletions

View File

@@ -1363,14 +1363,13 @@ static const struct CompileOnlyNode : public cmGeneratorExpressionNode
{
if (!dagChecker) {
reportError(context, content->GetOriginalExpression(),
"$<COMPILE_ONLY:...> may only be used via linking");
"$<COMPILE_ONLY:...> may only be used for linking");
return std::string();
}
// Linking checks for the inverse, so compiling is the opposite.
if (dagChecker->GetTransitivePropertiesOnly()) {
return parameters.front();
}
return std::string();
return std::string{};
}
} compileOnlyNode;
@@ -1389,8 +1388,7 @@ static const struct LinkOnlyNode : public cmGeneratorExpressionNode
"$<LINK_ONLY:...> may only be used for linking");
return std::string();
}
// Compile-only checks for the inverse, so linking is the opposite.
if (!dagChecker->GetTransitivePropertiesOnly()) {
if (!dagChecker->GetTransitivePropertiesOnlyCMP0131()) {
return parameters.front();
}
return std::string();