# IN\_LIST unexpected behavior when used with file sets?

**URL:** https://discourse.cmake.org/t/in-list-unexpected-behavior-when-used-with-file-sets/7857
**Category:** Code
**Created:** [April 7, 2023, 2:41pm UTC](https://discourse.cmake.org/t/in-list-unexpected-behavior-when-used-with-file-sets/7857 "2023-04-07T14:41:54Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![dsterk-x](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dsterk-x/32/2137_2.png) [@dsterk-x](https://discourse.cmake.org/u/dsterk-x)
#### Post date: [April 7, 2023, 2:41pm UTC](https://discourse.cmake.org/t/in-list-unexpected-behavior-when-used-with-file-sets/7857/1 "2023-04-07T14:41:54Z")

</div>

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

```auto
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.

```auto
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](https://github.com/dsterk-x/cmake_snippets/tree/main/examples/verify_header_example)

Could someone help me understanding the behavior of IN\_LIST genex in this context?

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [April 7, 2023, 3:26pm UTC](https://discourse.cmake.org/t/in-list-unexpected-behavior-when-used-with-file-sets/7857/2 "2023-04-07T15:26:07Z")

</div>

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

```cmake
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…

---

<div class="post-metadata">

### Author: ![dsterk-x](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dsterk-x/32/2137_2.png) [@dsterk-x](https://discourse.cmake.org/u/dsterk-x)
#### Post date: [April 7, 2023, 7:46pm UTC](https://discourse.cmake.org/t/in-list-unexpected-behavior-when-used-with-file-sets/7857/3 "2023-04-07T19:46:29Z")

</div>

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.

```auto
cmake_minimum_required(VERSION 3.24)

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

```

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [April 7, 2023, 9:19pm UTC](https://discourse.cmake.org/t/in-list-unexpected-behavior-when-used-with-file-sets/7857/4 "2023-04-07T21:19:09Z")

</div>

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](https://gitlab.kitware.com/cmake/cmake/-/issues) because clearly the result is not correct when semi-colons are part of the genex.

---

<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: [April 24, 2023, 4:46am UTC](https://discourse.cmake.org/t/in-list-unexpected-behavior-when-used-with-file-sets/7857/5 "2023-04-24T04:46:48Z")

</div>

> [@marc.chevrier](#):
>
> @kyle.edwards I suspect that list expansion is done **before** genex evaluation…

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