Merge branch 'add-git-to-ExternalProject'
Conflicts: Modules/ExternalProject.cmake
This commit is contained in:
commit
a03e85f13c
|
@ -18,6 +18,8 @@
|
|||
# [SVN_REVISION rev] # Revision to checkout from Subversion repo
|
||||
# [SVN_USERNAME john ] # Username for Subversion checkout and update
|
||||
# [SVN_PASSWORD doe ] # Password for Subversion checkout and update
|
||||
# [GIT_REPOSITORY url] # URL of git repo
|
||||
# [GIT_TAG tag] # Git branch name, commit id or tag
|
||||
# [URL /.../src.tgz] # Full path or URL of source
|
||||
# [TIMEOUT seconds] # Time allowed for file download operations
|
||||
# #--Update/Patch step----------
|
||||
|
@ -206,6 +208,62 @@ define_property(DIRECTORY PROPERTY "EP_PREFIX" INHERITED
|
|||
)
|
||||
|
||||
|
||||
function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git_repository git_tag src_name work_dir)
|
||||
file(WRITE ${script_filename}
|
||||
"if(\"${git_tag}\" STREQUAL \"\")
|
||||
message(FATAL_ERROR \"Tag for git checkout should not be empty.\")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND \${CMAKE_COMMAND} -E remove_directory \"${source_dir}\"
|
||||
RESULT_VARIABLE error_code
|
||||
)
|
||||
if(error_code)
|
||||
message(FATAL_ERROR \"Failed to remove directory: '${source_dir}'\")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND \"${git_EXECUTABLE}\" clone \"${git_repository}\" \"${src_name}\"
|
||||
WORKING_DIRECTORY \"${work_dir}\"
|
||||
RESULT_VARIABLE error_code
|
||||
)
|
||||
if(error_code)
|
||||
message(FATAL_ERROR \"Failed to clone repository: '${git_repository}'\")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND \"${git_EXECUTABLE}\" checkout ${git_tag}
|
||||
WORKING_DIRECTORY \"${work_dir}/${src_name}\"
|
||||
RESULT_VARIABLE error_code
|
||||
)
|
||||
if(error_code)
|
||||
message(FATAL_ERROR \"Failed to checkout tag: '${git_tag}'\")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND \"${git_EXECUTABLE}\" submodule init
|
||||
WORKING_DIRECTORY \"${work_dir}/${src_name}\"
|
||||
RESULT_VARIABLE error_code
|
||||
)
|
||||
if(error_code)
|
||||
message(FATAL_ERROR \"Failed to init submodules in: '${work_dir}/${src_name}'\")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND \"${git_EXECUTABLE}\" submodule update --recursive
|
||||
WORKING_DIRECTORY \"${work_dir}/${src_name}\"
|
||||
RESULT_VARIABLE error_code
|
||||
)
|
||||
if(error_code)
|
||||
message(FATAL_ERROR \"Failed to update submodules in: '${work_dir}/${src_name}'\")
|
||||
endif()
|
||||
|
||||
"
|
||||
)
|
||||
|
||||
endfunction(_ep_write_gitclone_script)
|
||||
|
||||
|
||||
function(_ep_write_downloadfile_script script_filename remote local timeout)
|
||||
if(timeout)
|
||||
set(timeout_args TIMEOUT ${timeout})
|
||||
|
@ -613,6 +671,19 @@ function(_ep_add_mkdir_command name)
|
|||
endfunction(_ep_add_mkdir_command)
|
||||
|
||||
|
||||
function(_ep_get_git_version git_EXECUTABLE git_version_var)
|
||||
if(git_EXECUTABLE)
|
||||
execute_process(
|
||||
COMMAND "${git_EXECUTABLE}" --version
|
||||
OUTPUT_VARIABLE ov
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
string(REGEX REPLACE "^git version (.+)$" "\\1" version "${ov}")
|
||||
set(${git_version_var} "${version}" PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
||||
function(_ep_add_download_command name)
|
||||
ExternalProject_Get_Property(${name} source_dir stamp_dir download_dir tmp_dir)
|
||||
|
||||
|
@ -620,6 +691,7 @@ function(_ep_add_download_command name)
|
|||
get_property(cmd TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND)
|
||||
get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
|
||||
get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
|
||||
get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
|
||||
get_property(url TARGET ${name} PROPERTY _EP_URL)
|
||||
|
||||
# TODO: Perhaps file:// should be copied to download dir before extraction.
|
||||
|
@ -683,6 +755,46 @@ function(_ep_add_download_command name)
|
|||
set(cmd ${Subversion_SVN_EXECUTABLE} co ${svn_repository} ${svn_revision}
|
||||
--username=${svn_username} --password=${svn_password} ${src_name})
|
||||
list(APPEND depends ${stamp_dir}/${name}-svninfo.txt)
|
||||
elseif(git_repository)
|
||||
find_package(Git)
|
||||
if(NOT GIT_EXECUTABLE)
|
||||
message(FATAL_ERROR "error: could not find git for clone of ${name}")
|
||||
endif()
|
||||
|
||||
# The git submodule update '--recursive' flag requires git >= v1.6.5
|
||||
#
|
||||
_ep_get_git_version("${GIT_EXECUTABLE}" git_version)
|
||||
if(git_version VERSION_LESS 1.6.5)
|
||||
message(FATAL_ERROR "error: git version 1.6.5 or later required for 'git submodule update --recursive': git_version='${git_version}'")
|
||||
endif()
|
||||
|
||||
get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG)
|
||||
if(NOT git_tag)
|
||||
set(git_tag "master")
|
||||
endif()
|
||||
|
||||
set(repository ${git_repository})
|
||||
set(module)
|
||||
set(tag ${git_tag})
|
||||
configure_file(
|
||||
"${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
|
||||
"${stamp_dir}/${name}-gitinfo.txt"
|
||||
@ONLY
|
||||
)
|
||||
|
||||
get_filename_component(src_name "${source_dir}" NAME)
|
||||
get_filename_component(work_dir "${source_dir}" PATH)
|
||||
|
||||
# Since git clone doesn't succeed if the non-empty source_dir exists,
|
||||
# create a cmake script to invoke as download command.
|
||||
# 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} ${src_name} ${work_dir}
|
||||
)
|
||||
set(comment "Performing download step (git clone) for '${name}'")
|
||||
set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitclone.cmake)
|
||||
list(APPEND depends ${stamp_dir}/${name}-gitinfo.txt)
|
||||
elseif(url)
|
||||
get_filename_component(work_dir "${source_dir}" PATH)
|
||||
set(repository "external project URL")
|
||||
|
@ -741,6 +853,7 @@ function(_ep_add_update_command name)
|
|||
get_property(cmd TARGET ${name} PROPERTY _EP_UPDATE_COMMAND)
|
||||
get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
|
||||
get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
|
||||
get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
|
||||
|
||||
set(work_dir)
|
||||
set(comment)
|
||||
|
@ -769,6 +882,21 @@ function(_ep_add_update_command name)
|
|||
set(cmd ${Subversion_SVN_EXECUTABLE} up ${svn_revision}
|
||||
--username=${svn_username} --password=${svn_password})
|
||||
set(always 1)
|
||||
elseif(git_repository)
|
||||
if(NOT GIT_EXECUTABLE)
|
||||
message(FATAL_ERROR "error: could not find git for fetch of ${name}")
|
||||
endif()
|
||||
set(work_dir ${source_dir})
|
||||
set(comment "Performing update step (git fetch) for '${name}'")
|
||||
get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG)
|
||||
if(NOT git_tag)
|
||||
set(git_tag "master")
|
||||
endif()
|
||||
set(cmd ${GIT_EXECUTABLE} fetch
|
||||
COMMAND ${GIT_EXECUTABLE} checkout ${git_tag}
|
||||
COMMAND ${GIT_EXECUTABLE} submodule update --recursive
|
||||
)
|
||||
set(always 1)
|
||||
endif()
|
||||
|
||||
ExternalProject_Add_Step(${name} update
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
# The module defines the following variables:
|
||||
# GIT_EXECUTABLE - path to git command line client
|
||||
# GIT_FOUND - true if the command line client was found
|
||||
# Example usage:
|
||||
# find_package(Git)
|
||||
# if(GIT_FOUND)
|
||||
# message("git found: ${GIT_EXECUTABLE}")
|
||||
# endif()
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2010 Kitware, Inc.
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
# (To distributed this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
# Look for 'git' or 'eg' (easy git)
|
||||
#
|
||||
set(git_names git eg)
|
||||
|
||||
# Prefer .cmd variants on Windows unless running in a Makefile
|
||||
# in the MSYS shell.
|
||||
#
|
||||
if(WIN32)
|
||||
if(NOT CMAKE_GENERATOR MATCHES "MSYS")
|
||||
set(git_names git.cmd git eg.cmd eg)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_program(GIT_EXECUTABLE
|
||||
NAMES ${git_names}
|
||||
DOC "git command line client"
|
||||
)
|
||||
mark_as_advanced(GIT_EXECUTABLE)
|
||||
|
||||
# Handle the QUIETLY and REQUIRED arguments and set GIT_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(Git DEFAULT_MSG GIT_EXECUTABLE)
|
|
@ -973,6 +973,24 @@ cmLocalUnixMakefileGenerator3
|
|||
this->ConfigurationName.c_str());
|
||||
if (cmd.size())
|
||||
{
|
||||
// Use "call " before any invocations of .bat or .cmd files
|
||||
// invoked as custom commands in the WindowsShell.
|
||||
//
|
||||
bool useCall = false;
|
||||
|
||||
if (this->WindowsShell)
|
||||
{
|
||||
std::string suffix;
|
||||
if (cmd.size() > 4)
|
||||
{
|
||||
suffix = cmSystemTools::LowerCase(cmd.substr(cmd.size()-4));
|
||||
if (suffix == ".bat" || suffix == ".cmd")
|
||||
{
|
||||
useCall = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cmSystemTools::ReplaceString(cmd, "/./", "/");
|
||||
// Convert the command to a relative path only if the current
|
||||
// working directory will be the start-output directory.
|
||||
|
@ -1044,6 +1062,10 @@ cmLocalUnixMakefileGenerator3
|
|||
}
|
||||
}
|
||||
}
|
||||
if (useCall && launcher.empty())
|
||||
{
|
||||
cmd = "call " + cmd;
|
||||
}
|
||||
commands1.push_back(cmd);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ include(ExternalProject)
|
|||
|
||||
find_package(CVS)
|
||||
find_package(Subversion)
|
||||
find_package(Git)
|
||||
|
||||
set(base "${CMAKE_BINARY_DIR}/CMakeExternals")
|
||||
set(binary_base "${base}/Build")
|
||||
|
@ -37,8 +38,6 @@ if(NOT DEFINED can_build_tutorial_step5)
|
|||
endif()
|
||||
endif()
|
||||
|
||||
message(STATUS "can_build_tutorial_step5='${can_build_tutorial_step5}'")
|
||||
|
||||
|
||||
# Empty projects that test all the known ExternalProject_Add argument key words:
|
||||
#
|
||||
|
@ -212,7 +211,7 @@ if(do_cvs_tests)
|
|||
SOURCE_DIR ${local_cvs_repo}
|
||||
URL ${CMAKE_CURRENT_SOURCE_DIR}/cvsrepo.tgz
|
||||
BUILD_COMMAND ""
|
||||
CONFIGURE_COMMAND ${CVS_EXECUTABLE} --version
|
||||
CONFIGURE_COMMAND "${CVS_EXECUTABLE}" --version
|
||||
INSTALL_COMMAND ""
|
||||
)
|
||||
|
||||
|
@ -310,7 +309,7 @@ if(do_svn_tests)
|
|||
SOURCE_DIR ${local_svn_repo}
|
||||
URL ${CMAKE_CURRENT_SOURCE_DIR}/svnrepo.tgz
|
||||
BUILD_COMMAND ""
|
||||
CONFIGURE_COMMAND ${Subversion_SVN_EXECUTABLE} --version
|
||||
CONFIGURE_COMMAND "${Subversion_SVN_EXECUTABLE}" --version
|
||||
INSTALL_COMMAND ""
|
||||
)
|
||||
|
||||
|
@ -353,6 +352,80 @@ if(do_svn_tests)
|
|||
endif()
|
||||
|
||||
|
||||
set(do_git_tests 0)
|
||||
|
||||
if(GIT_EXECUTABLE)
|
||||
set(do_git_tests 1)
|
||||
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" --version
|
||||
OUTPUT_VARIABLE ov
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
string(REGEX REPLACE "^git version (.+)$" "\\1" git_version "${ov}")
|
||||
message(STATUS "git_version='${git_version}'")
|
||||
|
||||
if(git_version VERSION_LESS 1.6.5)
|
||||
message(STATUS "No ExternalProject git tests with git client less than version 1.6.5")
|
||||
set(do_git_tests 0)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
if(do_git_tests)
|
||||
set(local_git_repo "../../LocalRepositories/GIT")
|
||||
|
||||
# Unzip/untar the git repository in our source folder so that other
|
||||
# projects below may use it to test git args of ExternalProject_Add
|
||||
#
|
||||
set(proj SetupLocalGITRepository)
|
||||
ExternalProject_Add(${proj}
|
||||
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/LocalRepositories/GIT
|
||||
URL ${CMAKE_CURRENT_SOURCE_DIR}/gitrepo.tgz
|
||||
BUILD_COMMAND ""
|
||||
CONFIGURE_COMMAND "${GIT_EXECUTABLE}" --version
|
||||
INSTALL_COMMAND ""
|
||||
)
|
||||
|
||||
# git by commit id:
|
||||
#
|
||||
set(proj TutorialStep1-GIT-byhash)
|
||||
ExternalProject_Add(${proj}
|
||||
GIT_REPOSITORY "${local_git_repo}"
|
||||
GIT_TAG d1970730310fe8bc07e73f15dc570071f9f9654a
|
||||
UPDATE_COMMAND ""
|
||||
CMAKE_GENERATOR "${CMAKE_GENERATOR}"
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
|
||||
INSTALL_COMMAND ""
|
||||
DEPENDS "SetupLocalGITRepository"
|
||||
)
|
||||
|
||||
# git by explicit branch/tag name:
|
||||
#
|
||||
set(proj TutorialStep1-GIT-bytag)
|
||||
ExternalProject_Add(${proj}
|
||||
GIT_REPOSITORY "${local_git_repo}"
|
||||
GIT_TAG "origin/master"
|
||||
UPDATE_COMMAND ""
|
||||
CMAKE_GENERATOR "${CMAKE_GENERATOR}"
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
|
||||
INSTALL_COMMAND ""
|
||||
DEPENDS "SetupLocalGITRepository"
|
||||
)
|
||||
|
||||
# Live git / master (no GIT_TAG):
|
||||
#
|
||||
set(proj TutorialStep1-GIT-master)
|
||||
ExternalProject_Add(${proj}
|
||||
GIT_REPOSITORY "${local_git_repo}"
|
||||
CMAKE_GENERATOR "${CMAKE_GENERATOR}"
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
|
||||
INSTALL_COMMAND ""
|
||||
DEPENDS "SetupLocalGITRepository"
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
# Test the testable built/installed products:
|
||||
#
|
||||
enable_testing()
|
||||
|
@ -417,3 +490,10 @@ if(can_build_tutorial_step5)
|
|||
set_property(TEST TutorialStep5-InstallTreeTest
|
||||
APPEND PROPERTY LABELS Step5 InstallTree)
|
||||
endif()
|
||||
|
||||
|
||||
message(STATUS "can_build_tutorial_step5='${can_build_tutorial_step5}'")
|
||||
message(STATUS "do_cvs_tests='${do_cvs_tests}'")
|
||||
message(STATUS "do_svn_tests='${do_svn_tests}'")
|
||||
message(STATUS "do_git_tests='${do_git_tests}'")
|
||||
message(STATUS "GIT_EXECUTABLE='${GIT_EXECUTABLE}'")
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue