[CMake] Wanted: Interface link options

Anders Lindgren andlind at gmail.com
Mon Jun 16 05:53:47 EDT 2014


Hi!

Petr, thanks for the suggestion to use "-NODEFAULTLIB:xxx" instead of
"/NODEFAULTLIB:xxx". I managed to get it to work using:

    set_target_properties(mylib PROPERTIES INTERFACE_LINK_LIBRARIES
$<$<CONFIG:Debug>:-NODEFAULTLIB:msvcrt>)

However, I've noticed one drawback: in the generated Visual Studio project,
the option is hidden inside the "Additional Dependencies" list rather than
being part of "Ignore Specific Library". This feels less ergonomic and a
lot more fragile... (When using LINK_FLAGS_DEBUG and /NODEFAULTLIB:xxx, the
option is placed in the correct location.)

Hence, I still believe that INTERFACE_LINK_OPTIONS and LINK_OPTIONS should
be added to CMake. (I'm glad to here that there is some work in progress
for this!)

In addition, suggest that the Visual Studio generators should be extended
to recognize linker options on the form "-NNN" (in addition to "/NNN").

Sincerely,
    Anders Lindgren



On Fri, Jun 13, 2014 at 1:53 PM, Petr Kmoch <petr.kmoch at gmail.com> wrote:

> Hi Andres.
>
> I cannot comment on the property request itself, but you should be able to
> work around its absence by using `-` instead of `/` to introduce the linker
> option - the Visual Studio tools understand both, AFAIK.
>
> Petr
>
>
> On Fri, Jun 13, 2014 at 1:42 PM, Anders Lindgren <andlind at gmail.com>
> wrote:
>
>> Hi!
>>
>> I have a third party-library only available in Release flavor. When
>> building a Debug configuration, I need to pass the option
>> /NODEFAULTLIB:libcmt to the Visual Studio linker.
>>
>> I have been playing around with the new target interface system. However,
>> I'm missing a way for a library to specify linker options, that would
>> transitively affect targets that use the library (just like the
>> INTERFACE_COMPILE_OPTIONS and INTERFACE_LINK_LIBRARIES do for compiler
>> options and libraries, respectively).
>>
>> So, I suggest adding a INTERFACE_LINK_OPTIONS target property. That way I
>> would add the library using:
>>
>>     add_library(the_library.lib STATIC IMPORTED)
>>     set_property(TARGET the_library.lib
>>       PROPERTY INTERFACE_LINK_OPTIONS
>> $<$<CONFIG:Debug>:/NODEFAULTLIB:libcmt>)
>>
>> In addition, there are two properties, COMPILE_FLAGS and COMPILE_OPTIONS,
>> with the difference that the latter understands generator expressions. I
>> also suggest adding a LINK_OPTIONS along the same lines.
>>
>> (Note that the INTERFACE_LINK_LIBRARIES property is designed to contain
>> both libraries and linker options. However, an entry is only interpreted as
>> an option if it starts with a "-", which is not the case for Visual Studio
>> options.)
>>
>> Sincerely,
>>     Anders Lindgren
>>
>>
>> --
>>
>> Powered by www.kitware.com
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Kitware offers various services to support the CMake community. For more
>> information on each offering, please visit:
>>
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140616/99373d4e/attachment.html>


More information about the CMake mailing list