'Include both #ifdef and #else code in doxygen output

If have code in the following format:

#ifdef MY_DEFINE
    ///some doxy comment
#else
    ///other doxy comment
#endif

MY_DEFINE is defined at compile time. My issue is that when doxy processes the code above, only "other doxy comment" is handled. Defining MY_DEFINE in the doxyfile makes it so "some doxy comment" is handled. I need both doxy comments to make it into the doxygen output.

Is there a simple catch all configuration I can add to the doxyfile?

The doxygen generation needs to be run on different machines, so something not needing additional installation is preferred. There are other #define statements which need to be handled by doxygen, so setting ENABLE_PREPROCESSING to NO is not enough.

Thanks!



Solution 1:[1]

You can set ENABLE_PREPROCESSING=YES, then add a predefined symbol PREDEFINED=DOXYGEN

Then you can:

#if defined(MY_DEFINE) || defined(DOXYGEN)
/// if defined
#endif

#if !defined(MY_DEFINE) || defined(DOXYGEN)
/// if not defined
#endif

The drawback is that you cannot use #else. Also Doxygen gets confused if the same symbol is defined to be two different things on different preprocessor settings.

If you disable ENABLE_PREPROCESSING you cannot document #define's in your headers.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Calmarius