Need an option to skip system headers while generating dependencies
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
There is currently no way to tell cmake not to consider system headers while generating dependencies.
If the source file contain for example the following includes:
#include <iostream>
#include <boost/lexical_cast.hpp>
#include <tbb/atomic.hpp>
#include <unistd.h>
#include <sys/types.h>
#include "projectdir1/header1.h"
#include "projectdir2/header2.hpp"
#include "header3.h"
then CMake will try to find each of the file in the directories given by include_directories()
, which has a huge performance impact on build process when CMake happens to actually find the files (please note that CMake does not consider some system dirs like /usr/include
or /usr/include/c++/4.8
by default, and that's why the issue is somehow hidden. BTW. This is a really strange - why e.g. boost header from /usr/include
are treated differently than those ones from /opt/boost-1.55.0/include
?).
However the system header files do not change often, and can be ignored by CMake in a two ways:
- by ignoring the files that are #included inside the
< >
brackets - by ignoring directories that are marked as SYSTEM ones during scanning for files (it could by some new property like NOT-FOR-DEPS instead of SYSTEM), just like
g++ -MM
does (and you know, g++ provides such an option for a reason...)
I assume there might be some projects that require dependencies for system headers, so that features need to be configurable. And yes, in my opinion it would be nice to have both of the features implemented, it really shouldn't be a rocket science.
The currently provided features does not fix the issue:
-
include_regular_expression()
is not a solution, as it's hardly possible to enumerate all non-system headers with it; - the
fast
targets are not an option either, as they ignore all the dependencies, besides there is noall/fast
target (see also https://blogs.kde.org/2006/08/06/working-cmake-dependency-hell) - there is
INCLUDE_REGEX_LINE
variable in CMake sources, but it seems to be hardcoded, cannot be changed by user.
See also #2607 (closed), #8777 (closed), and #17676 (closed).