# Build Integration
This page covers how to integrate synta-codegen into CMake, Meson, and
Makefile build systems, and documents the optional helper functions available
with `--with-helpers`.
## CLI Options Reference
```bash
# Single-file: header only
synta-codegen --lang c schema.asn1 -o types.h
synta-codegen --lang c schema.asn1 --with-helpers -o types.h
synta-codegen --lang c schema.asn1 --header-path "../../include/synta.h" -o types.h
# Single-file: implementation (--impl names the header to #include)
synta-codegen --lang c schema.asn1 --impl types.h -o types.c
# Multi-file: headers and implementations in one shot
synta-codegen --lang c a.asn1 b.asn1 --emit both --output-dir ./generated/
# Multi-file with build system file
synta-codegen --cmake a.asn1 b.asn1 --output-dir ./generated/
synta-codegen --meson a.asn1 b.asn1 --output-dir ./generated/
# Validate imports without generating output
synta-codegen --check-imports a.asn1 b.asn1
# Help
synta-codegen --help
```
## CMake Integration (--cmake)
`--cmake` generates a `CMakeLists.txt` targeting CMake 3.10 or later with C99
standard.
Key properties of the generated file:
- Defines a `Synta::Synta` IMPORTED target that wraps libcsynta. The path is
taken from `--synta-root` if provided, or from a `SYNTA_ROOT` CMake cache
variable at configure time.
- Generates one `add_library()` call per schema module, in topological order.
- Sets platform-specific link libraries automatically:
- Linux / BSD: `pthread`, `dl`, `m`
- macOS: `pthread`
- Windows: `ws2_32`, `userenv`, `bcrypt`
- Default library type is STATIC. Pass `--shared` to switch to SHARED.
Example generated CMakeLists excerpt:
```cmake
cmake_minimum_required(VERSION 3.10)
project(MySchema C)
set(CMAKE_C_STANDARD 99)
# ... Synta::Synta imported target setup ...
add_library(my_schema STATIC types.c)
target_link_libraries(my_schema PUBLIC Synta::Synta)
```
## Meson Integration (--meson)
`--meson` generates a `meson.build` file with `c_std=c99` and
`warning_level=2`.
Key properties:
- If `--synta-root` is provided, locates libcsynta with
`cc.find_library('csynta', dirs: synta_root)`.
- Otherwise, uses `dependency('synta')` to locate it via pkg-config or the
Meson wrap system.
- Generates one `library()` or `shared_library()` call per module.
- Generates `declare_dependency()` entries for inter-module dependencies.
## Makefile Integration
```makefile
SYNTA_CODEGEN = path/to/synta-codegen
SYNTA_INCLUDE = path/to/synta/include
SYNTA_LIB = path/to/synta/lib
# Generate header, then implementation separately
types.h: schema.asn1
$(SYNTA_CODEGEN) --lang c $< --with-helpers -o $@
types.c: schema.asn1 types.h
$(SYNTA_CODEGEN) --lang c $< --impl types.h -o $@
# Multi-file: generate all headers and implementations at once
generated/: a.asn1 b.asn1
$(SYNTA_CODEGEN) --lang c $^ --emit both --output-dir generated/
# Compile generated code
types.o: types.c types.h
gcc -c $< -I$(SYNTA_INCLUDE)
# Link with application
myapp: myapp.c types.o
gcc -o $@ $^ -L$(SYNTA_LIB) -lcsynta
clean:
rm -f types.h types.c types.o myapp
.PHONY: clean
```
## Helper Functions (--with-helpers)
With `--with-helpers`, three additional static inline functions are generated
in the header for each type.
### `TypeName_init`
Zero-initializes every field in the struct to 0, NULL, or false. Equivalent
to `memset(out, 0, sizeof(*out))` but expressed field-by-field for clarity.
```c
static inline void TypeName_init(TypeName *out);
```
### `TypeName_validate`
Checks that all required pointer fields are non-NULL, and that a CHOICE struct
has a recognized tag value. Returns `SyntaErrorCode_Success` or
`SyntaErrorCode_NullPointer` / `SyntaErrorCode_InvalidTag`.
```c,ignore
static inline SyntaErrorCode TypeName_validate(const TypeName *value);
```
### `TypeName_print`
Writes a human-readable debug representation to a `FILE*` stream. Handles
NULL input gracefully (prints `"(null)"`). Intended for debugging, not for
production output.
```c
static inline void TypeName_print(const TypeName *value, FILE *stream);
```
`_print` requires `<stdio.h>` to be included before the generated header, or
the generated header includes it automatically when `--with-helpers` is active.