包含用于使用Doxygen预处理器解析所有其他文件的头文件

时间:2021-10-10 15:08:35

I want to include the #defines from a h file for parsing of all other files with Doxygen.

我希望包含来自h文件的#define,用于使用Doxygen解析所有其他文件。


Project background:

项目背景:

My C project includes a header file config.h on it's the build command.

我的C项目包含一个头文件配置。h是build命令。

It also defines a target MODEL_A on the same build command.

它还在同一个构建命令中定义了一个目标MODEL_A。

config.h creates defines depending on the target being built (not the same lists of defines for MODEL_A as for MODEL_B):

配置。h根据正在构建的目标创建定义(与MODEL_A和MODEL_B的定义列表不同):

#if defined(MODEL_A)
#define HAS_FUNCTIONALITY_1
#define HAS_FUNCTIONALITY_2
#elif defined(MODEL_B)
#define HAS_FUNCTIONALITY_3
#define HAS_FUNCTIONALITY_4
#endif 

My issue with Doxygen:

我的问题与Doxygen:

I try to generate documentation with Doxygen. I have in the Doxyfile:

我尝试用Doxygen生成文档。我在Doxyfile中有:

# including of config.h to INPUT seems necessary.
INPUT = ./source/config.h \
    ./source
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = NO
INCLUDE_PATH = ./source
INCLUDE_FILE_PATTERNS = ./source/config.h
PREDEFINED = MODEL_A

The code that is dependent on the defines HAS_FUNCTIONALITY_x is not included in the documentation, as if the preprocessor did not get the defines in config.h.

依赖于定义HAS_FUNCTIONALITY_x的代码不包含在文档中,就好像预处理程序在config.h中没有得到定义一样。


My findings so far:

我的发现:

I inspected the preprocessor output with help of doxygen -d Preprocessor, and could see that:

我借助doxygen -d预处理器检查了预处理器输出,可以看到:

  • ./source/config.h was parsed first, and correctly according to MODEL_A (I can see the correct #defines in the preprocessor output). #define HAS_FUNCTIONALITY_1 figures in the preprocessor output.
  • / /配置源。首先解析h,并正确地根据MODEL_A(我可以在预处理程序输出中看到正确的#定义)。#在预处理器输出中定义HAS_FUNCTIONALITY_1图。
  • the preprocessing of C files which depend on HAS_FUNCTIONALITY_1 act as if it was not defined.
  • 依赖HAS_FUNCTIONALITY_1的C文件的预处理就好像没有定义它一样。

Defining HAS_FUNCTIONALITY_1 in the field PREDEFINED of the Doxyfile works as expected. This is not a practical solution, but still interesting.

在Doxyfile预定义的字段中定义HAS_FUNCTIONALITY_1可以正常工作。这不是一个实用的解决方案,但仍然很有趣。


How do I make sure that the #define rows that are preprocessed first from config.h stay defined when the preprocessor works on all subsequent C files?

如何确保#定义首先从配置中预处理的行。当预处理程序在所有后续的C文件上工作时,h保持定义?

1 个解决方案

#1


0  

It would probably be beneficial for you to show the C code itself. In general, Doxygen runs a standard preprocessor - i.e. the rendered code should be the same as if the compiler preprocessed it. In order to achieve the equivalent of #define HAS_FUNCTIONALITY_1 in the code - it has to be defined. I understand from your reluctance to add it to the doxygen configuration that it is defined somewhere else in the project (or perhaps the Makefile) and that that is the reason that the actual code acts as though it was defined. If this is the case, I don't see a plausible workaround other than more preprocessor trickery or simply adding it in the doxygen config file.

展示C代码本身可能对您有好处。通常,Doxygen运行一个标准的预处理器——也就是说,呈现的代码应该与编译器预处理的代码相同。为了在代码中实现#define HAS_FUNCTIONALITY_1的等效,必须定义它。我理解您不愿意将它添加到doxygen配置中,因为它是在项目中的其他地方(或者可能是Makefile)中定义的,这就是为什么实际的代码好像是被定义的。如果是这样的话,我没有看到其他可行的解决方案,除了使用更多的预处理程序或者只是在doxygen配置文件中添加它。

#1


0  

It would probably be beneficial for you to show the C code itself. In general, Doxygen runs a standard preprocessor - i.e. the rendered code should be the same as if the compiler preprocessed it. In order to achieve the equivalent of #define HAS_FUNCTIONALITY_1 in the code - it has to be defined. I understand from your reluctance to add it to the doxygen configuration that it is defined somewhere else in the project (or perhaps the Makefile) and that that is the reason that the actual code acts as though it was defined. If this is the case, I don't see a plausible workaround other than more preprocessor trickery or simply adding it in the doxygen config file.

展示C代码本身可能对您有好处。通常,Doxygen运行一个标准的预处理器——也就是说,呈现的代码应该与编译器预处理的代码相同。为了在代码中实现#define HAS_FUNCTIONALITY_1的等效,必须定义它。我理解您不愿意将它添加到doxygen配置中,因为它是在项目中的其他地方(或者可能是Makefile)中定义的,这就是为什么实际的代码好像是被定义的。如果是这样的话,我没有看到其他可行的解决方案,除了使用更多的预处理程序或者只是在doxygen配置文件中添加它。