# Read file and transform the result in a custom command directly?

**URL:** <https://discourse.cmake.org/t/read-file-and-transform-the-result-in-a-custom-command-directly/9448>\
**Category:** Code\
**Created:** [November 17, 2023, 1:07pm UTC](https://discourse.cmake.org/t/read-file-and-transform-the-result-in-a-custom-command-directly/9448 "2023-11-17T13:07:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eriols](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eriols/32/945_2.png) [@eriols](https://discourse.cmake.org/u/eriols)\
**Post date:** [November 17, 2023, 1:07pm UTC](https://discourse.cmake.org/t/read-file-and-transform-the-result-in-a-custom-command-directly/9448/1 "2023-11-17T13:07:04Z")

</div>

Before I run eg doxygen I want to read up some variables from a file that was written earlier in the build.  
This reading also entails transforming the result a bit before passing it on to doxygen.  
Is it customary to create a custom command that depends on the file creation and do all of this inside said command:  
1 read the file into a variable  
2 transforms the variables a bit (a few steps)  
3 store the result in a variable  
…and then have the call to doxygen depend on the above command?  
That is, can I do all this with the `${CMAKE_COMMAND}` inside the custom command directly somehow?  
Or do I need to write the commands to another file and then run it from the custom command with `-P`? I have never encountered the former, hence my question.  
Thank you.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [November 19, 2023, 2:40am UTC](https://discourse.cmake.org/t/read-file-and-transform-the-result-in-a-custom-command-directly/9448/2 "2023-11-19T02:40:03Z")

</div>

> [@eriols](#):
>
> That is, can I do all this with the `${CMAKE_COMMAND}` inside the custom command directly somehow?

If the `-E` subcommands do what you need. But I think a script and `-P` is easier and more common.
