CMake 3.23.0-rc1 | Exposes illegal generator expression

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

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

However, the following works fine:

    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.

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

Output from VS2022:

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

Output from Ninja:

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

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

1 Like

Yes it works fine on 3.22 / 3.21

Here is some example code we currently use. If this syntax is illegal I didn’t realize until now since it’s been working.

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

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:

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.

2 Likes

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.

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

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

This was also reported as CMake Issue 23203. See discussion there for analysis and further updates.

1 Like