CLion 无法解析所有宏

CLion doesn't resolve all macros

我有 5 个文件(+ 生成文件):

conf.h 通过 makefile 间接包含。

问题是 CLion 可以解析 conf.h 中定义的宏(通过转到声明),但它不会将它们用于突出显示。这意味着带有 #if 的部分总是折叠并突出显示为注释。您可以在 hello_world.c.

中看到该行为

是否可以以考虑此类声明的方式配置 CLion,或者至少禁用折叠和 'comment'-高亮显示? 请记住,不可能摆脱 makefile 因为它是一个具有复杂设置的巨大项目。 (original source)

可以在此处找到简化示例的源文件:https://gist.github.com/Benedikt1992/05d01948ed1638e656b1dfbad244337c

更新: 基本问题的简化和澄清

如果你刚才这么说...

The conf.h is indirectly included via the makefile.

...首先,我们可能会节省很多时间。但是,为了澄清我在说什么,因为您忘记将 MCVE 直接放入问题中,这里的代码显示了您的意思:

hello_world.h:

#ifndef SAMPLE_HELLO_WORLD_H
#define SAMPLE_HELLO_WORLD_H

/* PROJECT_CONF_H might be defined in the project Makefile */
#ifdef PROJECT_CONF_H
#include PROJECT_CONF_H
#endif /* PROJECT_CONF_H */

void hello_world();

#endif //SAMPLE_HELLO_WORLD_H

... 其中 PROJECT_CONF_H 未在源代码中的任何位置定义,而是通过 Makefile 中指定的编译器 command-line 选项定义。

不管怎样,你问:

The problem is that CLion can resolv the macros defined in conf.h (via go to declaration) but it doesn't consider them for highlightning.

我认为您是想说在包含 hello_world.h 的文件中,CLion 的代码突出显示机制无法识别通过 Makefile 命名的文件中的任何声明(特别是宏定义) PROJECT_CONF_H.

Which means the parts with #if are always collapsed and highlighted as comments. You can see that behaviour within hello_world.c.

Is it possible to configure CLion in a way that it considers such declarations or at least to disable the collapsing and 'comment'-highlightning?

尽管 CLion 很可能可以配置为禁用被预处理器条件抑制的折叠代码部分,但很难将此问题归咎于 CLion。很可能它只分析你的源文件,而不是你的 Makefile,所以就它而言,你的配置 header 确实从未包括在内。它知道 header 在 那里 ,所以其中的符号在它的索引中,仅此而已。

此时我观察到像 present 这样的代码结构非常不寻常。具体来说,通过 header 文件提供 build-time 配置数据的构建系统通常确保 header 始终存在,具有相同的名称,并通过设置其 内容进行操作 根据需要在 pre-build 配置步骤中(或要求人员手动执行)。

Keep in mind it is not possible to get rid of the makefile since it's a huge project with a complex setup.

make 是一个了不起的工具。没有理由要转储 make 或 Makefile。但是你应该考虑改变这方面的工作方式。