是否可以在cmake configure步骤中列出所有git分支或标签(在ccmake / cmake-gui中)?
我希望允许用户选择特定的分支/标记(在当前存储库中可用),这将用于下载外部项目的构建(make)步骤。
Inital CMakeLists.txt文件:
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 git@bitbucket.org:pypy/numpy.git
GIT_TAG ${REPO_TAG}
)
答案 0 :(得分:2)
使用:
execute_process(
COMMAND ${GIT_EXECUTABLE} ls-remote
git@bitbucket.org:pypy/numpy.git heads/*
RESULT_VARIABLE result
OUTPUT_VARIABLE output)
这些命令在result
变量中产生一系列行。每一行都是散列和分支的完整路径。这些行可以由string(REGEX ...)
命令处理,以提取可以提供给set_property(CACHE <user-option-var> PROPERTY STRINGS <list-of-branches>)
命令的分支名称,以设置<user-option-var>
列表框的选项。
答案 1 :(得分:0)
基于@ tamas.kenez回复。我创建了CMakeLists为我工作:
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)
execute_process(
COMMAND ${GIT_EXECUTABLE} ls-remote git@bitbucket.org:pypy/numpy.git tags/*
RESULT_VARIABLE RESULT
OUTPUT_VARIABLE OUTPUT)
set (DEFAULT_TAG "master")
set (REPO_TAG ${DEFAULT_TAG} CACHE STRING "Select a repo tag")
string (REGEX MATCHALL "([^/]+)[\^{}]\n" TAGS ${OUTPUT})
string (REGEX REPLACE "\n" ";" TAGS ${TAGS})
set_property (CACHE REPO_TAG PROPERTY STRINGS ${TAGS})
include(ExternalProject)
ExternalProject_Add (
numpy
GIT_REPOSITORY git@bitbucket.org:pypy/numpy.git
GIT_TAG "${REPO_TAG}"
)