是否可以在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}
)
最佳答案 使用:
execute_process(
COMMAND ${GIT_EXECUTABLE} ls-remote
git@bitbucket.org:pypy/numpy.git heads/*
RESULT_VARIABLE result
OUTPUT_VARIABLE output)
这些命令在结果变量中产生一系列行.每一行都是散列和分支的完整路径.这些行可以通过字符串(REGEX …)命令处理,以提取可以提供给set_property(CACHE< user-option-var> PROPERTY STRINGS< list-of-branches>)命令的分支名称来设置< user-option-var>列表框的选项.