Skip to content

Commit

Permalink
Migrate YCMBootstrap to use FetchContent module (#1078)
Browse files Browse the repository at this point in the history
  • Loading branch information
traversaro authored Apr 26, 2022
1 parent 56c56bb commit d66f198
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 25 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ endmacro()
# Load options
include(RobotologySuperbuildOptions)

# Python-related logic
# Python-related logic
if(ROBOTOLOGY_USES_PYTHON)
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
execute_process(COMMAND ${Python3_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix=''))"
Expand All @@ -43,7 +43,7 @@ endif()
# Bootstrap YCM
set(YCM_FOLDER src)
set(YCM_COMPONENT core)
set(YCM_MINIMUM_VERSION 0.11.1)
set(YCM_MINIMUM_VERSION 0.14.0)

# Include logic for generating Conda recipes (by default it is disabled) and exit
if(ROBOTOLOGY_GENERATE_CONDA_RECIPES)
Expand All @@ -53,7 +53,7 @@ if(ROBOTOLOGY_GENERATE_CONDA_RECIPES)
return()
endif()

include(YCMBootstrap)
include(YCMBootstrapFetch)

include(FindOrBuildPackage)
include(YCMEPHelper)
Expand Down
2 changes: 2 additions & 0 deletions cmake/BuildYARP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
include(YCMEPHelper)
include(FindOrBuildPackage)

find_or_build_package(YCM QUIET)

set(YARP_OPTIONAL_DEPS "")
if(ROBOTOLOGY_ENABLE_ROBOT_TESTING)
find_or_build_package(RobotTestingFramework QUIET)
Expand Down
15 changes: 15 additions & 0 deletions cmake/BuildYCM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (C) 2022 iCub Facility, Istituto Italiano di Tecnologia
# Authors: Silvio Traversaro <[email protected]>
# CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT

include(YCMEPHelper)
include(FindOrBuildPackage)

ycm_ep_helper(YCM TYPE GIT
STYLE GITHUB
REPOSITORY robotology/ycm.git
COMPONENT core
FOLDER src)

set(YCM_CONDA_PKG_NAME ycm-cmake-modules)
set(YCM_CONDA_PKG_CONDA_FORGE_OVERRIDE ON)
48 changes: 26 additions & 22 deletions cmake/YCMBootstrap.cmake → cmake/YCMBootstrapFetch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
# This module is intentionally kept as small as possible in order to
# avoid the spreading of different modules.
#
# The real bootstrap is performed by the ycm_bootstrap macro from the
# YCMEPHelper module that is downloaded from the YCM package.

# CMake variables read as input by this module:
# YCM_MINIMUM_VERSION : minimum version of YCM requested to use a system YCM
# YCM_TAG : if no suitable system YCM was found, bootstrap from this
# : TAG (either branch, commit or tag) of YCM repository
# USE_SYSTEM_YCM : if defined and set FALSE, skip searching for a system
# YCM_MINIMUM_VERSION : minimum version of YCM requested to use a system YCM
# YCM_REPOSITORY : if no suitable system YCM was found, bootstrap from this
# : GitHub reporitory of YCM
# YCM_TAG : if no suitable system YCM was found, bootstrap from this
# : TAG (either branch, commit or tag) of YCM repository
# USE_SYSTEM_YCM : if defined and set FALSE, skip searching for a system
# YCM and always bootstrap


Expand Down Expand Up @@ -80,23 +80,27 @@ endif()

message(STATUS "YCM not found. Bootstrapping it.")

set(YCM_BOOTSTRAP_BASE_ADDRESS "https://raw.githubusercontent.com/robotology/ycm/HEAD" CACHE STRING "Base address of YCM repository")
# Replace old raw.github address to support existing builds
if("${YCM_BOOTSTRAP_BASE_ADDRESS}" MATCHES "raw.github.com")
string(REPLACE "raw.github.com" "raw.githubusercontent.com" _tmp ${YCM_BOOTSTRAP_BASE_ADDRESS})
set_property(CACHE YCM_BOOTSTRAP_BASE_ADDRESS PROPERTY VALUE "${_tmp}")
# Download and use a copy of the YCM library for bootstrapping
# This is different from the YCM that will be downloaded as part of the superbuild
include(FetchContent)
if(DEFINED YCM_REPOSITORY)
set(YCM_FETCHCONTENT_REPOSITORY ${YCM_REPOSITORY})
else()
set(YCM_FETCHCONTENT_REPOSITORY robotology/ycm.git)
endif()
# New github address does not accept "//" in the path, therefore we remove the last slash
if("${YCM_BOOTSTRAP_BASE_ADDRESS}" MATCHES "/$")
string(REGEX REPLACE "/$" "" _tmp ${_tmp})
set_property(CACHE YCM_BOOTSTRAP_BASE_ADDRESS PROPERTY VALUE "${_tmp}")
if(DEFINED YCM_TAG)
set(YCM_FETCHCONTENT_TAG ${YCM_TAG})
else()
set(YCM_FETCHCONTENT_TAG master)
endif()
mark_as_advanced(YCM_BOOTSTRAP_BASE_ADDRESS)
FetchContent_Declare(YCM
GIT_REPOSITORY https://github.com/${YCM_FETCHCONTENT_REPOSITORY}
GIT_TAG ${YCM_FETCHCONTENT_TAG})

if("${YCM_BOOTSTRAP_BASE_ADDRESS}" MATCHES "/HEAD$" AND YCM_TAG)
string(REGEX REPLACE "/HEAD$" "/${YCM_TAG}" YCM_BOOTSTRAP_BASE_ADDRESS ${YCM_BOOTSTRAP_BASE_ADDRESS})
FetchContent_GetProperties(YCM)
if(NOT YCM_POPULATED)
message(STATUS "Fetching YCM.")
FetchContent_Populate(YCM)
# Add YCM modules in CMAKE_MODULE_PATH
include(${ycm_SOURCE_DIR}/tools/UseYCMFromSource.cmake)
endif()

include(IncludeUrl)
include_url(${YCM_BOOTSTRAP_BASE_ADDRESS}/modules/YCMEPHelper.cmake)
ycm_bootstrap()

0 comments on commit d66f198

Please sign in to comment.