Search code examples
doxygen

Is it possible for Doxygen to exclude undocumented functions from generated XML?


I want to generate documentation only for code that has Doxygen comments. I have created a Doxyfile via Doxygen version 1.8.9.1 and configured it to output only XML and to hide all undocumented code:

GENERATE_HTML          = NO
GENERATE_LATEX         = NO
GENERATE_XML           = YES
HIDE_UNDOC_MEMBERS     = YES
HIDE_UNDOC_CLASSES     = YES

After that I created a simple C header test.h with one documented and one non-documented function declaration:

void foo(int a);

/**
 * "bar" function description
 * @param b sample param
 */
void bar(int b);

By executing doxygen I expected only documentation for bar to be included in the resulting XML. Unfortunately, documentation for both functions is generated. Is it possible to generate documentation only for code that has Doxygen comments? Or will Doxygen always include everything in the XML output regardless of settings?


Solution

  • Before reading any further make sure EXTRACT_ALL is set to NO.

    I'm not a fan of the following solution but it does work. Use doxygen's preprocessor

    #ifdef PROJECT_NO_DOC
    void foo(int a); 
    #endif /* PROJECT_NO_DOC */
    
    /**
     *  * "bar" function description
     *   * @param b sample param
     *    */
    void bar(int b); 
    

    Note, in their docs you have to set a PREDEFINED macro but at least in my version of doxygen this was not required. Their docs specify to do it this way set a predefined macro in the config to do it for you

    #ifndef DOXYGEN_SHOULD_SKIP_THIS
    
     /* code that must be skipped by Doxygen */
    
    #endif /* DOXYGEN_SHOULD_SKIP_THIS */
    

    around the blocks that should be hidden and put:

    PREDEFINED = DOXYGEN_SHOULD_SKIP_THIS
    

    in the config file then all blocks should be skipped by doxygen as long as

    ENABLE_PREPROCESSING = YES
    

    There are other methods but they come with additional constraints ie to make sure no static method appear in your public docs you can set EXTRACT_STATIC to NO.