https://github.com/clausklein/cmakecustomtargetexamples
How generating files at build time with CMake
https://github.com/clausklein/cmakecustomtargetexamples
cmake graphvis ninja
Last synced: 6 months ago
JSON representation
How generating files at build time with CMake
- Host: GitHub
- URL: https://github.com/clausklein/cmakecustomtargetexamples
- Owner: ClausKlein
- Created: 2021-10-23T16:23:26.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-23T17:12:05.000Z (almost 4 years ago)
- Last Synced: 2025-02-12T11:13:44.868Z (8 months ago)
- Topics: cmake, graphvis, ninja
- Language: CMake
- Homepage:
- Size: 110 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Howto generating files at build time with CMake
Thanks to [Craig Scott](https://crascit.com/author/crascit/) for his Blog!
## A modified example from [https://crascit.com](https://crascit.com/2017/04/18/generated-sources-in-cmake-builds/)
Instead of using [add_custom_target()](https://cmake.org/cmake/help/latest/command/add_custom_target.html)
to generate the sources manually, you should define custom `OUTPUTS ` with `DEPENDS ` using
[add_custom_command()](https://cmake.org/cmake/help/latest/command/add_custom_command.html).CMake can then automatically work out dependencies when those outputs are used as inputs to another target.
[Sam Thursfield has more CMake tips](https://samthursfield.wordpress.com/2015/11/21/cmake-dependencies-between-targets-and-files-and-custom-commands/)
if you are intrested.## CMake and Ninja can generate graphviz files showing the dependencies between the targets in a project
This dependency trees [DAG](https://en.wikipedia.org/wiki/Directed_acyclic_graph) are generated with this
[CMakeLists.txt](CMakeLists.txt) and **dot**, a tool from [graphviz](https://graphviz.org/Gallery/directed/ninja.html)
