From: Đoàn Trần Công Danh Date: Sat, 30 May 2020 13:17:30 GMT Subject: Re: [PATCH v3 1/8] Introduce CMake support for configuring Git Message-ID: <20200530131730.GA2151@danh.dev> In-Reply-To: <09c972de52b35b14a4c6f44b10c3dfc1732b2c7a.1590759624.git.gitgitgadget@gmail.com> Hi Sibi, On 2020-05-29 13:40:17+0000, Sibi Siddharthan via GitGitGadget wrote: > +file(STRINGS ${CMAKE_SOURCE_DIR}/GIT-VERSION-FILE git_version REGEX "GIT_VERSION = (.*)") > +string(REPLACE "GIT_VERSION = " "" git_version ${git_version}) > +string(FIND ${git_version} "GIT" location) > +if(location EQUAL -1) > + string(REGEX MATCH "[0-9]*\\.[0-9]*\\.[0-9]*" git_version ${git_version}) This will strip everything begins with first non-number. With the same Git repo, The git binary generated via Makefile reports version: git version 2.27.0.rc2.274.g860c8aebb9.dirty The git binary generated via CMake reports: git version 2.27.0.GIT Anyway, I pretty much defer this step to build step. Since this will report the version when *cmake* is run. And *cmake* will be unlikely run again if nothing related to CMake is being changed. -- Danh