…But on a scale of 1 to “What is WRONG with you???”, how bad is it to do something like this?:
set(_dependency_checks
ENABLE_DEP
DepPkg_FOUND
OtherPkg_FOUND
AddonPkg_FOUND
)
add_feature_info(
"Dependency"
"${_dependency_checks}"
"Use the dependency"
)
list(JOIN _dependency_checks ";AND;" _if_conditions)
if(${_if_conditions})
# Configure the dependency; all of its conditions are met
endif()
(I’m specifically wondering about the if() statement there. The add_feature_info() second arg, I’m not worried about.)
I know it works, but it makes me feel kind of gross just writing it.
I can sort of understand the motivation to deduplicate code between add_feature_info and your if statement, but I think this is more complex and error-prone than it needs to be. I might consider it if there were like 10+ conditions, but for only 4, I would just violate DRY in the name of easier-to-read code.
(I mean, if it were just add_feature_info(), I could do this:
if(ENABLE_FOO AND Foo_FOUND AND Bar_FOUND AND
Baz_FOUND AND Bat_FOUND AND Frob_FOUND AND
Xyzzy_FOUND AND Zork_FOUND)
add_feature_info("Dependency" TRUE "Use the dependency")
else()
add_feature_info("Dependency" FALSE "Use the dependency")
endif()
But assume there’s more complexity involved in generating the initial _dependency_checks list to begin with, that precludes doing that.)