Now CMake has CMAKE_LINK_WHAT_YOU_USE
, simply set it to ON
before you create the target.
document:
https://cmake.org/cmake/help/latest/variable/CMAKE_LINK_WHAT_YOU_USE.html
and you can see its effect:
it will add -Wl,--no-as-needed
to link flags.