Enable clang-tidy on all samples
You should not exclude samples here, then we lose out on testing of many files. Tooling should omit diagnostics for the headers of system libraries, so all additional diagnosticas triggered by this proposal will be in our files and should be fixed.
Originally posted by @nedrebo in https://github.com/zivid/cpp-extra-samples/pull/85
@nedrebo,
We do not install Eigen, PCL nor OpenCV in our CI. That's why we don't run build them, and why I believe they're not linted.
When we run clang-tidy it uses CMakeLists.txt which will check whether (e.g.) Eigen is installed. Is there an acceptable way to skip this check when CMakeLists.txt is invoke with clang-tidy?
I tried the following and it works:
in lint.sh:
...
cmake -GNinja \
-DLINT_ONLY=ON \
-DUSE_EIGEN3=ON \
...
in CMakeLists.txt:
...
if(USE_EIGEN3)
if(LINT_ONLY)
message(Will lint Eigen3 samples, but do not require Eigen3 installed)
elseif(NOT DEFINED EIGEN3_INCLUDE_DIR)
...
Is this acceptable, or is there a better way.
Btw, I find that cmake remembers a variable set through -D if not set in a consecutive run. Maybe we should clear cmake-cache between runs? Or, is that some of what allows cmake to only rerun on changes?
I found -U :) So, we could just add:
...
cmake --build . || exit $?
cmake -ULINT_ONLY "$SOURCE_DIR" || exit $?
I am not sure I understand correctly what you ask for, but you must install all headers to be able to lint. Code that cannot compile successfully cannot be analyzed.
It sort of worked, although you're correct that it will throw an error on missing header. Were able to fix most other issues though. See https://github.com/zivid/cpp-extra-samples/pull/92.
Maybe this PR will have to wait until we've fixed the CI so that it installs these dependencies.
Yes, I think you should first make all dependencies available in CI, then you don't need to do the weird workaround.