10

As suggested here, I have some parts in my code, that are enabled by a compilation flag.

For example I have this piece of code:

#ifdef MYPROJ_HAS_BOOST
  ...
#endif

Doxygen will leave them out, because they are omitted, since MYPROJ_HAS_BOOST is not defined. I solved it, with adding a #define MYPROJ_HAS_BOOST.

However this is not nice, because in the future (I am planning to extend the project), when the time comes to re-generate my documentation, maybe I will have forgotten about this.

Is there any way to say to Doxygen (ideally via doxywizard) to take into account these parts of my code too?

usr1234567
  • 19,156
  • 14
  • 105
  • 120
gsamaras
  • 69,751
  • 39
  • 173
  • 279

4 Answers4

14

In your Doxyfile (or whatever you've renamed it to) add the lines

PREDEFINED = MYPROJ_HAS_BOOST

You can also do this in doxywizard by setting the variable PREDEFINED to include MYPROJ_HAS_BOOST.

randomusername
  • 7,559
  • 20
  • 46
  • Didn't check it, but probably will work. However, then I may change me flag and the setting will go to waste. +1 though, since I might (for some reason which I can't think now) want to take into account only the parts with `MYPROJ_HAS_BOOST`. – gsamaras Sep 25 '14 at 16:14
13

I think you just need to disable preprocessing at all by setting ENABLE_PREPROCESSING to NO in doxygen configuration file.

In doxywizard go to Expert -> Preprocessor and you will find ENABLE_PREPROCESSING. Just uncheck it to set it to NO.

More information about preprocessing in doxygen can be found in documentation here.

albert
  • 7,283
  • 3
  • 16
  • 31
afenster
  • 3,225
  • 16
  • 23
9

My understanding today is, that doxygen supports the defines. In your case you should enable

ENABLE_PREPROCESSING = YES

and set

PREDEFINED = MYPROJ_HAS_BOOST

or

PREDEFINED = MYPROJ_HAS_BOOST=1

If you want to reverse it (as you wanted it in your example) change to

PREDEFINED = MYPROJ_HAS_BOOST=0

Is is explained in more details here.

albert
  • 7,283
  • 3
  • 16
  • 31
musbach
  • 468
  • 1
  • 7
  • 25
  • Thanks for the answer, I didn't test it, but it seems OK. – gsamaras May 27 '16 at 18:09
  • This worked for me. I like it because it is precise and does not require changing the source code at all: you need only add a line to `Doxyfile.in` with the macro you wish to define; everything else is left the same. Note: this works for C as well as C++. – Liam Aug 13 '21 at 15:46
6

Doxygen defines the macro DOXYGEN which you can use.

#if defined(MYPROJ_HAS_BOOST) || DOXYGEN
  ...
#endif

If you have many macros, it might be easier to add the Doxygen macro then to sync your macros with the one in the Doxyfile.

usr1234567
  • 19,156
  • 14
  • 105
  • 120
  • 1
    Good for a quick solution. However, I have one macro, but in several places. +1 for the simplicity though (in the trade off of power of solution). – gsamaras Sep 25 '14 at 16:15
  • This did not work for me. Also, it requires changing the source code, which some may consider a negative. – Liam Aug 13 '21 at 15:47