Ninja: LINK_WHAT_YOU_USE fails with LDFLAGS=-Wl,--as-needed
When `CMAKE_LINK_WHAT_YOU_USE` is ON, CMake will generate link command with `-Wl,--no-as-needed` flag. However, CMake generates different link command for "Unix Makefiles" and Ninja generators. * "Unix Makefiles" will have that flag appended to the end of linker's flags * Ninja will have that flag appended to the end of FLAGS aka compiler's flags When `-Wl,--as-needed` is specified in `LDFLAGS` (as seen in most distro nowaday), the link command generated by `-GNinja` will have `-Wl,--as-needed` cancels CMake's `-Wl,--no-as-needed`. See: https://bugs.gentoo.org/596460 # Step to Reproduce: ```sh mkdir build cd build cmake -DCMAKE_BUILD_TYPE=None -DCMAKE_USE_SYSTEM_LIBRARIES=ON -GNinja .. ninja ctest -R RunCMake.LinkWhatYouUse ``` # Expected Result Test Passed # Actual Result Test Failed Linked to !6263
issue