target_link_libraries and list of PLATFORM_IDs

Hello, found this SO post that fails on 3.20 and I verified on 3.21.2 myself.
That is, you can’t list several libraries under target_link_libraries with PLATFORM_ID unless you put them in a list variable outside and then quote the whole expression.

Is this working as intended or is it an error? The documentation for the PLATFORM_ID genex does not mention any exception for target_link_libraries.

This is more a consequence of CMake parsing. $<SOME_GENEX:${list}> gets parsed as the arguments $<SOME_GENEX:first_element, second_element, and last_element> because of how the splitting works. Quoting the genex should do what you want.

Thanks, and sorry for the late reply.
Just quoting does not work for me (on 3.21.2), I need to have them in a separate variable. I think that’s the confusing bit.
Eg this "$<$<NOT:$<PLATFORM_ID:Windows>>:m,pthread>"
…fails as the resulting list I get is -lm,pthread rather than -lpthread -lm.

I’d guess it’s because of the comma. It looks like you wanted a list, and list separator is semicolon in CMake.

Thanks, yes you’re right. The following works: "$<$<NOT:$<PLATFORM_ID:Windows>>:m;pthread>"