Update PROJECT VERSION during build generation time

I’m using write_basic_package_version_file to generate a version file for a package. Further, I’m using project version to specify a path (/lib/myProject-${PROJECT_VERSION_MAJOR}) to a package folder where I’m going to install the said version file.

Suppose I get my version from a git repo. If I create a new git tag and build a project the script has to reflect changes.

I need to update PROJECT_VERSION cache by CMakeLists.txt script obtaining a git repository tag during BUILD TIME, not a configure time. This ideally should help me to avoid running configuration every time I need to update version (I already use --presets but still, it’s quite hard).

Any ideas?