0

I am using CMake to run clang-tidy while compiling my embedded target.

if(CLANG_TIDY)
  set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
endif()

CMake sets the correct driver mode automatically:

--tidy="clang-tidy;--extra-arg-before=--driver-mode=g++"

But because this is an embedded target it has some arguments clang-tidy doesn't recognize.

I would expect it to compile normally and for clang-tidy to use that compilation database to lint the code.
Is there a setting missing?

The full error message is:

/cmake/bin/cmake -E __run_co_compile --tidy="clang-tidy;--extra-arg-before=--driver-mode=g++" --source=/workspaces/project/Core/Src/src/factorial.cpp -- /opt/gcc-arm-none-eabi/bin/arm-none-eabi-g++ -DARM_MATH_CM4 -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -DSTM32H723xx -DUSE_HAL_DRIVER -I/workspaces/project/Core/Inc -I/workspaces/project/Core/Src/src -I/workspaces/project/Drivers/CMSIS/Device/ST/STM32H7xx/Include -I/workspaces/project/Drivers/CMSIS/Include -I/workspaces/project/Drivers/STM32H7xx_HAL_Driver/Inc/Legacy -I/workspaces/project/Drivers/STM32H7xx_HAL_Driver/Inc -g -mcpu=cortex-m7 -ffunction-sections -fdata-sections -fno-common -fmessage-length=0 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Og -g -std=c++20 -MD -MT CMakeFiles/project.elf.dir/Core/Src/src/factorial.cpp.obj -MF CMakeFiles/project.elf.dir/Core/Src/src/factorial.cpp.obj.d -o CMakeFiles/project.elf.dir/Core/Src/src/factorial.cpp.obj -c /workspaces/project/Core/Src/src/factorial.cpp
[build] error: argument unused during compilation: '-mcpu=cortex-m7' [clang-diagnostic-unused-command-line-argument,-warnings-as-errors]
[build] error: argument unused during compilation: '-mfloat-abi=hard' [clang-diagnostic-unused-command-line-argument,-warnings-as-errors]
[build] error: argument unused during compilation: '-mfpu=fpv4-sp-d16' [clang-diagnostic-unused-command-line-argument,-warnings-as-errors]
[build] 4 warnings generated.
[build] Suppressed 2 warnings (1 in non-user code, 1 NOLINT).
[build] Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
[build] 3 warnings treated as errors
elhe
  • 122
  • 10

1 Answers1

0

You might want run clang-tidy in quiet mode, but it will also ignore other warnings.

if(CLANG_TIDY)
  set(CMAKE_CXX_CLANG_TIDY "clang-tidy" -quiet)
endif()
273K
  • 29,503
  • 10
  • 41
  • 64
  • This unfortunately did not help. The errors are shown just as before. I checked that the executed command by CMake includes `-quiet` and it does: `/cmake/bin/cmake -E __run_co_compile --tidy="clang-tidy;-quiet;--extra-arg-before=--driver-mode=g++" ` – elhe Feb 27 '23 at 14:22