[CMake] Trouble with conditional generator expression inside target_link_libraries
Björn Blissing
bjorn.blissing at vti.se
Thu Oct 4 10:06:35 EDT 2018
Hello,
I am having trouble with a conditional generator expression inside target link libraries, which seems to expand incorrectly (or at least not the way I expect).
In short, I have a list of libraries that is found by a CMake module. The list is composed of a number of elements each preceded by "optimized" or "debug", depending on if there are built for release or debug. These libraries should only be included if a boolean is set to true. I have tried to write a generator expression which only includes the list of libraries if this variable is set. But it seems that this expression gets expanded wrong.
If I try to condense the problem to a minimum example, it would be something like this:
LIST(APPEND MYLIB_LIBRARIES optimized foo)
LIST(APPEND MYLIB_LIBRARIES debug foo_d)
TARGET_LINK_LIBRARIES(target_name
PUBLIC
$<$<BOOL:TRUE>:${MYLIB_LIBRARIES}>
)
This generator expression makes my target depend of the following libraries for the release build:
foo.lib & optimized.lib
And for the debug build:
foo_d.lib, foo.lib & optimized.lib
Which is obviously incorrect.
Replacing the generator expression with an IF-statement instead works. But I would like to stick to generator expressions if possible to keep my CMake code consistent.
How should I rewrite my generator expression to get the correct expansion?
Regards,
Björn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20181004/77ccfafd/attachment.html>
More information about the CMake
mailing list