Exclude third_party from clang-tidy checks - c++

I'm trying to run clang-tidy on a big project with a lot of files that include third party libraries:
#include "third_party/..."
And thus I receive a lot of errors corresponding to these third party libraries.
Adding NOLINT to each include is not an option since the project is large (and it seems that it doesn't work).
I tried to use -header-filter, but I still receive errors from third party libraries.
clang-tidy -header-filter='-third_party' "${SOURCE_FILES[#]}"
Is it possible to exclude third_party/* from checks?

You should flag these headers as system headers.
You can do this via
#pragma clang system_header
These headers will get ignored by clang-tidy and will produce no warnings.

Related

C++ compiler flag to ignore warnings for external libraries but without including directory

There are two ways, as far as I can tell, to ignore warnings for external libraries.
First way is to use #pragma:
#pragma gcc diagnostic ignored "-Wunused-parameter"
Second way is to add -isystem/path/to/system/lib to the compiler flags. This labels that particular include path as an external include path, and so the compiler will not emit warnings stemming from those includes.
I have a large project with many compilation targets, some of which use particular third party libraries which cause problems for my compiler. For reasons I cannot use the #pragma option.
But if I use the -isystem as a blanket compiler flag for all build targets, then I will unfortunately include /path/to/system/lib for every other build target, even those which do not use that system library. This means other targets will search through those external libraries, which is not desirable.
Is there a compiler option, similar to -isystem which can be added in a blanket way, which does not add to the search path, but only excludes warnings if the path happens to already be included in the search path?
I have a large project with many compilation targets, some of which use particular third party libraries which cause problems for my compiler. For reasons I cannot use the #pragma option.
Can you elaborate on this? Why is a wrapper header with #pragma GCC diagnostic not an option? That is, something like this:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include </path/to/real/include.h>
#pragma GCC diagnostic pop
(Or if you want to get fancy, use #include_next.) You would apply this only when crossing subsystem boundaries; the subsystem itself would be compiled with -Wunused-parameter.
I don't see anything in the GCC/libcpp sources which would allow one to reset the system header flag without adding a new system header. In any case, this looks to me like something which could be reasonably addressed within the build system.

Does adding many -isystem include directives slow down the compilation process significantly?

For our software project, we have around 15 third party library dependencies. We suppress the warnings in these third party libraries using the -isystem include directive.
Our software project consists of more than 10 executables and libraries, each having dependencies on a subset of the third party libraries. We compile with clang on mac.
An easy way to disable all third party warnings for all projects in our build system is to include all third party libraries in all projects with -isystem.
The alternative is to separately define for each of our projects the -isystem directive. This is more work to set up and will blow up the configurations of all project files, but only the third party libraries that are actually used are included.
I'd prefer to go with the first option because it's not much work, but I am not sure if this will significantly slow down the compilation process?
This flag will slowdown only standard headers search because prior each standard header is found it will also search it in your directories. So, that it depends on how many such directories you add and how many standard headers you use. For each standard header the impact will be a summ of:
time ls YOUR_DIR >> /dev/null 2>&1
for each your added directory.

Using boost without having to set up an environment

Is there a way to use C++ boost libraries without having the set up an environment?
I am trying to use boost::split but am getting errors because boost::split could not find other dependent files.
I know how to set up the environment with CMake/VS, but this is just a light weight utility program, so there's no need to do that.
Is there a way to just use boost libraries on the fly?
I am aware that much of boost is header-only, but I have received the following error, which is confusing me:
C:\Development\Libraries\boost_1_50_0\boost\algorithm\string.hpp:18:60: fatal error: boost/algorithm/string/std_containe
rs_traits.hpp: No such file or directory
compilation terminated.
Well, obviously this will only work for header-only libraries. You need more stuff for the boost-libraries that come with files to link.
Now, I'm doing just that: I use some of the boost header libraries, none of the link libraries, and I don't need any preparation for that. EXCEPT that boost includes some of its headers with <filename> instead of "filename", so you HAVE to add the boost library directory to the search path for include files. Nothing else should be required.
EDIT: except possibly for an adjustment to your warning settings. Unfortunately, boost is not "warning clear", which conflicts with my -Werror and /WX switches. I had to disable some warnings globally because there were just too many of them (and warning pragmas don't work with precompiled headers on all platforms), and fixed a few inside the boost headers.

How to eliminate external lib/third party warnings in GCC [duplicate]

This question already has answers here:
How to suppress GCC warnings from library headers?
(10 answers)
Closed 7 years ago.
In the software project I'm working on, we use certain 3rd party libraries which, sadly, produce annoying gcc warnings.
We are striving to clean all code of warnings, and want to enable the treat-warnings-as-errors (-Werror) flag in GCC.
Is there a way to make these 3rd party generated warnings, which we cannot fix, to disappear?
Use -isystem
Example:
gcc -I./src/ -isystem /usr/include/boost/ -c file.c -o obj/file.o
With -isystem NO warning about boost :D
If you're using CMake, you can achieve this by adding SYSTEM to include_directories:
include_directories(SYSTEM "${LIB_DIR}/Include")
^^^^^^
I presume you are talking about the warnings coming from the 3rd party library headers.
The GCC specific solution would be to create another wrapper header file which has essentially the two lines:
#pragma GCC system_header
#include "real_3rd_party_header.h"
And use the wrapper instead of the original 3rd party header.
Check another SO response detailing the pragma. It essentially tells GCC that this (with recursively included files) is a system header, and no warning messages should be generated.
Otherwise, I'm not aware how one can disable warnings coming from the 3rd party code. Except by the brute force of course: in the build system configure the files to be built with warnings off.
http://www.artima.com/cppsource/codestandards.html
Example 1: A third-party header file.
A library header file that you cannot
change could contain a construct that
causes (probably benign) warnings.
Then wrap the file with your own
version that #includes the original
header and selectively turns off the
noisy warnings for that scope only,
and then #include your wrapper
throughout the rest of your project.

Conditionally disable warnings with qmake/gcc?

I am involved with a software project written in Qt and built with qmake and gcc on Linux. We have to link to a third-party library that is of fairly low quality and spews tons of warnings. I would like to use -W -Wall on our source code, but pass -w to the nasty third-party library to keep the console free of noise and clutter so we can focus on our code quality.
In qmake, is there a way to conditionally add CFLAGS/CXXFLAGS to certain files and libraries?
Jonathan, I think the problem is where your source files are including header files from 3rd party libraries, and you want to switch off the warnings for the latter.
Kevin, i think you can use pragmas to control warnings : gcc diagnostic pragmas
You could add these before and after any #includes for 3rd party libs.
What if you include your library using -isystem.
In the project file e.g.:
QMAKE_CXXFLAGS += -isystem /usr/local/boost_1_44_0
Normally, you'd build the third-party library in a separate directory from your own code, so you would have a different makefile for it, so you could put a different set of flags for that compilation.
If you've mixed the third-party library code with your own code, you have set yourself up for a maintenance nightmare.
Kevin,
qmake CONFIG+=debug QMAKE_CXXFLAGS_WARN_ON=-w QMAKE_CFLAGS_WARN_ON=-w
should do
(use CONFIG+=release if you wish...)
As Martin wrote adding the include directory via
QMAKE_CXXFLAGS += -isystem ...
suppresses warnings just in the respective headers. No need to disable warnings for any source files of your project (or even project-wide) or mess with #pragmas or wrappers files.
Note that if you're using QtCreator you'll still (i.e. additionally) want add the directory to INCLUDEPATH so the indexer picks up the headers.