Skip to content

Commit

Permalink
Merge pull request #458 from robotology/fixrobsub1690
Browse files Browse the repository at this point in the history
Fix regression(s) introduced by YCMEPHelper refactor
  • Loading branch information
traversaro authored Aug 14, 2024
2 parents 50ce674 + 4017827 commit 5c1f89a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
15 changes: 12 additions & 3 deletions YCMConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,20 @@ if(NOT DEFINED YCM_USE_CMAKE OR YCM_USE_CMAKE)
endif()

# Use modules from unreleased CMake (default ON)
if(NOT DEFINED YCM_USE_CMAKE_NEXT OR NOT YCM_USE_CMAKE_NEXT)
set_property(GLOBAL PROPERTY YCM_USE_CMAKE_NEXT OFF)
if(CMAKE_VERSION VERSION_LESS 3.22)
set(YCM_USE_CMAKE_NEXT_DEFAULT_VALUE ON)
else()
set(YCM_USE_CMAKE_NEXT_DEFAULT_VALUE OFF)
endif()
option(YCM_USE_CMAKE_NEXT "Use legacy YCM fork of ExternalProject module instead of upstream CMake ExternalProject" ${YCM_USE_CMAKE_NEXT_DEFAULT_VALUE})
if(NOT YCM_USE_CMAKE_NEXT AND CMAKE_VERSION VERSION_LESS 3.22)
message(FATAL_ERROR "YCM_USE_CMAKE_NEXT set to OFF is not supported with CMake < 3.22")
endif()
if(YCM_USE_CMAKE_NEXT)
set_property(GLOBAL PROPERTY YCM_USE_CMAKE_NEXT ON)
list(APPEND YCM_MODULE_PATH "${YCM_MODULE_DIR}/cmake-next/proposed")
list(APPEND CMAKE_MODULE_PATH ${_YCM_SRC_DIR}/cmake-next/proposed)
else()
set_property(GLOBAL PROPERTY YCM_USE_CMAKE_NEXT OFF)
endif()

# Use modules from specific CMake versions (default ON)
Expand Down
20 changes: 17 additions & 3 deletions modules/YCMEPHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,10 @@ function(YCM_EP_HELPER _name)
# a git repo folder if it already exists

# We do not define the custom GIT DOWNLOAD command if the outside call of YCMEPHelper already redefined it
if(NOT DEFINED _YH_${_name}_DOWNLOAD_COMMAND)
# or if we are using the vendored ExternalProject of YCM, that already redefines DOWNLOAD internally
get_property(_yeph_YCM_USE_CMAKE_NEXT GLOBAL PROPERTY YCM_USE_CMAKE_NEXT)

if(NOT DEFINED _YH_${_name}_DOWNLOAD_COMMAND AND NOT _yeph_YCM_USE_CMAKE_NEXT)
# Coherently with how the gitclone command is created inside ExternalProject, we also define a CMake
# script that defines the clone commands, and then we call it
# This part is inspired by https://gitlab.kitware.com/cmake/cmake/-/blob/v3.30.2/Modules/ExternalProject/shared_internal_commands.cmake#L945-1034
Expand All @@ -1186,8 +1189,8 @@ function(YCM_EP_HELPER _name)
set(git_remote_name "origin")
endif()

_ep_get_tls_version(${_name} tls_version)
_ep_get_tls_verify(${_name} tls_verify)
set(tls_version "")
set(tls_verify "")
set(git_shallow "${_YH_${_name}_SHALLOW}")
set(git_progress "")
set(git_config "")
Expand Down Expand Up @@ -1216,6 +1219,7 @@ submodules=${git_submodules}
get_filename_component(work_dir "${${_name}_SOURCE_DIR}" PATH)

set(clone_script ${${_name}_TMP_DIR}/${_name}-gitsafeclone.cmake)
set(stamp_dir ${${_name}_STAMP_DIR})
_ycm_ep_write_gitclone_script(
${clone_script}
${${_name}_SOURCE_DIR}
Expand All @@ -1242,6 +1246,16 @@ submodules=${git_submodules}
-P ${clone_script}
)

# We use configure_file() to write the repo_info_file for compatibility
# with upstreams CMake's gitclone

set(repo_info_file ${stamp_dir}/${_name}-gitinfo.txt)
configure_file(
"${YCM_MODULE_DIR}/modules/YCMEPHelper/RepositoryInfo.txt.in"
"${repo_info_file}"
@ONLY
)

list(APPEND ${_name}_COMMAND_ARGS DOWNLOAD_COMMAND "${cmd}")
endif()

Expand Down
10 changes: 10 additions & 0 deletions modules/YCMEPHelper/RepositoryInfo.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This is a generated file and its contents are an internal implementation detail.
# The download step will be re-executed if anything in this file changes.
# No other meaning or use of this file is supported.

method=git
command=@cmd@
source_dir=@source_dir@
work_dir=@work_dir@
@extra_repo_info@

2 changes: 1 addition & 1 deletion modules/YCMEPHelper/gitsafeclone.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ if(EXISTS "@source_dir@")
set(number_of_tries 0)
while(error_code AND number_of_tries LESS 3)
execute_process(
COMMAND "@git_EXECUTABLE@" fetch @git_clone_options@ origin
COMMAND "@git_EXECUTABLE@" fetch origin
WORKING_DIRECTORY "@work_dir@/@src_name@"
RESULT_VARIABLE error_code
)
Expand Down
12 changes: 11 additions & 1 deletion tools/UseYCMFromSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@ list(APPEND CMAKE_MODULE_PATH ${_YCM_SRC_DIR}/modules)
list(APPEND CMAKE_MODULE_PATH ${_YCM_SRC_DIR}/find-modules)
list(APPEND CMAKE_MODULE_PATH ${_YCM_SRC_DIR}/build-modules)
list(APPEND CMAKE_MODULE_PATH ${_YCM_SRC_DIR}/style-modules)
if(NOT DEFINED YCM_USE_CMAKE_NEXT OR YCM_USE_CMAKE_NEXT)

if(CMAKE_VERSION VERSION_LESS 3.22)
set(YCM_USE_CMAKE_NEXT_DEFAULT_VALUE ON)
else()
set(YCM_USE_CMAKE_NEXT_DEFAULT_VALUE OFF)
endif()
option(YCM_USE_CMAKE_NEXT "Use legacy YCM fork of ExternalProject module instead of upstream CMake ExternalProject" ${YCM_USE_CMAKE_NEXT_DEFAULT_VALUE})
if(NOT YCM_USE_CMAKE_NEXT AND CMAKE_VERSION VERSION_LESS 3.22)
message(FATAL_ERROR "YCM_USE_CMAKE_NEXT set to OFF is not supported with CMake < 3.22")
endif()
if(YCM_USE_CMAKE_NEXT)
set_property(GLOBAL PROPERTY YCM_USE_CMAKE_NEXT ON)
list(APPEND CMAKE_MODULE_PATH ${_YCM_SRC_DIR}/cmake-next/proposed)
else()
Expand Down

0 comments on commit 5c1f89a

Please sign in to comment.