Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Headers processing

Filtering header content

A C/C++ header can contains different zone, some of which are parts of the public API, and some of which may correspond to specific low-level options.

litgen (and srcmlcpp) can filter a header based on preprocessor #ifdef, #ifndef and #if occurrences.

For #if, the macro name referenced in the condition is matched against header_filter_acceptable__regex, exactly like #ifdef: both #if MY_OPTION and #if defined(MY_OPTION) are filtered on the name MY_OPTION (this is a name match, not an evaluation of the macro’s value).

Within an accepted region, only the primary branch is kept: the content of #else and #elif branches is dropped (their #else / #elif / #endif markers themselves remain).

Let’s look at an example header: its code is defined in the cpp_code variable below.

Let’s try to generate bindings for it:

Loading...

We see that elements inside #ifdef ARCANE_OPTION were not processed (as desired). However, elements inside #ifdef COMMON_OPTION and #if defined(COMMON_OPTION) were also not processed, even though we would like to publish them. Let’s correct this by adjusting the options:

Loading...

API Prefixes

In a given header files, function can have an “API Prefix”, that denotes whether they should be published or not in a shared library.

You can set the API marker in the options:

Loading...

You can also decide to export non API function, with an optional comment.

Loading...

Header preprocessing

If you need to preprocess header code before the generation, you can create a function that transforms the source code, and store it inside options.srcmlcpp_options.code_preprocess_function.

For example:

Loading...