Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get git branch/tag names in CMake, from external project?

Tags:

git

cmake

Is it possible to list all git branches or tags in cmake configure step (in ccmake/cmake-gui)?

I want to allow the user to select a specific branch/tag (available on current repository), which will be used in build (make) step for download external project.

Inital CMakeLists.txt file:

cmake_minimum_required (VERSION 2.8)
project (project_name)

find_package (Git)
if (GIT_FOUND)
      message("git found: ${GIT_EXECUTABLE} in version     ${GIT_VERSION_STRING}")
endif (GIT_FOUND)

set (DEFAULT_TAG "tag_default")
# set (TAGS ...) getting the names of all tags from repository

set (REPO_TAG ${DEFAULT_TAG} CACHE STRING "Select a repo tag")
set_property (CACHE REPO_TAG PROPERTY STRINGS ${TAGS})

include(ExternalProject)
ExternalProject_Add (
    numpy
    GIT_REPOSITORY [email protected]:pypy/numpy.git
    GIT_TAG ${REPO_TAG}
)
like image 943
abrzozowski Avatar asked Aug 10 '15 11:08

abrzozowski


People also ask

How do I find my git repository tags?

In order to find the latest Git tag available on your repository, you have to use the “git describe” command with the “–tags” option. This way, you will be presented with the tag that is associated with the latest commit of your current checked out branch.

How do I get all tags on GitHub?

Listing the available tags in Git is straightforward. Just type git tag (with optional -l or --list ).

Does git tag apply to all branches?

Yes! The difference between a branch name and a tag name is that a branch name is expected to move, and git will move it automatically in that "on a branch" case.

How do you create a tag from a branch?

In order to create a new tag, you have to use the “git tag” command and specify the tag name that you want to create. As an example, let's say that you want to create a new tag on the latest commit of your master branch. To achieve that, execute the “git tag” command and specify the tagname.


1 Answers

Use:

execute_process(
    COMMAND ${GIT_EXECUTABLE} ls-remote
        [email protected]:pypy/numpy.git heads/*
    RESULT_VARIABLE result
    OUTPUT_VARIABLE output)

The commands yield a sequence of lines in the result variable. Each line is the hash and the full path of a branch. These lines can be processed by string(REGEX ...) commands to extract the branch names which can be supplied to the set_property(CACHE <user-option-var> PROPERTY STRINGS <list-of-branches>) command to set the options for the listbox of <user-option-var>.

like image 86
tamas.kenez Avatar answered Oct 22 '22 00:10

tamas.kenez