warnings.cmake 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  2. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. # global additional warnings.
  4. if (MSVC)
  5. # warning level 4
  6. add_compile_options(/W4)
  7. else ()
  8. # refer to https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
  9. add_compile_options(
  10. -Wall -Wextra -Wformat -Wformat-security
  11. $<$<COMPILE_LANGUAGE:C>:-Wshadow>
  12. )
  13. # -pedantic causes warnings like "ISO C forbids initialization between function pointer and ‘void *’" which
  14. # is widely used in the codebase.
  15. #
  16. # -fpermissive causes warnings like "-fpermissive is valid for C++/ObjC++ but not for C"
  17. #
  18. # Reference:
  19. # - gcc-4.8 https://gcc.gnu.org/onlinedocs/gcc-4.8.4/gcc/Warning-Options.html
  20. # - gcc-11.5 https://gcc.gnu.org/onlinedocs/gcc-11.5.0/gcc/Warning-Options.html
  21. add_compile_options (
  22. $<$<COMPILE_LANGUAGE:C>:-Wimplicit-function-declaration>
  23. )
  24. # https://gcc.gnu.org/gcc-5/changes.html introduces incompatible-pointer-types
  25. # https://releases.llvm.org/7.0.0/tools/clang/docs/DiagnosticsReference.html#wincompatible-pointer-types
  26. # is the earliest version that supports this option I can found.
  27. # Assume AppClang versioning is compatible with Clang.
  28. if ((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "5.1")
  29. OR (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0.0")
  30. OR (CMAKE_C_COMPILER_ID STREQUAL "AppClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0.0"))
  31. add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wincompatible-pointer-types>)
  32. endif()
  33. # options benefit embedded system.
  34. add_compile_options (
  35. -Wdouble-promotion
  36. )
  37. # waivers
  38. add_compile_options (
  39. -Wno-unused
  40. -Wno-unused-parameter
  41. )
  42. endif ()