[CMake] Testing for existence of a target in a generator expression

Craig Scott audiofanatic at gmail.com
Fri Sep 25 06:17:52 EDT 2015


I can't see anything in the CMake docs which seems to facilitate this, but
I was wondering if there's any way to test whether a target is defined
inside a generator expression? What I'd like to be able to do is something
like this:

target_compile_definitions(bar PUBLIC
$<STREQUAL:$<TARGET_EXISTS:foo>:HAVE_FOO>)

This would open up the possibility of setting build flags, etc. depending
on things defined later in the CMakeLists.txt file. For a good example of
the sort of problem it might solve, have a look at the following question
on StackOverflow:

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


-- 
Craig Scott
Melbourne, Australia
http://crascit.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150925/e20f5a78/attachment.html>


More information about the CMake mailing list