CMake: Linking statically against libgcc and libstdc++ into a shared library
As of cmake 3.13, there is a new cmake function for general linker options:
https://cmake.org/cmake/help/v3.13/command/target_link_options.html
target_link_options(<target> [BEFORE]
<INTERFACE|PUBLIC|PRIVATE> [items1...]
[<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
The appropriate way to specify libraries to be linked is still:
https://cmake.org/cmake/help/v3.13/command/target_link_libraries.html
target_link_libraries(<target>
<PRIVATE|PUBLIC|INTERFACE> <item>...
[<PRIVATE|PUBLIC|INTERFACE> <item>...]...)
There are a few different signatures depending on whether or not you want these libraries to be propagated to dependent targets, so be sure to check the docs.
Yes, target_link_libraries
is a correct way to set linker flags or linker options.
Documentation of target_link_libraries
:
Specify libraries or flags to use when linking a given target.
Item names starting with -, but not -l or -framework, are treated as linker flags.
https://cmake.org/cmake/help/v3.0/command/target_link_libraries.html (emphasis not in original)