Merge topic 'ExternalProject-git-clone-o'

83d63391 ExternalProject: Add option to set `git clone -o` argument
This commit is contained in:
Brad King 2016-01-19 09:35:40 -05:00 committed by CMake Topic Stage
commit 65146afc4e
2 changed files with 22 additions and 6 deletions

View File

@ -0,0 +1,5 @@
ExternalProject-git-clone-o
---------------------------
* The :module:`ExternalProject` module learned a new ``GIT_REMOTE_NAME``
option to control the ``git clone --origin`` value.

View File

@ -57,6 +57,8 @@ Create custom targets to build projects in external trees
URL of git repo
``GIT_TAG <tag>``
Git branch name, commit id or tag
``GIT_REMOTE_NAME <name>``
The optional name of the remote, default to ``origin``
``GIT_SUBMODULES <module>...``
Git submodules that shall be updated, all if empty
``HG_REPOSITORY <url>``
@ -494,7 +496,7 @@ define_property(DIRECTORY PROPERTY "EP_UPDATE_DISCONNECTED" INHERITED
"ExternalProject module."
)
function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git_repository git_tag git_submodules src_name work_dir gitclone_infofile gitclone_stampfile)
function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git_repository git_tag git_remote_name git_submodules src_name work_dir gitclone_infofile gitclone_stampfile)
file(WRITE ${script_filename}
"if(\"${git_tag}\" STREQUAL \"\")
message(FATAL_ERROR \"Tag for git checkout should not be empty.\")
@ -524,7 +526,7 @@ set(error_code 1)
set(number_of_tries 0)
while(error_code AND number_of_tries LESS 3)
execute_process(
COMMAND \"${git_EXECUTABLE}\" clone \"${git_repository}\" \"${src_name}\"
COMMAND \"${git_EXECUTABLE}\" clone --origin \"${git_remote_name}\" \"${git_repository}\" \"${src_name}\"
WORKING_DIRECTORY \"${work_dir}\"
RESULT_VARIABLE error_code
)
@ -645,7 +647,7 @@ endif()
endfunction()
function(_ep_write_gitupdate_script script_filename git_EXECUTABLE git_tag git_submodules git_repository work_dir)
function(_ep_write_gitupdate_script script_filename git_EXECUTABLE git_tag git_remote_name git_submodules git_repository work_dir)
if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.6)
set(git_stash_save_options --all --quiet)
else()
@ -687,7 +689,7 @@ if(\"\${show_ref_output}\" MATCHES \"refs/remotes/${git_tag}\")
set(git_remote \"\${CMAKE_MATCH_1}\")
set(git_tag \"\${CMAKE_MATCH_2}\")
else()
set(git_remote \"origin\")
set(git_remote \"${git_remote_name}\")
set(git_tag \"${git_tag}\")
endif()
@ -1749,6 +1751,11 @@ function(_ep_add_download_command name)
endif()
get_property(git_submodules TARGET ${name} PROPERTY _EP_GIT_SUBMODULES)
get_property(git_remote_name TARGET ${name} PROPERTY _EP_GIT_REMOTE_NAME)
if(NOT git_remote_name)
set(git_remote_name "origin")
endif()
# For the download step, and the git clone operation, only the repository
# should be recorded in a configured RepositoryInfo file. If the repo
# changes, the clone script should be run again. But if only the tag
@ -1772,7 +1779,7 @@ function(_ep_add_download_command name)
# The script will delete the source directory and then call git clone.
#
_ep_write_gitclone_script(${tmp_dir}/${name}-gitclone.cmake ${source_dir}
${GIT_EXECUTABLE} ${git_repository} ${git_tag} "${git_submodules}" ${src_name} ${work_dir}
${GIT_EXECUTABLE} ${git_repository} ${git_tag} ${git_remote_name} "${git_submodules}" ${src_name} ${work_dir}
${stamp_dir}/${name}-gitinfo.txt ${stamp_dir}/${name}-gitclone-lastrun.txt
)
set(comment "Performing download step (git clone) for '${name}'")
@ -1993,9 +2000,13 @@ function(_ep_add_update_command name)
if(NOT git_tag)
set(git_tag "master")
endif()
get_property(git_remote_name TARGET ${name} PROPERTY _EP_GIT_REMOTE_NAME)
if(NOT git_remote_name)
set(git_remote_name "origin")
endif()
get_property(git_submodules TARGET ${name} PROPERTY _EP_GIT_SUBMODULES)
_ep_write_gitupdate_script(${tmp_dir}/${name}-gitupdate.cmake
${GIT_EXECUTABLE} ${git_tag} "${git_submodules}" ${git_repository} ${work_dir}
${GIT_EXECUTABLE} ${git_tag} ${git_remote_name} "${git_submodules}" ${git_repository} ${work_dir}
)
set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitupdate.cmake)
set(always 1)