Skip to content

Commit ea920eb

Browse files
jcfrkwryankrattiger
andcommitted
ExternalProjectDependency: Force git protocol to https
This commit ensures `EP_GIT_PROTOCOL` variable is always set to "https" and that `<SUPERBUILD_TOPLEVEL_PROJECT>_USE_GIT_PROTOCOL` is always set to OFF. Change required following the removal of git protocol by GitHub. See details at https://github.blog/2021-09-01-improving-git-protocol-security-github Co-authored-by: Ryan Krattiger <[email protected]>
1 parent e00b913 commit ea920eb

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

ExternalProjectDependency.cmake

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,17 @@ endif()
9292
#.rst:
9393
# .. cmake:variable:: EP_GIT_PROTOCOL
9494
#
95-
# The value of this variable is controlled by the option ``<SUPERBUILD_TOPLEVEL_PROJECT>_USE_GIT_PROTOCOL``
96-
# automatically defined by including this CMake module. Setting this option allows to update the value of
97-
# ``EP_GIT_PROTOCOL`` variable.
95+
# The value of this variable is always set to ``https``.
9896
#
99-
# If enabled, the variable ``EP_GIT_PROTOCOL`` is set to ``git``. Otherwise, it is set to ``https``.
100-
# The option is enabled by default.
97+
# Following the removal of git protocol by GitHub, the option
98+
# ``<SUPERBUILD_TOPLEVEL_PROJECT>_USE_GIT_PROTOCOL`` is obsolete.
99+
# It allowed to toggle between ``git`` and ``https``.
100+
# If this option is enabled, a warning is reported and the option is forced to ``OFF``.
101+
#
102+
# Similarly, if the variable ``EP_GIT_PROTOCOL`` is already set to ``git``, a warning is reported
103+
# and the value is forced to ``https``.
104+
#
105+
# See details at https://github.blog/2021-09-01-improving-git-protocol-security-github
101106
#
102107
# The variable ``EP_GIT_PROTOCOL`` can be used when adding external project. For example:
103108
#
@@ -109,9 +114,22 @@ endif()
109114
# [...]
110115
# )
111116
#
112-
option(${SUPERBUILD_TOPLEVEL_PROJECT}_USE_GIT_PROTOCOL "If behind a firewall turn this off to use https instead." ON)
113-
set(EP_GIT_PROTOCOL "git")
114-
if(NOT ${SUPERBUILD_TOPLEVEL_PROJECT}_USE_GIT_PROTOCOL)
117+
if(DEFINED ${SUPERBUILD_TOPLEVEL_PROJECT}_USE_GIT_PROTOCOL AND ${SUPERBUILD_TOPLEVEL_PROJECT}_USE_GIT_PROTOCOL)
118+
message(WARNING "Forcing ${SUPERBUILD_TOPLEVEL_PROJECT}_USE_GIT_PROTOCOL to OFF (Already set to ON in current scope)")
119+
set(${SUPERBUILD_TOPLEVEL_PROJECT}_USE_GIT_PROTOCOL OFF CACHE BOOL "" FORCE)
120+
endif()
121+
if(DEFINED EP_GIT_PROTOCOL)
122+
if("${EP_GIT_PROTOCOL}" STREQUAL "git")
123+
get_property(_value_set_in_cache CACHE EP_GIT_PROTOCOL PROPERTY VALUE SET)
124+
if(_value_set_in_cache)
125+
message(WARNING "Forcing EP_GIT_PROTOCOL cache variable to 'https' (Already set to '${EP_GIT_PROTOCOL}' in current scope)")
126+
set(EP_GIT_PROTOCOL "https" CACHE STRING "" FORCE)
127+
else()
128+
message(WARNING "Forcing EP_GIT_PROTOCOL variable to 'https' (Already set to '${EP_GIT_PROTOCOL}' in current scope)")
129+
set(EP_GIT_PROTOCOL "https")
130+
endif()
131+
endif()
132+
else()
115133
set(EP_GIT_PROTOCOL "https")
116134
endif()
117135

0 commit comments

Comments
 (0)