# Run command at beginning of make

**URL:** <https://discourse.cmake.org/t/run-command-at-beginning-of-make/3649>\
**Category:** Code\
**Created:** [June 28, 2021, 10:29pm UTC](https://discourse.cmake.org/t/run-command-at-beginning-of-make/3649 "2021-06-28T22:29:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaykemper](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/2acd7d/32.png) [@jaykemper](https://discourse.cmake.org/u/jaykemper)\
**Post date:** [June 28, 2021, 10:29pm UTC](https://discourse.cmake.org/t/run-command-at-beginning-of-make/3649/1 "2021-06-28T22:29:28Z")

</div>

I’m trying to get git information for my project build. The “execute\_process” command runs during the configuration of the project (“cmake /path/to/project/”):

execute\_process(  
COMMAND git describe --tag --always  
WORKING\_DIRECTORY ${CMAKE\_SOURCE\_DIR}  
OUTPUT\_VARIABLE GIT\_TAG\_INFO’  
OUTPUT\_STRIP\_TRAILING\_WHITESPACE  
)

I can use the “install” command with the CODE keyword and put the command in quotes and it will run during “make install”:

install( CODE  
"  
{the above command}  
"  
)

However, how would I get this command to run at compile-time (“make”)?

---

<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:** [June 28, 2021, 10:47pm UTC](https://discourse.cmake.org/t/run-command-at-beginning-of-make/3649/2 "2021-06-28T22:47:04Z")

</div>

You can use `add_custom_command(OUTPUT does_not_exist COMMAND …)` to get it to run all the time. Just make sure `does_not_exist` doesn’t exist and the build tools will always try to update it on every run.

---

<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:** [June 28, 2021, 10:48pm UTC](https://discourse.cmake.org/t/run-command-at-beginning-of-make/3649/3 "2021-06-28T22:48:31Z")

</div>

Note that controlling the scheduling is not possible, so it can run at any point during the build, not just at the beginning, though you can write a real file which is additionally listed in `OUTPUTS` and tack that into the dependency graph via `add_custom_target(run_git DEPENDS touched_file)` then depending on that from wherever you need.
