IN_LIST unexpected behavior when used with file sets?

I tried to work with file sets and the IN_LIST generator expression. My code looks like in the listing below.

cmake_minimum_required(VERSION 3.24)


set(TARGET_NAME alice)

add_library(${TARGET_NAME}
  src/alice.c
)

target_sources(${TARGET_NAME} PUBLIC FILE_SET HEADERS TYPE HEADERS
  BASE_DIRS
    "$<$<IN_LIST:${CMAKE_SYSTEM_PROCESSOR},x86_64;x86>:${CMAKE_CURRENT_LIST_DIR}/include/var/${CMAKE_SYSTEM_PROCESSOR}>"
    # "$<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},x86>:${CMAKE_CURRENT_LIST_DIR}/include/var/${CMAKE_SYSTEM_PROCESSOR}>"
    # "$<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},x86_64>:${CMAKE_CURRENT_LIST_DIR}/include/var/${CMAKE_SYSTEM_PROCESSOR}>"
  FILES
    "$<$<IN_LIST:${CMAKE_SYSTEM_PROCESSOR},x86_64;x86>:${CMAKE_CURRENT_LIST_DIR}/include/var/${CMAKE_SYSTEM_PROCESSOR}/arch_specifics.h>"
    # "$<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},x86>:${CMAKE_CURRENT_LIST_DIR}/include/var/${CMAKE_SYSTEM_PROCESSOR}/arch_specifics.h>"
    # "$<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},x86_64>:${CMAKE_CURRENT_LIST_DIR}/include/var/${CMAKE_SYSTEM_PROCESSOR}/arch_specifics.h>"
)

install(TARGETS ${TARGET_NAME} EXPORT export_all FILE_SET HEADERS)

When using the IN_LIST genex, CMake reports errors.

CMake Error at src/alice/CMakeLists.txt:12 (target_sources):
  File:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/$<$<IN_LIST:x86_64,x86_64

  must be in one of the file set's base directories:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/$<$<IN_LIST:x86_64,x86_64
    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/x86>:/home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/include/var/x86_64>


CMake Error at src/alice/CMakeLists.txt:12 (target_sources):
  File:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/x86>:/home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/include/var/x86_64/arch_specifics.h>

  must be in one of the file set's base directories:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/$<$<IN_LIST:x86_64,x86_64
    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/x86>:/home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/include/var/x86_64>


CMake Error at src/alice/CMakeLists.txt:12 (target_sources):
  File:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/$<$<IN_LIST:x86_64,x86_64

  must be in one of the file set's base directories:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/$<$<IN_LIST:x86_64,x86_64
    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/x86>:/home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/include/var/x86_64>


CMake Error at src/alice/CMakeLists.txt:12 (target_sources):
  File:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/x86>:/home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/include/var/x86_64/arch_specifics.h>

  must be in one of the file set's base directories:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/$<$<IN_LIST:x86_64,x86_64
    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/x86>:/home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/include/var/x86_64>


CMake Error at src/alice/CMakeLists.txt:12 (target_sources):
  File:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/$<$<IN_LIST:x86_64,x86_64

  must be in one of the file set's base directories:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/$<$<IN_LIST:x86_64,x86_64
    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/x86>:/home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/include/var/x86_64>


CMake Error at src/alice/CMakeLists.txt:12 (target_sources):
  File:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/x86>:/home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/include/var/x86_64/arch_specifics.h>

  must be in one of the file set's base directories:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/$<$<IN_LIST:x86_64,x86_64
    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/x86>:/home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/include/var/x86_64>


CMake Error in src/alice/CMakeLists.txt:
  Found relative path while evaluating include directories of "alice":

    "$<BUILD_INTERFACE:$<1"



CMake Error at src/alice/CMakeLists.txt:12 (target_sources):
  File:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/$<$<IN_LIST:x86_64,x86_64

  must be in one of the file set's base directories:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/$<$<IN_LIST:x86_64,x86_64
    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/x86>:/home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/include/var/x86_64>


CMake Error at src/alice/CMakeLists.txt:12 (target_sources):
  File:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/x86>:/home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/include/var/x86_64/arch_specifics.h>

  must be in one of the file set's base directories:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/$<$<IN_LIST:x86_64,x86_64
    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/x86>:/home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/include/var/x86_64>


CMake Error at src/alice/CMakeLists.txt:12 (target_sources):
  File:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/$<$<IN_LIST:x86_64,x86_64

  must be in one of the file set's base directories:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/$<$<IN_LIST:x86_64,x86_64
    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/x86>:/home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/include/var/x86_64>


CMake Error at src/alice/CMakeLists.txt:12 (target_sources):
  File:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/x86>:/home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/include/var/x86_64/arch_specifics.h>

  must be in one of the file set's base directories:

    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/$<$<IN_LIST:x86_64,x86_64
    /home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/x86>:/home/ds/prj/cmake_snippets/examples/generator_expressions/in_list/src/alice/include/var/x86_64>

However, when using STREQUAL genex instead, everything works as expected.

I have made an example here

Could someone help me understanding the behavior of IN_LIST genex in this context?

I suggest to you to replace the semi-colon with the $<SEMICOLON> genex.

target_sources(${TARGET_NAME} PUBLIC FILE_SET HEADERS TYPE HEADERS
  BASE_DIRS
    "$<$<IN_LIST:${CMAKE_SYSTEM_PROCESSOR},x86_64$<SEMICOLON>x86>:${CMAKE_CURRENT_LIST_DIR}/include/var/${CMAKE_SYSTEM_PROCESSOR}>"

  FILES
    "$<$<IN_LIST:${CMAKE_SYSTEM_PROCESSOR},x86_64$<SEMICOLON>x86>:${CMAKE_CURRENT_LIST_DIR}/include/var/${CMAKE_SYSTEM_PROCESSOR}/arch_specifics.h>"
  )

@kyle.edwards I suspect that list expansion is done before genex evaluation…

Thanks a lot for the hint. This worked for me.
I was confused because the following code just works for me without using $<SEMICOLON>.
Both files are compiled in this case.

cmake_minimum_required(VERSION 3.24)

add_library(alice
  src/alice.c
  "$<$<IN_LIST:${CMAKE_SYSTEM_PROCESSOR},x86;x86_64>:src/conditional_file.c>"
)

The expansion of lists and evaluation of generator expressions is not always done in the same way, so resulting in different behaviors.

But, for the FILE_SET, I think you can create an issue because clearly the result is not correct when semi-colons are part of the genex.

It probably is…but not much we can do about that now. $<SEMICOLON> is the safer thing to do here anyways.