From 26e7d0029d36ec62f6b0173b7e16eb2707c7343f Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Wed, 6 Apr 2022 19:54:52 +0200 Subject: [PATCH 1/9] Create UseYCMFromSource.cmake --- tools/UseYCMFromSource.cmake | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tools/UseYCMFromSource.cmake diff --git a/tools/UseYCMFromSource.cmake b/tools/UseYCMFromSource.cmake new file mode 100644 index 00000000..1829a77b --- /dev/null +++ b/tools/UseYCMFromSource.cmake @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: 2012-2021 Istituto Italiano di Tecnologia (IIT) +# SPDX-License-Identifier: BSD-3-Clause + +# This module can be used to use YCM modules directly from the source repo, +# to just use them in the build without installing them. + +if(DEFINED __USEYCMFROMSOURCE_INCLUDED) + return() +endif() +set(__USEYCMFROMSOURCE_INCLUDED TRUE) + +get_filename_component(_YCM_SRC_DIR ${CMAKE_CURRENT_LIST_DIR} DIRECTORY) + +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) +list(APPEND CMAKE_MODULE_PATH ${_YCM_SRC_DIR}/cmake-next/proposed) From 357a914113ae9a58b3a9456e12b8d3a5a3913201 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Wed, 6 Apr 2022 19:58:28 +0200 Subject: [PATCH 2/9] Update YCMEPHelper.cmake --- modules/YCMEPHelper.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/YCMEPHelper.cmake b/modules/YCMEPHelper.cmake index 58e1e003..e747a2c7 100644 --- a/modules/YCMEPHelper.cmake +++ b/modules/YCMEPHelper.cmake @@ -92,7 +92,7 @@ set(_ycm_YCMBootstrap_sha1sum 59c6dfc84ec36518c5be5aef13af252a8250bad7) # new scope the variables added by the included files. macro(_YCM_INCLUDE _module) - if(YCM_FOUND) + if(YCM_FOUND OR DEFINED __USEYCMFROMSOURCE_INCLUDED) include(${_module}) else() # We assume that YCMEPHelper was included using include_url, or that at @@ -215,7 +215,7 @@ macro(_YCM_SETUP) set(_print-directories-all print-directories-all) endif() - if(NOT YCM_FOUND) # Useless if we don't need to bootstrap + if(NOT (YCM_FOUND OR DEFINED __USEYCMFROMSOURCE_INCLUDED)) # Useless if we don't need to bootstrap set(YCM_BOOTSTRAP_BASE_ADDRESS "https://raw.github.com/robotology/ycm/HEAD/" CACHE STRING "Base address of YCM repository") mark_as_advanced(YCM_BOOTSTRAP_BASE_ADDRESS) endif() @@ -1327,7 +1327,7 @@ endfunction() unset(__YCM_BOOTSTRAPPED_CALLED CACHE) macro(YCM_BOOTSTRAP) - if(YCM_FOUND OR DEFINED __YCM_BOOTSTRAPPED_CALLED) + if(YCM_FOUND OR DEFINED __YCM_BOOTSTRAPPED_CALLED OR DEFINED __USEYCMFROMSOURCE_INCLUDED) return() endif() set(__YCM_BOOTSTRAPPED_CALLED TRUE CACHE INTERNAL "") From 819a6bb45dcdfc8fcf8bd422de11dd358b3d4ca1 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Wed, 13 Apr 2022 17:41:56 +0200 Subject: [PATCH 3/9] Create YCMBootstrapFetch.cmake --- tools/YCMBootstrapFetch.cmake | 96 +++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 tools/YCMBootstrapFetch.cmake diff --git a/tools/YCMBootstrapFetch.cmake b/tools/YCMBootstrapFetch.cmake new file mode 100644 index 00000000..3380bcd5 --- /dev/null +++ b/tools/YCMBootstrapFetch.cmake @@ -0,0 +1,96 @@ +# SPDX-FileCopyrightText: 2012-2021 Istituto Italiano di Tecnologia (IIT) +# SPDX-License-Identifier: BSD-3-Clause + +# This module is intentionally kept as small as possible in order to +# avoid the spreading of different modules. +# + +# 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 and always bootstrap + + +if(DEFINED __YCMBOOTSTRAP_INCLUDED) + return() +endif() +set(__YCMBOOTSTRAP_INCLUDED TRUE) + + +######################################################################## +# _YCM_CLEAN_PATH +# +# Internal function that removes a directory and its subfolder from an +# environment variable. +# This is useful because will stop CMake from finding the external +# projects built in the main project on the second CMake run. +# +# _path: path that should be removed +# _envvar: environment variable to clean + +function(_YCM_CLEAN_PATH _path _envvar) + get_filename_component(_path ${_path} REALPATH) + set(_var_new "") + if(NOT "$ENV{${_envvar}}" MATCHES "^$") + file(TO_CMAKE_PATH "$ENV{${_envvar}}" _var_old) + if(NOT WIN32) + # CMake handles correctly ":" except for the first character + string(REPLACE ":" ";" _var_old "${_var_old}") + endif() + foreach(_dir ${_var_old}) + get_filename_component(_dir ${_dir} REALPATH) + if(NOT "${_dir}" MATCHES "^${_path}") + list(APPEND _var_new ${_dir}) + endif() + endforeach() + endif() + list(REMOVE_DUPLICATES _var_new) + file(TO_NATIVE_PATH "${_var_new}" _var_new) + if(NOT WIN32) + string(REPLACE ";" ":" _var_new "${_var_new}") + endif() + set(ENV{${_envvar}} "${_var_new}") +endfunction() + + +# Remove binary dir from CMAKE_PREFIX_PATH and PATH before searching for +# YCM, in order to avoid to find the YCM version bootstrapped by YCM +# itself. +_ycm_clean_path("${CMAKE_BINARY_DIR}/install" CMAKE_PREFIX_PATH) +_ycm_clean_path("${CMAKE_BINARY_DIR}/install" PATH) + + +# If the USE_SYSTEM_YCM is explicitly set to false, we just skip to bootstrap. +if(NOT DEFINED USE_SYSTEM_YCM OR USE_SYSTEM_YCM) + find_package(YCM ${YCM_MINIMUM_VERSION} QUIET) + if(COMMAND set_package_properties) + set_package_properties(YCM PROPERTIES TYPE RECOMMENDED + PURPOSE "Used by the build system") + endif() + if(YCM_FOUND) + message(STATUS "YCM found in ${YCM_MODULE_DIR}.") + set_property(GLOBAL APPEND PROPERTY YCM_PROJECTS YCM) + return() + endif() +endif() + +message(STATUS "YCM not found. Bootstrapping it.") + +# 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) +FetchContent_Declare(YCM + GIT_REPOSITORY https://github.com/robotology/ycm + GIT_TAG master) + +FetchContent_GetProperties(YCM) +if(NOT YCM_POPULATED) + message(STATUS "Fetching YCM.") + FetchContent_Populate(YCM) + # Add YCM modules in CMAKE_MODULE_PATH + message(STATUS "YCM_SOURCE_DIR: ${ycm_SOURCE_DIR}") + include(${ycm_SOURCE_DIR}/tools/UseYCMFromSource.cmake) +endif() + From 23949b13e32ff6d60a4e189f3e8946535ab2f4bf Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Wed, 13 Apr 2022 17:44:02 +0200 Subject: [PATCH 4/9] Update YCMBootstrapFetch.cmake --- tools/YCMBootstrapFetch.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/YCMBootstrapFetch.cmake b/tools/YCMBootstrapFetch.cmake index 3380bcd5..6a750994 100644 --- a/tools/YCMBootstrapFetch.cmake +++ b/tools/YCMBootstrapFetch.cmake @@ -81,9 +81,14 @@ message(STATUS "YCM not found. Bootstrapping it.") # 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_TAG) + set(YCM_FETCHCONTENT_TAG ${YCM_TAG}) +else() + set(YCM_FETCHCONTENT_TAG master) +endif() FetchContent_Declare(YCM GIT_REPOSITORY https://github.com/robotology/ycm - GIT_TAG master) + GIT_TAG ${YCM_FETCHCONTENT_TAG}) FetchContent_GetProperties(YCM) if(NOT YCM_POPULATED) From 3384eb7dea8743eb73243051eebb6e3da21b4248 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Wed, 13 Apr 2022 18:14:55 +0200 Subject: [PATCH 5/9] Update YCMBootstrapFetch.cmake --- tools/YCMBootstrapFetch.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/YCMBootstrapFetch.cmake b/tools/YCMBootstrapFetch.cmake index 6a750994..8762880f 100644 --- a/tools/YCMBootstrapFetch.cmake +++ b/tools/YCMBootstrapFetch.cmake @@ -95,7 +95,6 @@ if(NOT YCM_POPULATED) message(STATUS "Fetching YCM.") FetchContent_Populate(YCM) # Add YCM modules in CMAKE_MODULE_PATH - message(STATUS "YCM_SOURCE_DIR: ${ycm_SOURCE_DIR}") include(${ycm_SOURCE_DIR}/tools/UseYCMFromSource.cmake) endif() From a3e48890fa104f8c3177bf744b1120f60bcc0ac1 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Thu, 14 Apr 2022 14:30:38 +0200 Subject: [PATCH 6/9] Update ycm-using.7.rst --- help/manual/ycm-using.7.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/help/manual/ycm-using.7.rst b/help/manual/ycm-using.7.rst index 8ce03761..ff9a5b7c 100644 --- a/help/manual/ycm-using.7.rst +++ b/help/manual/ycm-using.7.rst @@ -123,7 +123,7 @@ Using YCM as Soft Dependency ---------------------------- In order to make it a soft dependency, you will need to get the files -``tools/YCMBootstrap.cmake`` and ``modules/IncludeUrl.cmake`` from the YCM +``tools/YCMBootstrapFetch.cmake`` from the YCM sources (see :manual:`ycm-installing(7)` for instructions on how to download YCM) and copy them inside your project tree: @@ -131,8 +131,7 @@ YCM) and copy them inside your project tree: cd mkdir cmake - cp /tools/YCMBootstrap.cmake cmake - cp modules/IncludeUrl.cmake cmake + cp /tools/YCMBootstrapFetch.cmake cmake These files must be in a folder included in :cmake:variable:`CMAKE_MODULE_PATH` for your project: @@ -141,7 +140,7 @@ for your project: list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -Now you can include ``YCMBootstrap.cmake``: +Now you can include ``YCMBootstrapFetch.cmake``: .. code-block:: cmake @@ -149,7 +148,7 @@ Now you can include ``YCMBootstrap.cmake``: # set(YCM_TAG [tag, branch, or commit hash]) # Bootstrap YCM - include(YCMBootstrap) + include(YCMBootstrapFetch) This is the suggested method when you build a superbuild. Downloading all your project would require a network connection anyway, therefore you will need to From c83f70b4f58789ab63b4fe64d0265fc304683540 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Thu, 14 Apr 2022 14:33:27 +0200 Subject: [PATCH 7/9] Update ycm-superbuild-example.7.rst --- help/manual/ycm-superbuild-example.7.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/help/manual/ycm-superbuild-example.7.rst b/help/manual/ycm-superbuild-example.7.rst index e5b0abbb..54f025f2 100644 --- a/help/manual/ycm-superbuild-example.7.rst +++ b/help/manual/ycm-superbuild-example.7.rst @@ -107,7 +107,7 @@ Create a ``CMakeLists.txt`` with this content: # Choose whether you want YCM to be a soft or a hard dependency and uncomment # the appropriate line: - include(YCMBootstrap) # This will make it a soft dependency + include(YCMBootstrapFetch) # This will make it a soft dependency # find_package(YCM 0.1 REQUIRED) # This will make it a hard dependency include(FindOrBuildPackage) From ad7cc7cc2fd29211be548a4465c7edd9426dc9c3 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Thu, 14 Apr 2022 14:34:26 +0200 Subject: [PATCH 8/9] Update ycm-superbuild-example.7.rst --- help/manual/ycm-superbuild-example.7.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/help/manual/ycm-superbuild-example.7.rst b/help/manual/ycm-superbuild-example.7.rst index 54f025f2..91796250 100644 --- a/help/manual/ycm-superbuild-example.7.rst +++ b/help/manual/ycm-superbuild-example.7.rst @@ -125,12 +125,12 @@ Create a ``cmake`` folder that will contain all required CMake modules mkdir cmake If you want YCM as a soft dependency you will need to get the files -``tools/YCMBootstrap.cmake`` and ``modules/IncludeUrl.cmake`` from the YCM +``tools/YCMBootstrapFetch.cmake`` from the YCM sources. If you want to make it a hard dependency you don't have to add these files, but the user will have to install YCM before he can build the superbuild. .. note: - If the user has YCM installed, ``YCMBootstrap`` will find it and will + If the user has YCM installed, ``YCMBootstrapFetch`` will find it and will not download it again, but it will use the user's installation. Create the files ``cmake/BuildTemplatePkg.cmake`` and From 1f7f179403412270d5ee7dd2aaca927f96de7c78 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Thu, 14 Apr 2022 14:37:36 +0200 Subject: [PATCH 9/9] Update CHANGELOG.md --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28205941..d614a554 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased Minor] ### Added -* Added new find module `FindSOXR.cmake` for libsoxr (https://github.com/robotology/ycm/pull/385) +* Added new find module `FindSOXR.cmake` for libsoxr (https://github.com/robotology/ycm/pull/385). +* Add new `YCMBootstrapFetch.cmake` module that substitutes the `YCMBootstrap.cmake` module (https://github.com/robotology/ycm/pull/403). The new `YCMBootstrapFetch.cmake` script to permit projects to bootstrap YCM by just using `FetchContent` module. A different file is created as the semantics of this new bootstrap script is a bit different, as it just make YCM available in the project, but it does not also adds it as a subproject in the superbuild sense. Superbuilds that want to switch from `YCMBootstrap.cmake` to `YCMBootstrapFetch.cmake` need to create `BuildYCM.cmake` script, and appropriately call `find_or_build_package(YCM)`, as done for example in the robotology-superbuild in https://github.com/robotology/robotology-superbuild/pull/1078 . ### Changed * CMake 3.16 or later is now required (https://github.com/robotology/ycm/pull/386). * The `CMakeRC` module is imported again from the official repository, and it no longer prints the debug message (https://github.com/robotology/ycm/pull/384). +### Deprecated +* The `YCMBootstrap.cmake` module is now deprecated (https://github.com/robotology/ycm/pull/403). + ### Removed * Removed `FindEigen3.cmake` module (https://github.com/robotology/ycm/pull/399).