[cmake-developers] Duplicated linking flags are removed when linking final executable

Sergio Checa Sergio.Checa at bmw-carit.de
Mon Mar 14 09:33:51 EDT 2016


Hello,

This is my first email to this list, so please tell me if I'm not following the contribution process properly.

Here is the scenario that I am working on:


                  .--->  -flags  A
                  |
    main ----> L -|
                  |
                  '--->  -flags  B

If "-flags" are the same text, only one occurrence appears in the resulting linking line in the target's generated link.txt.

This is a simple CMakeLists.txt that reproduces the above (doesn't build anything):

cmake_minimum_required(VERSION 3.5)

file(WRITE a.cpp "")
file(WRITE b.cpp "")
file(WRITE lib.cpp "")
file(WRITE main.cpp "")

add_library(A STATIC a.cpp)
add_library(B STATIC b.cpp)

add_library(L STATIC lib.cpp)

target_link_libraries(L
    -Wl,-whole-archive A -Wl,-no-whole-archive
    -Wl,-whole-archive B -Wl,-no-whole-archive
)

add_executable(main main.cpp)
target_link_libraries(main L)

When linking, only one occurrence of "-Wl,-whole-archive" and one of "-Wl,-no-whole-archive" are kept. The others are filtered out.

All the best,
Sergio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160314/b5f5204b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Duplicated-linking-flags-are-removed.patch
Type: text/x-patch
Size: 2806 bytes
Desc: 0001-Duplicated-linking-flags-are-removed.patch
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160314/b5f5204b/attachment.bin>


More information about the cmake-developers mailing list