Skip to content

Check target exists with generator expressions

It would be nice to be able to check if a target exists in a generator expression. Something like $<TARGET_EXISTS:...> that return 1 if the target exists. This way I could link in optional dependencies with generator expressions:

target_link_libraries(foo $<$<TARGET_EXISTS:bar>:bar>)
target_compile_definitions(foo PUBLIC $<$<TARGET_EXISTS:bar>:HAS_FOO=1>)

This way it will optionally link in bar if its available from another add_subdirectory.

There is also this related stackoverflow question about this same scenario:

https://stackoverflow.com/questions/32766151/check-for-optionally-targets-in-cmake-that-are-not-in-the-correct-order

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information