# expression generator in list

**URL:** https://discourse.cmake.org/t/expression-generator-in-list/2763
**Category:** Usage
**Created:** [February 15, 2021, 5:05pm UTC](https://discourse.cmake.org/t/expression-generator-in-list/2763 "2021-02-15T17:05:19Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![grimgort](https://discourse.cmake.org/user_avatar/discourse.cmake.org/grimgort/32/1002_2.png) [@grimgort](https://discourse.cmake.org/u/grimgort)
#### Post date: [February 15, 2021, 5:05pm UTC](https://discourse.cmake.org/t/expression-generator-in-list/2763/1 "2021-02-15T17:05:19Z")

</div>

Hello,

Using the following list gives me an error in add\_link\_option, but not in target\_link\_option.  
In particular $\<$CONFIG:Release:XXX; returns $\<0:""\> .So the second generator expression doesn’t work. it seems to work with target\_link\_option.

```
list(
    APPEND
    c_link_flag
    $<$<CONFIG:Release>:
    #/OPT:ICF;
    /SAFESEH;
    #/NODEFAULTLIB:"libucrt.lib";
    #/NODEFAULTLIB:"libmmt.lib";
    /ERRORREPORT:PROMPT;
    >
    /INCREMENTAL;
    /DYNAMICBASE:NO;
    /FIXED:NO;
    /NOLOGO;
    #matisse_lib flag support
    /MANIFEST;
    /SUBSYSTEM:CONSOLE;
    /TLBID:1;
    #/MANIFESTUAC:"level='asInvoker' uiAccess='false'";
  )
  add_link_options(${c_link_flag})
```

---

<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: [February 15, 2021, 5:48pm UTC](https://discourse.cmake.org/t/expression-generator-in-list/2763/2 "2021-02-15T17:48:56Z")

</div>

I don’t think you can do all the whitespace splitting you’re doing there. The explicit `;` characters likely aren’t helping either. I think this needs to be something like:

```cmake
set(c_release_link_flags
  #/OPT:ICF
  /SAFESEH
  #/NODEFAULTLIB:"libucrt.lib"
  #/NODEFAULTLIB:"libmmt.lib"
  /ERRORREPORT:PROMPT
  )
list(APPEND c_link_flag
  "$<$<CONFIG:Release>:${c_release_link_flags}>"
  /INCREMENTAL
  /DYNAMICBASE:NO
  /FIXED:NO
  /NOLOGO
  # matisse_lib flag support
  /MANIFEST
  /SUBSYSTEM:CONSOLE
  /TLBID:1
  #"/MANIFESTUAC:\"level='asInvoker' uiAccess='false'\""
  )
add_link_options(${c_link_flag})

```

---

<div class="post-metadata">

### Author: ![grimgort](https://discourse.cmake.org/user_avatar/discourse.cmake.org/grimgort/32/1002_2.png) [@grimgort](https://discourse.cmake.org/u/grimgort)
#### Post date: [February 16, 2021, 9:03am UTC](https://discourse.cmake.org/t/expression-generator-in-list/2763/3 "2021-02-16T09:03:51Z")

</div>

This solution still doesn’t work. I have errors of the following type (with add\_compile\_option)

```
 fatal error C1083: Unable to open the source file : '$<1:/analysis' : No such file or directory

```

Preformatted text`my code 🙂

```
    set(c_compile_debug_flags  
    /analysis
    /W3
    #/Od
    /Fd
    /Zc:inline
    /errorReport:prompt
    /WX-
    /Zc:forScope
    #/RTC1
    /MTd
    /FC
    /EHsc
    /nologo
    /GS
    /diagnostics:column
    )
   set(c_compile_release_flags  
    /analyze-
    /W3
    /Gy
    #/O2
    /Zc:inline
    /errorReport:prompt
    /GF
    /WX-
    /Zc:forScope
    /MT
    /FC
    /EHsc
    /nologo
    /diagnostics:column
    #matisse_lib flag support
    /GS-
    /TC
    /Zl
    )
  list(
    APPEND
    c_compile_flags
    "$<$<CONFIG:Debug>:${c_compile_debug_flags}>"
    "$<$<CONFIG:Release>:${c_compile_release_flags}>"
```

---

<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: [February 16, 2021, 12:42pm UTC](https://discourse.cmake.org/t/expression-generator-in-list/2763/4 "2021-02-16T12:42:20Z")

</div>

Ah, the embedded `;` in the genex element confuses the list parser. I would just add the genex entries directly to the `target_compile_options` command instead of using an intermediate variable. CMake’s list encoding is not really that great, unfortunately, but we’re stuck with it 😕 .
