# CMake 3.23.0-rc1 | Exposes illegal generator expression

**URL:** https://discourse.cmake.org/t/cmake-3-23-0-rc1-exposes-illegal-generator-expression/4984
**Category:** Development
**Created:** [February 10, 2022, 7:34pm UTC](https://discourse.cmake.org/t/cmake-3-23-0-rc1-exposes-illegal-generator-expression/4984 "2022-02-10T19:34:41Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [February 10, 2022, 7:34pm UTC](https://discourse.cmake.org/t/cmake-3-23-0-rc1-exposes-illegal-generator-expression/4984/1 "2022-02-10T19:34:41Z")

</div>

The following generator expression is causing issues in cmake 3.23.0-rc1

```auto
    set(foobar TRUE)
    target_link_libraries(my_library PRIVATE
        $<$<OR:$<CONFIG:Debug>,$<BOOL:${foobar}>>:
            advapi32.lib
        >
    )

```

However, the following works fine:

```auto
    set(foobar TRUE)
    target_link_libraries(my_library PRIVATE
        $<$<OR:$<CONFIG:Debug>,$<BOOL:${foobar}>>:advapi32.lib>
    )

```

EDIT:

Based on everyone’s feedback it appears we just have illegal CMake code which the 3.23 rc1 exposed. The issue is quick enough to fix in our code.

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [February 10, 2022, 7:49pm UTC](https://discourse.cmake.org/t/cmake-3-23-0-rc1-exposes-illegal-generator-expression/4984/2 "2022-02-10T19:49:47Z")

</div>

To help those who are googling here are the errors I got:

Output from VS2022:

```auto
35>LINK : fatal error LNK1104: cannot open file '$<1:.obj'

```

Output from Ninja:

```auto
ninja: error: build.ninja:2422: bad $-escape (literal $ must be written as $$)

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 10, 2022, 8:45pm UTC](https://discourse.cmake.org/t/cmake-3-23-0-rc1-exposes-illegal-generator-expression/4984/3 "2022-02-10T20:45:56Z")

</div>

Did this ever work? The argument splitting happens here before the genex parser, so you’re passing these arguments to `target_link_libraries`:

- `$<$<OR:$<CONFIG:Debug>,$<BOOL:${foobar}>>:`
- `advapi32.lib`
- `>`

None of these are genexes (the first does contain some, but is the `$<1:` you see).

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [February 10, 2022, 8:54pm UTC](https://discourse.cmake.org/t/cmake-3-23-0-rc1-exposes-illegal-generator-expression/4984/4 "2022-02-10T20:54:52Z")

</div>

> [@ben.boeckel](#):
>
> Did this ever work?

Yes it works fine on 3.22 / 3.21

Here is some [example code](https://github.com/GPUOpen-Drivers/pal/blob/b638e90ca4e6e5a6fc4f00029d62f8e064aa18eb/cmake/PalCompileDefinitions.cmake#L101) we currently use. If this syntax is illegal I didn’t realize until now since it’s been working.

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [February 11, 2022, 12:57am UTC](https://discourse.cmake.org/t/cmake-3-23-0-rc1-exposes-illegal-generator-expression/4984/5 "2022-02-11T00:57:52Z")

</div>

It’s worth noting that this breakage only occurred with `target_link_libraries` and `target_compile_definitions` still works fine for us.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [February 11, 2022, 10:09am UTC](https://discourse.cmake.org/t/cmake-3-23-0-rc1-exposes-illegal-generator-expression/4984/6 "2022-02-11T10:09:34Z")

</div>

I have my doubts that ever did work, at least not in the way you expected. You might find the following article I published recently to be helpful:

> **[Quoting In CMake](https://crascit.com/2022/01/25/quoting-in-cmake/)**
>
> Get some clarity on CMake's quoting rules, as we highlight common pitfalls and offer guidelines for safer use.

If you want to confirm the behavior with different CMake versions, use `get_target_property(prop my_library LINK_LIBRARIES)` after you call `target_link_libraries()`. Print the value of `${prop}` and if you see semicolons inserted in the middle of what you provided, that confirms that your generator expression is being split instead of being treated as a single whole.

---

<div class="post-metadata">

### Author: ![dbahadir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dbahadir/32/197_2.png) [@dbahadir](https://discourse.cmake.org/u/dbahadir)
#### Post date: [February 11, 2022, 10:31am UTC](https://discourse.cmake.org/t/cmake-3-23-0-rc1-exposes-illegal-generator-expression/4984/7 "2022-02-11T10:31:26Z")

</div>

Since when did CMake allow any line-breaks or whitespace in general within generator-expressions?  
I thought this would never have worked?

**Edit:** I answered via Email and I wasn’t aware of all the existing answers. Apparently, GMail made multiple, separate Email-threads out of this, not all containing all answers.  
Therefore just ignore my question.

---

<div class="post-metadata">

### Author: ![dbahadir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dbahadir/32/197_2.png) [@dbahadir](https://discourse.cmake.org/u/dbahadir)
#### Post date: [February 11, 2022, 10:41am UTC](https://discourse.cmake.org/t/cmake-3-23-0-rc1-exposes-illegal-generator-expression/4984/8 "2022-02-11T10:41:02Z")

</div>

Is it just me or is the website of your example code not reachable?  
(I assume it is a company internal page only?)

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [February 11, 2022, 1:37pm UTC](https://discourse.cmake.org/t/cmake-3-23-0-rc1-exposes-illegal-generator-expression/4984/9 "2022-02-11T13:37:35Z")

</div>

I accidentally posted an internal link. I updated it to the open source version.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [February 15, 2022, 10:47pm UTC](https://discourse.cmake.org/t/cmake-3-23-0-rc1-exposes-illegal-generator-expression/4984/11 "2022-02-15T22:47:51Z")

</div>

This was also reported as [CMake Issue 23203](https://gitlab.kitware.com/cmake/cmake/-/issues/23203). See discussion there for analysis and further updates.
