# $\<0\> genex doesn't evaluate argument, $\<IF\> evaluates both. Is that intentional?

**URL:** https://discourse.cmake.org/t/0-genex-doesnt-evaluate-argument-if-evaluates-both-is-that-intentional/1960
**Category:** Usage
**Created:** [October 2, 2020, 11:56am UTC](https://discourse.cmake.org/t/0-genex-doesnt-evaluate-argument-if-evaluates-both-is-that-intentional/1960 "2020-10-02T11:56:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [October 2, 2020, 11:56am UTC](https://discourse.cmake.org/t/0-genex-doesnt-evaluate-argument-if-evaluates-both-is-that-intentional/1960/1 "2020-10-02T11:56:31Z")

</div>

I’ve been hit by a difference between `$<0:x>` and `$<IF:c,x,y>` which I considered unexpected, and wanted to ask whether it’s intentional.

In these example, assume target `foo` does _not_ exist. Tested with CMake 3.18.3.

The following genex evaluates to the empty string just fine:

```
$<$<TARGET_EXISTS:foo>:$<TARGET_LINKER_FILE:foo>>

```

However, if we use `$<IF>` instead:

```
$<IF:$<TARGET_EXISTS:foo>,$<TARGET_LINKER_FILE:foo>,>

```

we get an error saying

> No target “foo”

This means that both branches of `$<IF>` must be fully valid, regardless of the condition. From my view, it severly diminishes the usability of `$<IF>` if I have to think about whether the condition affects the validity of both branches, instead of using it automatically whenever I need an if-else.

Is this behaviour intentional, or should I file a bug?

---

<div class="post-metadata">

### Author: ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)
#### Post date: [October 2, 2020, 2:59pm UTC](https://discourse.cmake.org/t/0-genex-doesnt-evaluate-argument-if-evaluates-both-is-that-intentional/1960/2 "2020-10-02T14:59:44Z")

</div>

Sounds like the same concern:  
`IF Generator expression evaluates both branches eagerly`  
[https://gitlab.kitware.com/cmake/cmake/-/issues/21045](https://gitlab.kitware.com/cmake/cmake/-/issues/21045)

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [October 2, 2020, 3:08pm UTC](https://discourse.cmake.org/t/0-genex-doesnt-evaluate-argument-if-evaluates-both-is-that-intentional/1960/3 "2020-10-02T15:08:09Z")

</div>

Yes, that’s the same issue. Thanks for finding the ticket.

So it seems the answer to “Is that intentional?” is “No, but it’s not practical to address.” Unfortunate, but understandable; I can live with that.
