expression generator in list

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})

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:

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})

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 :slight_smile:

    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}>"

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 :confused: .