linting_build.cmake 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. if(UA_ENABLE_STATIC_ANALYZER STREQUAL MINIMAL OR UA_ENABLE_STATIC_ANALYZER STREQUAL REDUCED OR UA_ENABLE_STATIC_ANALYZER STREQUAL FULL)
  2. # cpplint just gives warnings about coding style
  3. find_program(CPPLINT_EXE NAMES "cpplint")
  4. if(CPPLINT_EXE)
  5. set(CMAKE_C_CPPLINT "${CPPLINT_EXE};--quiet")
  6. set(CMAKE_CXX_CPPLINT "${CPPLINT_EXE};--quiet")
  7. endif()
  8. endif()
  9. if(UA_ENABLE_STATIC_ANALYZER STREQUAL REDUCED OR UA_ENABLE_STATIC_ANALYZER STREQUAL FULL)
  10. # clang-tidy has certain warnings as errors
  11. find_program(CLANG_TIDY_EXE NAMES "clang-tidy")
  12. if(CLANG_TIDY_EXE)
  13. set(CMAKE_C_CLANG_TIDY "${CLANG_TIDY_EXE};-p=compile_commands.json")
  14. set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE};-p=compile_commands.json")
  15. endif()
  16. elseif(UA_ENABLE_STATIC_ANALYZER STREQUAL FULL)
  17. # cppcheck provides just warnings but checks "all" (for now) - huge CPU impact
  18. find_program(CPPCHECK_EXE NAMES "cppcheck")
  19. if(CPPCHECK_EXE)
  20. set(CMAKE_C_CPPCHECK "${CPPCHECK_EXE};--project=compile_commands.json;--enable=all;--inconclusive;--inline-suppr;\
  21. --suppressions-list=${PROJECT_SOURCE_DIR}/cppcheck-suppressions.txt;-D__GNUC__;-i ${PROJECT_SOURCE_DIR}/build")
  22. set(CMAKE_CXX_CPPCHECK "${CPPCHECK_EXE};--project=compile_commands.json;--enable=all;--inconclusive;--inline-suppr;\
  23. --suppressions-list=${PROJECT_SOURCE_DIR}/cppcheck-suppressions.txt;-D__GNUC__;-i ${PROJECT_SOURCE_DIR}/build")
  24. endif()
  25. # "include what you use" requires additional configuration - ignore for now
  26. find_program(IWYU_EXE NAMES "iwyu")
  27. if(IWYU_EXE)
  28. #set(CMAKE_C_INCLUDE_WHAT_YOU_USE "${IWYU_EXE}")
  29. #set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU_EXE}")
  30. endif()
  31. endif()
  32. # adds new target "clangformat" to enforce clang-format rules
  33. find_program(CLANG_FORMAT_EXE NAMES "clang-format")
  34. if(CLANG_FORMAT_EXE)
  35. file(GLOB_RECURSE FILES_TO_FORMAT
  36. ${PROJECT_SOURCE_DIR}/arch/*.c
  37. ${PROJECT_SOURCE_DIR}/plugins/*.c
  38. ${PROJECT_SOURCE_DIR}/src/*.c
  39. ${PROJECT_SOURCE_DIR}/arch/*.h
  40. ${PROJECT_SOURCE_DIR}/include/*.h
  41. ${PROJECT_SOURCE_DIR}/plugins/*.h
  42. ${PROJECT_SOURCE_DIR}/src/*.h
  43. )
  44. add_custom_target(
  45. clangformat COMMAND ${CLANG_FORMAT_EXE}
  46. -style=file
  47. -i
  48. ${FILES_TO_FORMAT}
  49. )
  50. endif()