IN_LIST generator-expression does not work as expected

Hi, I have a piece of code like this:

set(SOME_LIST member_a meber_b)
set(TEST_STRING member_a)
if (${TEST_STRING} IN_LIST SOME_LIST)
    target_sources(a_library
        PRIVATE
            some_code_a.c
    )
else()
    target_sources(a_library
        PRIVATE
            some_code_b.c
    )
endif()

It works fine to pick up some_code_a.c.
But if I convert it to generator-expression:

target_sources(a_library
    PRIVATE
$<$<IN_LIST:${TEST_STRING},SOME_LIST>:${CMAKE_CURRENT_SOURCE_DIR}/some_code_a.c>
$<$<NOT:$<IN_LIST:${TEST_STRING},SOME_LIST>>:${CMAKE_CURRENT_SOURCE_DIR}/some_code_b.c>
)

It always picks up some_code_b.c.
I just couldn’t understand.
Is there anyone who can help me out with this?

You have to expand your SOME_LIST:

target_sources(a_library
    PRIVATE
"$<$<IN_LIST:${TEST_STRING},${SOME_LIST}>:${CMAKE_CURRENT_SOURCE_DIR}/some_code_a.c>"
"$<$<NOT:$<IN_LIST:${TEST_STRING},${SOME_LIST}>>:${CMAKE_CURRENT_SOURCE_DIR}/some_code_b.c>"
)

Thanks, Jakub.
It worked!!!
But… why?
I mean, other generator expressions such as NOT and STREQUAL do not need to be expanded.

AFAIK they do.
That’s because the CMake variables do not exist anymore when the genex gets evaluated.

Hmmm…
There might be some miss understanding.
By “expand", do you mean ${CMAKE_VAR}?
If it is, then expanding CMake variables for IN_LIST only does not work either.
It’s the double quotation marks that fix my example.

Yes, that’s what I meant.
The double Quotation is just another piece of the puzzle, which prevents premature splitting of the genex by the argument parser. Without it, after expansion of the list, the semicolons will mess things up.
Typically you want your genex quoted like that.

Thank again!

Hi

Why BOOL/NOT/AND/OR doesn’t need double Quotation? If the double Quotation is necessary for IN_LIST to avoid issue caused by semicolon in list, why not mention this in document or refine this defect in CMAKE source code?

Best Regards
Jianliang Shen