Include a header file to parse all other files using the Doxygen preprocessor

I want to include #define from the h file to parse all other files using Doxygen.


Project background

My C project includes the config.h header file on it with the build command.

It also defines the target MODEL_A in the same build command.

config.h creates determines depending on the created target (not the same lists 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 problem with Doxygen:

I am trying to create documentation with Doxygen. I have a 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 

Code that depends on HAS_FUNCTIONALITY_x definitions is not contained in the documentation, as if the preprocessor had not received the definition in config.h .


My results so far:

I checked the preprocessor output with doxygen -d Preprocessor and could see that:

  • Was first analyzed
  • ./source/config.h and correctly according to MODEL_A (I can see the correct #defines at the output of the preprocessor). #define HAS_FUNCTIONALITY_1 digits in the output of the preprocessor.
  • preprocessing C files that depend on HAS_FUNCTIONALITY_1 acts as if it had not been defined.

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


How do I make sure that #define lines pre-processed from config.h remain defined when the preprocessor is running in all subsequent C files?

+4
source share
1 answer

It may be useful for you to show the C code itself. In general, Doxygen starts the standard preprocessor - that is, the visualized code should be the same as if the compiler had pre-processed it. To achieve the equivalent of #define HAS_FUNCTIONALITY_1 in the code - it must be defined. I understand from your unwillingness to add it to the doxygen configuration, which is defined somewhere else in the project (or, possibly, in the Makefile), and for this very reason the actual code acts as if it were defined. If so, I see no plausible workaround other than a more complex preprocessor or just adding it to the doxygen configuration file.

0
source

All Articles