Skip to content
Julien SOYSOUVANH edited this page Jul 14, 2021 · 5 revisions

Welcome to the Kodgen wiki!

Kodgen is a C++17 code generator based on libclang. It allows generating completely arbitrary files and code based on C++ entities parsed from your C++ files.

Motivation

Back in my student life, I worked on a 3D game engine and had to develop the serialization/reflection module. There are different approaches, but we decided to go with a system similar to Unreal Engine 4's: a "header tool". Their tool basically parses the project headers and generates code from the parsed data. We more or less managed to make it work, but I was not satisfied with the result: it was way too rigid, hard to maintain, and hard to extend.

Kodgen was born from this past experience, with the idea to provide a generic tool allowing code generation from C++ source code (like UE4 header tool, protobuff/flatbuffers compilers...). It is meant to be flexible and well-documented to meet all possible needs.

What can we do with Kodgen?

Well, as previously said, you will be able to generate files and code based on parsed C++ entities (namespaces, variables, functions, enums, classes/structs, methods and fields). Some rather common use cases would be to generate bindings from your C++ code to other languages, or to generate and inject code in your own source files, just like UE4 does it.

This library doesn't do anything on its own, it only provides an API and a flow that must be extended to generate code. The library user - you - will have to write a few classes to generate code for your needs. The code is highly modular however, so it is easy to plug existent generation code in your own generation flow.