Use CMAKE_*_FLAGS_INIT variables to initialize flags
The proper way of presetting compiler and linker flags in a toolchain is to use the special CMAKE_*_FLAGS_INIT variables, which are used by CMake to initialize the matching CMAKE_*_FLAGS variables on initial configuration.
I also added the linker flags -Wl,--as-needed -Wl,--no-undefined for libraries.