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}
)
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.
Listing the available tags in Git is straightforward. Just type git tag (with optional -l or --list ).
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.
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.
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>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With