Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add cmake doc #607

Merged
merged 11 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions doc/cmake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Building a new data model library with CMake

PODIO exposes multiple CMake macros to enable the building of data model libraries.
For a package developer tutorial on CMake, please have a look [here](https://hsf-training.github.io/hsf-training-cmake-webpage/). PODIO follows the same conventions used therein.

## Exported CMake functions and macros
The file [cmake/podioMacros.cmake](https://github.com/AIDASoft/podio/blob/master/cmake/podioMacros.cmake) provides the following functions for external use:

1. `PODIO_GENERATE_DATAMODEL` - generate the data model from provided yaml file
2. `PODIO_ADD_DATAMODEL_CORE_LIB` - compile the generated data model
3. `PODIO_ADD_ROOT_IO_DICT` - configure ROOT I/O backend and interface to Python
4. `PODIO_ADD_SIO_IO_BLOCKS` - configure SIO backend

Their exact parameters and functionality are documented in the file mentioned above. Below a few examples.

## A simple example
After a proper `find_package(podio REQUIRED)`, the C++ code of the new data model `newdm` can be created and compiled via

```cmake
# generate the c++ code from the yaml definition
PODIO_GENERATE_DATAMODEL(newdm newdm.yaml headers sources)

# compile the core data model shared library (no I/O)
PODIO_ADD_DATAMODEL_CORE_LIB(newdm "${headers}" "${sources}")

# generate and compile the ROOT I/O dictionary for the default I/O system
PODIO_ADD_ROOT_IO_DICT(newdmDict newmdm "${headers}" src/selection.xml)
```
For an explicit choice of I/O backends one needs to add the `IO_BACKEND_HANDLERS` parameter and then generate and compile the corresponding backends, like shown below for the ROOT and SIO backends:

```cmake
# generate the c++ code from the yaml definition
PODIO_GENERATE_DATAMODEL(newdm newdm.yaml headers sources IO_BACKEND_HANDLERS "ROOT;SIO")

# compile the core data model shared library (no I/O)
PODIO_ADD_DATAMODEL_CORE_LIB(newdm "${headers}" "${sources}")

# generate and compile the ROOT I/O dictionary for the default I/O system
PODIO_ADD_ROOT_IO_DICT(newdmDict newmdm "${headers}" src/selection.xml)

# compile the SIOBlocks shared library for the SIO backend
PODIO_ADD_SIO_IO_BLOCKS(newdm "${headers}" "${sources}")
```

For a complete example, please have a look at [EDM4hep](https://github.com/key4hep/EDM4hep/blob/main/edm4hep/CMakeLists.txt)
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Welcome to PODIO's documentation!
examples.md
frame.md
userdata.md
cmake.md
advanced_topics.md
templates.md
python.md
Expand Down