CLANG_TIDY property unexpected behavior with Generator Expression revaluating to empty string
I'm trying to use generator expressions in the CXX_CLANG_TIDY
target property:
set_property(TARGET ${TARGET} PROPERTY CXX_CLANG_TIDY "<IF:$<BOOL:TRUE>,${CLANG_TIDY_CMD},>")
behaves appropriately, I see clang-tidy getting invoked with the contents of ${CLANG_TIDY_CMD}
However, if the genex evaluates to an empty string:
set_property(TARGET ${TARGET} PROPERTY CXX_CLANG_TIDY "<IF:$<BOOL:FALSE>,${CLANG_TIDY_CMD},>")
I see an unexpected result (notice the genex is present in the --tidy
command):
[build] FAILED: foo.cpp.o [build] cmake -E __run_co_compile --tidy="$<IF:$<BOOL:FALSE>,clang-tidy;--config-file=clang_tidy.current;-header-filter=foo/*,>;--extra-arg-before=--driver-mode=g++" --source=foo.cpp ...
I would expect the previous genex statement to behave similar to:
set_property(TARGET ${TARGET} PROPERTY CXX_CLANG_TIDY "")
Which does not invoke clang-tidy.
Looking in the code, I am able to see that if the general expression evaluates to an empty string, the lambda evaluateProp
returns the original string ( value
) here:
https://gitlab.kitware.com/cmake/cmake/-/blob/v3.27.6/Source/cmCommonTargetGenerator.cxx#L330-342
auto evaluateProp = [&](std::string const& prop) -> std::string {
auto const value = this->GeneratorTarget->GetProperty(prop);
if (!value) {
return std::string{};
}
auto evaluatedProp = cmGeneratorExpression::Evaluate(
*value, this->GeneratorTarget->GetLocalGenerator(), config,
this->GeneratorTarget, nullptr, this->GeneratorTarget, lang);
if (!evaluatedProp.empty()) {
return evaluatedProp;
}
return *value;
};
std::string const tidy_prop = cmStrCat(lang, "_CLANG_TIDY");
tidy = evaluateProp(tidy_prop);
Edited by Brad King