Feature to allow multiple translation unit compilations of generated pure headers #1141
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The purpose of this PR is to allow including pure headers into multiple translation units without ODR violations.
First and foremost it splits
phase2_func_defs
intophase2_inline_defs
andphase3_regular_defs
. Produced .h file gets all declarations (as before), alias definitions and anything template-related, while the rest go to .hpp.A flag
-tu-compatible-h2
is added that stops generated hpp files from including other hpps as it is not necessary to produce a buildable source, but the default behaviour is unchanged. When using the flag it is important to include the resulting .hpp at least somewhere as it is never included automatically.With a simple-ish cmake functions it makes it possible to produce automatically both header with declarations and inline definitions and a cpp with non-inline definitions. As an example, in my hobby project cmake parses h2s, finds #cppinclude lines and adds them to a new .cpp as regular #include, than includes the generated .hpp.