views:

101

answers:

3

Is it possible to document preprocessor defines in Doxygen? I expected to be able to do it just like a variable or function, however the Doxygen output appears to have "lost" the documentation for the define, and does not contain the define its self either.

I tried the following

/**My Preprocessor Macro.*/
#define TEST_DEFINE(x) (x*x)

and

/**@def TEST_DEFINE

   My Preprocessor Macro.
*/
#define TEST_DEFINE(x) (x*x)

I also tried putting them within a group (tried defgroup, addtogroup and ingroup) rather than just at the "file scope" however that had no effect either (although other items in the group were documented as intended).

I looked through the various Doxygen options, but couldn't see anything that would enable (or prevent) the documentation of defines.

A: 

Try setting EXTRACT_ALL option, I have that set in my project and it generates documentation for #defines. There might be a more elegant way of doing it without using EXTRACT_ALL so be sure to check the documentation

http://www.doxygen.nl/config.html#cfg_extract_all

Sam Post
+4  A: 

Yes, it is possible. The Doxygen documentation says:

To document global objects (functions, typedefs, enum, macros, etc), you must document the file in which they are defined. In other words, there must at least be a

/*! \file */

or a

/** @file */

line in this file.

You can use @defgroup, @addtogroup, and @ingroup to put related items into the same module, even if they appear in separate files (see documentation here for details). Here's a minimal example that works for me (using Doxygen 1.6.3):

Doxyfile:

# Empty file.

Test.h:

/** @file */

/**My Preprocessor Macro.*/ 
#define TEST_DEFINE(x) (x*x) 

/**
 * @defgroup TEST_GROUP Test Group
 *
 * @{
 */

/** Test AAA documentation. */
#define TEST_AAA (1)
/** Test BBB documentation. */
#define TEST_BBB (2)
/** Test CCC documentation. */
#define TEST_CCC (3)
/** @} */

Foo.h:

/** @file */

/**
 * @addtogroup TEST_GROUP
 *
 * @{
 */

/** @brief My Class. */     
class Foo {
    public:
        void method();
};

/** @} */

Bar.h:

/** @file */

/**
 * @ingroup TEST_GROUP
 * My Function.
 */
void Bar();

In this case, the TEST_DEFINE documentation appears in the Test.h entry under the Files tab in the HTML output, and the TEST_AAA etc. definitions appear under Test Group in the Modules tab together with class Foo and function Bar.

One thing to note is that if you put the file name after the @file command, e.g:

/** @file Test.h */

then this must match the actual name of the file. If it doesn't, documentation for items in the file won't be generated.

An alternative solution, if you don't want to add @file commands, is to set EXTRACT_ALL = YES in your Doxyfile.

I hope this helps!

ChrisN
Does that mean there is no way to put them in a group/module? Thats what I'm really trying to do so that they are along with the functions / classes / etc they are related to (there spread over several files as well).
Fire Lancer
Hi Fire Lancer, I've added some detail about grouping to my answer
ChrisN
Ok, I got it to work in an addtogroup or defgroup block. ingroup seems to loose the define somewhere (defgroup is in a .cpp with the group main docs, and everything except the defines in the header is getting put in the group fine)...I'm guessing that must be some kind of bug on Doxygens part?
Fire Lancer
Curious. I tried the setup you describe and it works OK for me. Without seeing your code it's hard to know what to suggest.
ChrisN
A: 

In my "C" files, I use a comment format and #define line like this:

/** @brief Number of milli-seconds to wait*/
#define kTimeoutMSec (2)

My html documents do end up containing documentation I specify. (I do have @file at the top of the file and EXTRACT_ALL=YES)

Jim Chargin