[CMake] Trouble with conditional generator expression inside target_link_libraries

Eric Noulard eric.noulard at gmail.com
Thu Oct 4 11:09:40 EDT 2018


Le jeu. 4 oct. 2018 à 16:53, Björn Blissing <bjorn.blissing at vti.se> a
écrit :

> Hello Eric,
>
>
>
> The minimal example was just to display the expansion error. In real life
> the code uses a Boolean variable (and the rest of the CMake code is much
> larger as well).
>
It was just to show the expansion error you get if you try to use a
> conditional generator expression inside a target_link_libraries function.
>

Sometimes the devil is hiding in the details.
Do ou manage to reproduce the genex expansion error on a toy example?


> I do agree that using it would be simpler if I could use:
>
>      $<$<CONFIG:Debug>:${MYLIBS_DEBUG}>
>
>      $<$<CONFIG:Release>:${MYLIBS_OPTIMIZED}>
>
>
>
> But since I use a third party find module the MYLIB_LIBRARIES variable is
> not separated into these categories. I was hoping to avoid rewriting this
> external find module.
>

You can perfectly write a CMake helper function which takes MYLIB_LIBRARIES
as input and spit out MYLIBS_DEBUG, MYLIBS_OPTIMIZED as an output.
This way you don't have to rewrite 3rd party code and keep your code clean.

-- 
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20181004/1ba1f0c5/attachment.html>


More information about the CMake mailing list