2323# when only a specific branch of a repo is required and the full history
2424# is not required. Note that the SHALLOW option will only work for a branch
2525# or tag and cannot be used for an arbitrary SHA.
26+ # OPTIONAL, when present, this option makes this operation optional.
27+ # The function will output a warning and return if the repo could not be
28+ # cloned.
2629#
2730# Targets:
2831# * <directory>-rebase: fetches latest updates and rebases the given external
2932# git repository onto it.
3033# * rebase: Rebases all git externals, including sub projects
3134#
3235# Options (global) which control behaviour:
33- # GIT_EXTERNAL_VERBOSE
36+ # COMMON_GIT_EXTERNAL_VERBOSE
3437# This is a global option which has the same effect as the VERBOSE option,
3538# with the difference that output information will be produced for all
3639# external repos when set.
@@ -53,15 +56,15 @@ if(NOT GIT_EXECUTABLE)
5356endif ()
5457
5558include (CMakeParseArguments )
56- option (GIT_EXTERNAL_VERBOSE "Print git commands as they are executed" OFF )
59+ option (COMMON_GIT_EXTERNAL_VERBOSE "Print git commands as they are executed" OFF )
5760
5861if (NOT GITHUB_USER AND DEFINED ENV{GITHUB_USER})
5962 set (GITHUB_USER $ENV{GITHUB_USER} CACHE STRING
6063 "Github user name used to setup remote for 'user' forks" )
6164endif ()
6265
6366macro (GIT_EXTERNAL_MESSAGE msg )
64- if (GIT_EXTERNAL_VERBOSE OR GIT_EXTERNAL_LOCAL_VERBOSE )
67+ if (COMMON_GIT_EXTERNAL_VERBOSE )
6568 message (STATUS "${NAME} : ${msg} " )
6669 endif ()
6770endmacro ()
@@ -74,7 +77,7 @@ function(JOIN VALUES GLUE OUTPUT)
7477endfunction ()
7578
7679function (GIT_EXTERNAL DIR REPO tag )
77- cmake_parse_arguments (GIT_EXTERNAL_LOCAL "VERBOSE;SHALLOW" "" "RESET" ${ARGN} )
80+ cmake_parse_arguments (GIT_EXTERNAL_LOCAL "VERBOSE;SHALLOW;OPTIONAL " "" "RESET" ${ARGN} )
7881 set (TAG ${tag} )
7982 if (GIT_EXTERNAL_TAG AND "${tag} " MATCHES "^[0-9a-f]+$" )
8083 set (TAG ${GIT_EXTERNAL_TAG} )
@@ -115,7 +118,12 @@ function(GIT_EXTERNAL DIR REPO tag)
115118 RESULT_VARIABLE nok ERROR_VARIABLE error
116119 WORKING_DIRECTORY "${GIT_EXTERNAL_DIR} " )
117120 if (nok)
118- message (FATAL_ERROR "${DIR} clone failed: ${error} \n " )
121+ if (GIT_EXTERNAL_LOCAL_OPTIONAL)
122+ message (STATUS "${DIR} clone failed: ${error} \n " )
123+ return ()
124+ else ()
125+ message (FATAL_ERROR "${DIR} clone failed: ${error} \n " )
126+ endif ()
119127 endif ()
120128
121129 # checkout requested tag
0 commit comments