[CMake] Transitive linker flags

Zaak Beekman zbeekman at gmail.com
Mon Apr 9 12:12:38 EDT 2018


Hi,

I'm defining a static library target and, conditionally, when on windows, I
need to pass a whole bunch of windows system libraries and tell Visual
Studio that any target linking against this static library should pass
additional linker flags ( `\NODEFAULTLIB:libcd \INCREMENTAL:NO` ). I tried
setting the LINKER_FLAGS property on the target with

    +  set_property(TARGET ECI_C
    +    PROPERTY
    +    APPEND
    +    LINK_FLAGS "${prefix}NODEFAULTLIB${colon}\"libcd\"")
    +    set_property(TARGET ECI_C
    +    PROPERTY
    +    APPEND
    +    LINK_FLAGS "${prefix}INCREMENTAL${colon}NO")

however, these flags did not seem to get transitively propagated to the
executable linking against this ECI_C static library. Am I doing something
wrong, or should I just specify the flags through the
`target_link_libraries( ECI_C INTERFACE FLAG1 FLAG2 )` command?  What's the
"right"/canonical way to do this?

Also, I'm extremely new to developing on Windows with MSVS, and I'm writing
CMake files to generate visual studio projects to more or less match some
that have been manually written. Without ignoring the `libcd` library I get
linker errors like

    error LNK2019: unresolved external symbol __imp_fopen

Which seems strange that I should have to ignore the standard C debug
library to fix. Without the `\INCREMENTAL:NO` flag I get warnings like

   warning LNK4217: locally defined symbol malloc imported in function
inittask

Are the manually written VS solution files or source code that I've
inherited doing something silly that requires these MSVS linker flags to be
set? It feels like this, along with the sheer quantity of system libraries
that are being passed to the linker may be a bit of a cludge. I'm
wondering, if it's worth spending my limited time investigating this
further or is this expected/common-practice/acceptable usage?

Thanks,
Zaak

Izaak "Zaak" Beekman

-------------------------------------------------------------------------------

HPC Scientist
ParaTools Inc. <http://www.paratools.com/>
1509 16th St, NW
Washington, DC 20036
mobile: (917) 797-3239
-------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180409/e31accd9/attachment.html>


More information about the CMake mailing list