[CMake] How to test for the usability of a target

Alexander Neundorf a.neundorf-work at gmx.net
Wed Oct 16 13:45:32 EDT 2013


On Tuesday 15 October 2013, Johannes Zarl wrote:
> Hi,
> 
> I'd like to make some code in my build system dependent on the existance of
> a target. Basically I'd like to write something like this:
> 
> if(TARGET optional_lib)
>   add_library(bar ${bar_srcs})
>   target_link_library(bar optional_lib)
> endif()
> 
> The problem I have is that for a couple of reasons the CMakelists file for
> bar needs to be read before optional_lib. Therefore the "TARGET
> optional_lib" test fails even though I can link bar successfully against
> optional_lib.

Can generator expressions maybe be used for that ?
They are evaluated at generate time, so at a time when the target is know to 
exist or not.

Alex


More information about the CMake mailing list