specifying link flags for only one static lib while linking executable

This thread Linking static libraries into shared libs? has a method for that.

SET (MYLIB -Wl,--whole-archive my_particular_lib -Wl,--no-whole-archive)
....
TARGET_LINK_LIBRARIES(yourtarget ${normalstuff} ${MYLIB} ${othernormalstuff})

The CMake docs state:

If a library name matches that of another target in the project a dependency will automatically be added in the build system to make sure the library being linked is up-to-date before the target links. Item names starting with '-', but not '-l' or '-framework', are treated as linker flags.

So the -Wl options should not interfere/be touched by CMake.


TARGET_LINK_LIBRARIES(myTarget -Wl,--whole-archive myLib -Wl,--no-whole-archive)

Simply replace myTarget and myLib

Oryginal post: https://stackoverflow.com/a/37564428/1052261

Tags:

Cmake