Run command at beginning of make

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/”):

COMMAND git describe --tag --always

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”)?

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.

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.