GCC can display all header dependencies of a .cpp file in a tree structure if the -H option is passed. It's a very handy feature because
1) it produces the output after/while evaluating the defines passed in the -D parameter,
2) it uses the same include paths which would be used during compilation.
There is one problem with its behavior which is very frustrating. If the content of an included header file evaluates to empty string during repeated inclusion (because of the content being enclosed in an #ifndef statement), then the included header file name is not listed as a dependency of the parent header file.
I will add a very brief example here:
// main.cpp
#include "header1.h"
int main(void) {
return 0;
}
// header1.h
#ifndef header1_h
#define header1_h
#include "header2.h"
#include "header3.h"
#endif
// header2.h
#ifndef header2_h
#define header2_h
#include "header3.h"
#endif
// header3.h
#ifndef header3_h
#define header3_h
void header3_function1(void);
#endif
I would expect this as correct output of "gcc.exe -H -c main.cpp":
. header1.h
.. header2.h
... header3.h
.. header3.h
Actual output:
. header1.h
.. header2.h
... header3.h
So I think that header3.h should be listed as a dependency of header1.h as well, even though its contents evaluate to empty string at that specific point.
Is there any way to force GCC to display the missing nodes in the tree?
Note 1: Displaying the missing nodes would not introduce any amounts of redundancy in the tree because even if header3.h had a large dependency subtree, it would not be listed in the output more than once because of the #ifndef statement.
Note 2: I have one work-around which is not an acceptable solution. If I append a dummy #define line at the end (outside the #ifndef block) of each header file in the application, then the missing nodes will appear. (But obviously modifying a large number of files in a repository - including built-in system headers - is not acceptable as a solution.)
Thanks.