Arno Duvenhage
Arno Duvenhage

Reputation: 1960

How to set Visual-Studio LinkLibraryDependencies property to yes through CMAKE

When I generate a Visual Studio target with cmake, the generated project file contains the following in the platform properties section:

<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    ...
    <ProjectReference>
      <LinkLibraryDependencies>false</LinkLibraryDependencies>
    </ProjectReference>
    ...
</ItemDefinitionGroup>

I would like to set the property to true from the CMakeLists file. How do I do this?

My project dependencies are set up using TARGET_LINK_LIBRARIES, but on Linux I can also use, for example:

TARGET_LINK_LIBRARIES(${targetname} "-Wl,--whole-archive" *some libs* "-Wl,--no-whole-archive")

This forces all symbols to link into the target.

With visual studio the way to link all symbols is to specify:

<LinkLibraryDependencies>true</LinkLibraryDependencies>

through the project settings.

Upvotes: 1

Views: 3307

Answers (1)

Arno Duvenhage
Arno Duvenhage

Reputation: 1960

It seems like the 'Link Library Dependencies' and 'Use Library Dependency Inputs' flags are no longer required to link all lib symbols.

In Visual Studio 2015 you can no use the /WHOLEARCHIVE linker flag on the target. I edited my answer to a related question to give more detail on this:

https://stackoverflow.com/a/23799529/1151329

The flag works like the GCC -whole-archive linker flag.

In my CMAKE file I added this:

SET_TARGET_PROPERTIES(${targetname} PROPERTIES LINK_FLAGS_DEBUG "/WHOLEARCHIVE:debug_lib_name")
SET_TARGET_PROPERTIES(${targetname} PROPERTIES LINK_FLAGS_RELEASE "/WHOLEARCHIVE:release_lib_name")

Upvotes: 2

Related Questions