# How to deal with code generators?

**URL:** https://discourse.cmake.org/t/how-to-deal-with-code-generators/2301
**Category:** Code
**Tags:** os:linux, gen:ninja, gen:makefiles
**Created:** [December 5, 2020, 9:50pm UTC](https://discourse.cmake.org/t/how-to-deal-with-code-generators/2301 "2020-12-05T21:50:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Massimiliano\_Cialdi](https://discourse.cmake.org/user_avatar/discourse.cmake.org/massimiliano_cialdi/32/924_2.png) [@Massimiliano\_Cialdi](https://discourse.cmake.org/u/Massimiliano_Cialdi)
#### Post date: [December 5, 2020, 9:50pm UTC](https://discourse.cmake.org/t/how-to-deal-with-code-generators/2301/1 "2020-12-05T21:50:21Z")

</div>

In the past I have dealt with code generators such as flex, bison, protobuf, etc…  
In an old project, using makefiles, it was the same make that wrote a header file containing the semantic version string, and a couple of files containing arrays generated from binary files with the command `xxd`.  
How is it possible to achieve this, with the right dependencies between files, with cmake?  
For example if it is necessary to run a command every time the executable is built.

best regards  
Max

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [December 6, 2020, 6:35pm UTC](https://discourse.cmake.org/t/how-to-deal-with-code-generators/2301/2 "2020-12-06T18:35:59Z")

</div>

For each generated file, use a add\_custom\_command() and file outputs and dependencies correctly.

Then use each output in no more than ONE target. The custom commands must be defined in the same directory as the target.
