[CMake] Question about getting git branch name.

J Decker d3ck0r at gmail.com
Sat Jun 8 18:34:41 EDT 2019


On Sat, Jun 8, 2019 at 3:25 PM Steven Truppe <workbench at gmx.at> wrote:

> Hi everyone,
>
> i want to have code lines like:
>
> #define BUILD_VERSION
>
> and the BUILD_VERSION should be the name of the actual branch the code
> was compiled with, this way i can create a branch for each version and
> name it like 0.1 so each version i'm using for release is an own branch.
>
> I found many examples that shows me the branch name (like git status)
>
git branch
Hmm this shows a list of things, have to extract the one with a * on the
beginning... cam probably use CMAKE list functions on the output.


EXECUTE_PROCESS(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND git rev-list
--max-count=1 HEAD OUTPUT_VARIABLE CURRENT_REPO_REVISION )

gives me the last hash...

but i don't know a way to get only the name of the current branch so i
> can for example execute_process to get the revision number into a
> variable and then use add_definition(..) to add it as a compile definition.
>
>
> best regards!
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190608/f0eac476/attachment.html>


More information about the CMake mailing list