I’ve got an old project that uses the clang /Ox flag for certain configurations on Windows. According to the online clang documentation (Clang Compiler User’s Manual — Clang 11 documentation),
this flag is deprecated. However, clang doesn’t produce any warnings or errors when this flag is used.
I would like to configure CMake to warn me about “bad” compiler flags (on both windows and Linux and with clang and gcc), so /Ox for clang (which is deprecated), /Og on clang (which does nothing), and so on. The only way I can think of to do this is to trawl through the clang and gcc documentation, draw up my own blacklist of “bad” flags, and compare that against CMAKE_CXX_FLAGS and friends. Is there a better way?
Disclaimer: It’s really hard to google for this - mostly I just get advice about how to check for deprecated C++ features, which isn’t quite what I’m interested in.
Cmake has a CheckCompilerFlag module, but I believe that just checks if enabling a certain flag produces an error.
Really, I think the best answer is to just not deal with specific flags at all. CMake is meant to be a higher level of abstraction for describing your build requirements, and you let the cmake devs worry about the actual low level flags for each compiler.
But it’s also arguable that optimization flags are not part of the build requirements, and so should be turned on from outside the project, or controlled with an option