Using target-specific generator expressions in global CMake variables

I’d like to write something of the form

set(CMAKE_VS_DEBUGGER_WORKING_DIRECTORY "$<TARGET_FILE_DIR:$<some genex to get the name of the target this ends up applying to>>")

so that each target’s value of VS_DEBUGGER_WORKING_DIRECTORY ends up being the directory the binary ends up in, without needing to manually set the property on every target.

However, I’ve not been able to find a generator expression to get the current target name for things that end up evaluated for a specific target.

Hopefully, this is easy, and I’m only struggling because Google’s dumber than it was ten or fifteen years ago.

I think you’re looking for $<TARGET_PROPERTY:NAME>.

Thanks, that’s exactly what I was looking for, and I’ve no idea how I managed to scroll past it so many times without seeing it.

Unfortunately, it seems it won’t work for my needs. When the generator expression is evaluated, it happens for all targets (which is what I was expecting), but apparently $<TARGET_PROPERTY:prop> may only be used with binary targets and may not be used with add_custom_command or add_custom_target, so using it in a CMAKE_ variable blows up as there’s no way to check if it’s going to work without already knowing the target’s name.