6
votes

I want to include the #defines from a h file for parsing of all other files with Doxygen.


Project background:

My C project includes a header file config.h on it's the build command.

It also defines a target MODEL_A on the same build command.

config.h creates defines depending on the target being built (not the same lists of defines for MODEL_A as for MODEL_B):

#if defined(MODEL_A)
#define HAS_FUNCTIONALITY_1
#define HAS_FUNCTIONALITY_2
#elif defined(MODEL_B)
#define HAS_FUNCTIONALITY_3
#define HAS_FUNCTIONALITY_4
#endif 

My issue with Doxygen:

I try to generate documentation with Doxygen. I have in the Doxyfile:

# including of config.h to INPUT seems necessary.
INPUT = ./source/config.h \
    ./source
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = NO
INCLUDE_PATH = ./source
INCLUDE_FILE_PATTERNS = ./source/config.h
PREDEFINED = MODEL_A

The code that is dependent on the defines HAS_FUNCTIONALITY_x is not included in the documentation, as if the preprocessor did not get the defines in config.h.


My findings so far:

I inspected the preprocessor output with help of doxygen -d Preprocessor, and could see that:

  • ./source/config.h was parsed first, and correctly according to MODEL_A (I can see the correct #defines in the preprocessor output). #define HAS_FUNCTIONALITY_1 figures in the preprocessor output.
  • the preprocessing of C files which depend on HAS_FUNCTIONALITY_1 act as if it was not defined.

Defining HAS_FUNCTIONALITY_1 in the field PREDEFINED of the Doxyfile works as expected. This is not a practical solution, but still interesting.


How do I make sure that the #define rows that are preprocessed first from config.h stay defined when the preprocessor works on all subsequent C files?

2
Is it an autotools project? If it is inclusion of config.h is usually conditional: #if HAVE_CONFIG_H #include <config.h>#endif So one has to set PREDEFINED = HAVE_CONFIG_H. I generated some documentation for code which conditionally defines two functions depending on libxml2 availability and after modifying PREDEFINED the documentation was generated. Doxygen 1.8.8-5. - wodny
Did you find an answer to this? I'm in the exact same situation and currently losing hope after looking at various threads on the web. - sahiljodhwani

2 Answers

0
votes

It would probably be beneficial for you to show the C code itself. In general, Doxygen runs a standard preprocessor - i.e. the rendered code should be the same as if the compiler preprocessed it. In order to achieve the equivalent of #define HAS_FUNCTIONALITY_1 in the code - it has to be defined. I understand from your reluctance to add it to the doxygen configuration that it is defined somewhere else in the project (or perhaps the Makefile) and that that is the reason that the actual code acts as though it was defined. If this is the case, I don't see a plausible workaround other than more preprocessor trickery or simply adding it in the doxygen config file.

0
votes

I ran into a very similar issue.

My headers were in a different directory from my source, e.g.:

doxy_input_dir/
    |
    + src/
    |
    + inc/

I had RECURSIVE input file option set to YES. I assumed the preprocessor would correctly find my headers. However, when I viewed the preprocessor output by running doxygen -d Predefined <doxyfile> I saw a lot of #include foo.h: not found! skipping....

The solution was to specify all of the header directories explicitly using the INCLUDE_PATH tag.