linting_target.cmake 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. find_package(ClangTools)
  2. # clang-tidy uses the compile_commands.json file for include dirs and other config
  3. add_custom_target(clang-tidy ${CLANG_TIDY_PROGRAM}
  4. -p=compile_commands.json
  5. -format-style=file
  6. --
  7. ${lib_sources}
  8. DEPENDS ${lib_sources}
  9. COMMENT "Run clang-tidy on the library")
  10. add_dependencies(clang-tidy open62541)
  11. set_target_properties(clang-tidy PROPERTIES FOLDER "CodeAnalysis")
  12. add_custom_target(cpplint cpplint
  13. ${lib_sources}
  14. ${internal_headers}
  15. ${default_plugin_headers}
  16. ${default_plugin_sources}
  17. ${ua_architecture_headers}
  18. ${ua_architecture_sources}
  19. DEPENDS ${lib_sources}
  20. ${internal_headers}
  21. ${default_plugin_headers}
  22. ${default_plugin_sources}
  23. ${ua_architecture_headers}
  24. ${ua_architecture_sources}
  25. COMMENT "Run cpplint code style checker on the library")
  26. set_target_properties(cpplint PROPERTIES FOLDER "CodeAnalysis")
  27. # adds new target "clang-format" to enforce clang-format rules
  28. find_program(CLANG_FORMAT_EXE NAMES "clang-format")
  29. if(CLANG_FORMAT_EXE)
  30. file(GLOB_RECURSE FILES_TO_FORMAT
  31. ${PROJECT_SOURCE_DIR}/arch/*.c
  32. ${PROJECT_SOURCE_DIR}/plugins/*.c
  33. ${PROJECT_SOURCE_DIR}/src/*.c
  34. ${PROJECT_SOURCE_DIR}/arch/*.h
  35. ${PROJECT_SOURCE_DIR}/include/*.h
  36. ${PROJECT_SOURCE_DIR}/plugins/*.h
  37. ${PROJECT_SOURCE_DIR}/src/*.h
  38. )
  39. add_custom_target(
  40. clang-format COMMAND ${CLANG_FORMAT_EXE}
  41. -style=file
  42. -i
  43. ${FILES_TO_FORMAT}
  44. )
  45. endif()