Access properties via generator expressions

I need a way to conditionally mark some include directories as PRIVATE or PUBLIC depending on global property.

here’s the code i use now that explicitly applies target property if global property is set:

    set_target_properties(mytarget PROPERTIES FOO ON)



Is there a better way to access global properties via generator expressions?

$<BOOL:${GLOBAL_FOO}> should do what you want.

That will work in the OP’s literal case, where the variable is set to its final value before the target_include_directories() call, and in the same scope. If that mirrors the OP’s real use case, it’s perfectly fine.

It wouldn’t work if in the real code, the variable could be set later/elsewhere, or change value after the target_include_directories() call. In such case, setting a property on a target (as the OP is currently doing) is the only way to make it work of which I know, and I use the same approach in our projects at work.

Thanks, seems like i’ve been taking wrong approach to expose private headers for unit testing.