It is crucial not to add unsupported compiler options because they can cause CMake's check_<lang>_compiler_flags macro to fail, causing problems like https://bugs.kde.org/show_bug.cgi?id=401018.
To prevent this, run an actual test when using clang on Mac.
This is almost unavoidable because determining compiler flag availability from compiler ID + version can be tricky to near impossible on Mac. Apple's llvm version numbers that are ahead of stock llvm versions and not easy to match. In addition, not all cmake versions distinguish between stock clang and "AppleClang" and those that do need policy CMP0025 set to NEW. That policy cannot be set after the project statement in the toplevel cmake file (= not in an ECM module).
This patch introduces a set of macros to simplify writing reliable conditional code for adding compiler flags. If will do the usual compiler ID + version checking to determine if a flag should be supported; when using Clang on Mac it will in addition use check_<lang>_compiler_flag(). This should be safe because Apple's llvm versions have always been ahead of stock versions; false negatives should thus never occur.
The C++ version of the new macro is used where possible.
BUG: 401018