# Supplying if() condition arguments via list variable

**URL:** https://discourse.cmake.org/t/supplying-if-condition-arguments-via-list-variable/13015
**Category:** Code
**Tags:** tool:cmake
**Created:** [November 21, 2024, 11:13pm UTC](https://discourse.cmake.org/t/supplying-if-condition-arguments-via-list-variable/13015 "2024-11-21T23:13:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ferdnyc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ferdnyc/32/267_2.png) [@ferdnyc](https://discourse.cmake.org/u/ferdnyc)
#### Post date: [November 21, 2024, 11:13pm UTC](https://discourse.cmake.org/t/supplying-if-condition-arguments-via-list-variable/13015/1 "2024-11-21T23:13:33Z")

</div>

I know it’s not uncommon to do things like this:

```cmake
set(_my_targets lib1 lib2 mainexe configexe)
install(
  TARGETS ${_my_targets}
  RUNTIME DESTINATION ...
)

```

Or this…

```cmake
set(_qt_components Core Network Widgets)
find_package(Qt6 COMPONENTS ${_qt_components})

```

…But on a scale of 1 to “What is WRONG with you???”, how bad is it to do something like **this**?:

```cmake
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.

---

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [November 22, 2024, 1:05am UTC](https://discourse.cmake.org/t/supplying-if-condition-arguments-via-list-variable/13015/2 "2024-11-22T01:05:54Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ferdnyc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ferdnyc/32/267_2.png) [@ferdnyc](https://discourse.cmake.org/u/ferdnyc)
#### Post date: [November 22, 2024, 1:14am UTC](https://discourse.cmake.org/t/supplying-if-condition-arguments-via-list-variable/13015/3 "2024-11-22T01:14:44Z")

</div>

Well, the real code does actually have… 8 conditions. So, it’s definitely on the line.

But it still feels icky.

---

<div class="post-metadata">

### Author: ![ferdnyc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ferdnyc/32/267_2.png) [@ferdnyc](https://discourse.cmake.org/u/ferdnyc)
#### Post date: [November 22, 2024, 1:25am UTC](https://discourse.cmake.org/t/supplying-if-condition-arguments-via-list-variable/13015/4 "2024-11-22T01:25:02Z")

</div>

(I mean, if it were just `add_feature_info()`, I could do this:

```cmake
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.)
