Using a function keyword in a generator expression

What’s the correct syntax for using a function argument as a conditional operator in a generator expression? The example below encapsulates what I’m trying to achieve, but the syntax here doesn’t work, and neither do various different (and less readable) versions that I’ve tried:

    function(set_SWIG_flags)

        set (prefix       SWIGLIB)
        set (noValues     PY2 PY3)
        cmake_parse_arguments(${prefix} "${noValues}" "${singleValues}" "${multiValues}" ${ARGN})

        set(CMAKE_SWIG_FLAGS -c++
                             -builtin
                             $<SWIGLIB_PY2:-classic>
                             PARENT_SCOPE)

    endfunction()

I’m sure this must be possible, but I’d appreciate a push in the right direction.

The variable must be expanded:

$<$<BOOL:${SWIGLIB_PY2}>:-classic>

But, here, genex are not required. You can also do:

set(MY_SWIG_FLAGS -c++ -builtin)
if(SWIG_PY2)
  list(APPEND MY_SWIG_FLAGS -classic)
endif()
set(CMAKE_SWIG_FLAGS ${MY_SWIG_FLAGS} PARENT_SCOPE)

Thank you; I think your second suggestion is actually much better. I was trying to be too clever for my own good.