How to ignore generated code in doxygen

762 views Asked by At

So, we are using doxygen in a big project.

Some of the source code is generated during the build, like my_generated_code_fragment.h

It is used in the source code, like this

file foo.cc

void foo()
{
#include "my_generated_code_fragment.h"
}

Now, when running doxygen from the repository under source control, doxygen rightly complain that file my_generated_code_fragment.h is missing, with an error like:

foo.cc:1234: warning: include file my_generated_code_fragment.h not found, perhaps you forgot to add its directory to INCLUDE_PATH?

Problem

We don't want to perform a full build first, just to generate the missing files, in order to generate documentation. Note that the generated code does not contain doxygen comments anyway.

Solution considered so far

  1. Do Nothing

Do nothing and ignore doxygen errors. Not really satisfactory.

  1. Generate dummy files

Generate dummy files like my_generated_code_fragment.h prior to running doxygen.

This creates complications in the build scripts, where "using doxygen" is now different on different projects, because the files containing generated code differs.

  1. Use preprocessor flags

Change the code to

void foo()
{
#ifndef IN_DOXYGEN
#include "my_generated_code_fragment.h"
#undef IN_DOXYGEN
}

and set PREDEFINED

This is the best solution considered so far, but it means changing the code.

Question

Is there a better option, like tell doxygen using a setting in Doxyfile that file my_generated_code_fragment.h is expected to be missing, and should be ignored ?

Note:

EXCLUDE does not work for this, as the error is seen when parsing file foo.cc, not when parsing the generated code.

Using doxygen version 1.8.5 at the moment.

1

There are 1 answers

0
Marc Alff On BEST ANSWER

Documenting the solution taken then.

Solution 3, to use pre-processor flags when building with doxygen, and changing the (small) parts of the code that uses generated content worked well.

This allows to use doxygen on "raw" source code, pulled from git.