Sergio Losilla
Sergio Losilla

Reputation: 850

CMAKE_CXX_CLANG_TIDY: avoid clang-diagnostic-error interrupting build

I am building a C++ project using clang-tidy as linter (cmake -DCMAKE_CXX_CLANG_TIDY=clang-tidy).

After updating my system (Fedora 28->29, cmake 3.11->3.12 I believe), I cannot build any more when clang-tidy reports some clang-diagnostic-error (which I cannot fix right now...). I am pretty sure that clang-diagnostic-error's did not interrupt the build earlier... But I cannot be hundred percent sure.

Edit: The change happened in clang-tidy, now it returns a non-zero exit code when errors are found.

Is it possible to suppress those errors, something like the opposite of "-warnings-as-errors"?

Upvotes: 4

Views: 2799

Answers (1)

Sergio Losilla
Sergio Losilla

Reputation: 850

Not sure if a solution or a workaround, but this does the trick (in my OS...):

cmake -DCMAKE_CXX_CLANG_TIDY="${PATH_TO_SCRIPT}/suppress_exit_status.sh;clang-tidy"

PATH_TO_SCRIPT to script is the absolute path to suppress_exit_status.sh, which looks like:

#!/bin/sh
$@||echo Command \"$@\" failed with exit code $?

|| is the "or" operator, the second operands is only executed if the first one fails. It seems that cmake captures standard error from the command and throws it way, hence the error message.

I could not figure out a more elegant way to do this, it is not possible to throw || directly into CMAKE_CXX_CLANG_TIDY.

Upvotes: 2

Related Questions