[CMake] target_link_libraries can't set linker options with Visual Studio generator

Patrick Griffiths patrick.griffiths at gmail.com
Mon Jun 29 17:48:36 EDT 2015


I'm using CMake 3.2.3.

I really need to be able to add options to LINK_FLAGS using generator
expressions. When I use LINK_FLAGS with set_target_properties or
set_property, generator expressions are not expanded.

I noticed that the documentation for target_link_libraries says:

"Item names starting with -, but not -l or -framework, are treated as
linker flags...."

So I tried setting options with target_link_libraries. Unfortunately, it
doesn't work.

Some generator expressions (e.g. $<TARGET_FILE_DIR:target>) error out
during generation:  "Expressions which require the linker language may not
be used while evaluating link libraries".

In case where the generator expressions do evaluate, the VS generator
treats all options as if they were link libraries, so my options end-up in
the list of libraries to link. For example, I end-up with
-PDBSTRIPPED:c:/path/to/lib/mylib.pdb in the Linker>Additional Dependencies
setting.

I'm really stuck. How can I set linker flags that use generator expressions?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150629/8d958807/attachment.html>


More information about the CMake mailing list