Skip to content

Commit

Permalink
Permit to use FetchContent_MakeAvailable when YCM is used via FetchCo…
Browse files Browse the repository at this point in the history
…ntent and other related changes (#463)
  • Loading branch information
traversaro authored Nov 9, 2024
1 parent f40b0b7 commit b1c62ba
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@


cmake_minimum_required(VERSION 3.16)
project(YCM NONE)
project(YCM VERSION 0.17.0 LANGUAGES NONE)

# Check if the project is the main project or included via FetchContent
if (NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
# Project is included via FetchContent
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/UseYCMFromSource.cmake)
return()
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/internal-modules")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules")
Expand Down
12 changes: 12 additions & 0 deletions YCMConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
# SPDX-FileCopyrightText: 2012-2021 Istituto Italiano di Tecnologia (IIT)
# SPDX-License-Identifier: BSD-3-Clause

# A macro to print a warning when using deprecated variables, called by
# variable_watch
macro(_YCM_DEPRECATED_VARIABLE_WARNING _variable)
message(DEPRECATION "The ${_variable} variable is deprecated")
endmacro()

set(YCM_VERSION @YCM_VERSION@)
set(YCM_VERSION_MAJOR @YCM_VERSION_MAJOR@)
set(YCM_VERSION_MINOR @YCM_VERSION_MINOR@)
set(YCM_VERSION_PATCH @YCM_VERSION_PATCH@)
set(YCM_VERSION_REVISION @YCM_VERSION_REVISION@)
variable_watch(YCM_VERSION_REVISION _ycm_deprecated_variable_warning)
set(YCM_VERSION_DATE @YCM_VERSION_DATE@)
variable_watch(YCM_VERSION_DATE _ycm_deprecated_variable_warning)
set(YCM_VERSION_DATE_REVISION @YCM_VERSION_DATE_REVISION@)
variable_watch(YCM_VERSION_DATE_REVISION _ycm_deprecated_variable_warning)
set(YCM_VERSION_API @YCM_VERSION_API@)
variable_watch(YCM_VERSION_API _ycm_deprecated_variable_warning)
set(YCM_VERSION_SHORT @YCM_VERSION_SHORT@)
variable_watch(YCM_VERSION_SHORT _ycm_deprecated_variable_warning)
set(YCM_VERSION_SOURCE @YCM_VERSION_SOURCE@)
variable_watch(YCM_VERSION_SOURCE _ycm_deprecated_variable_warning)
set(YCM_VERSION_DIRTY @YCM_VERSION_DIRTY@)
variable_watch(YCM_VERSION_DIRTY _ycm_deprecated_variable_warning)

@PACKAGE_INIT@

Expand Down
21 changes: 7 additions & 14 deletions internal-modules/YCMVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ This module should not be used outside YCM.

Variables defined by this module::

YCM_VERSION - Full version, including git commit and dirty state.
YCM_VERSION_MAJOR - YCM major version
YCM_VERSION_MINOR - YCM minor version
YCM_VERSION_PATCH - YCM patch version
YCM_VERSION_FULL - Full version, including git commit and dirty state.
YCM_VERSION_REVISION - Number of commits since latest release (git only)
YCM_VERSION_DATE - Date of the latest commit (git only)
YCM_VERSION_DATE_REVISION - Number of commits since of beginning of the day
Expand All @@ -30,13 +27,8 @@ Variables defined by this module::

include(GitInfo)

set(YCM_VERSION_MAJOR 0)
set(YCM_VERSION_MINOR 16)
set(YCM_VERSION_PATCH 9)

set(YCM_VERSION_API "${YCM_VERSION_MAJOR}.${YCM_VERSION_MINOR}")
set(YCM_VERSION_SHORT "${YCM_VERSION_MAJOR}.${YCM_VERSION_MINOR}.${YCM_VERSION_PATCH}")
set(YCM_VERSION "${YCM_VERSION_SHORT}")

unset(YCM_VERSION_SOURCE)
unset(YCM_VERSION_DIRTY)
Expand Down Expand Up @@ -73,22 +65,22 @@ if(DEFINED YCM_GIT_WT_HASH)
string(APPEND YCM_VERSION_SHORT ".${YCM_VERSION_REVISION}")
endif()
set(YCM_VERSION_SOURCE "${_date}+git${YCM_GIT_WT_HASH_SHORT}")
set(YCM_VERSION "${YCM_VERSION_SHORT}-${YCM_VERSION_SOURCE}")
set(YCM_VERSION_FULL "${YCM_VERSION_SHORT}-${YCM_VERSION_SOURCE}")
elseif(NOT "${YCM_GIT_WT_TAG}" STREQUAL "v${YCM_VERSION_SHORT}")
# This is the same commit as the latest tag, but the version different
# Probably some work in progress...
# Add some random information.
string(TIMESTAMP _ts "%Y%m%d")
string(APPEND YCM_VERSION_SHORT "~${_ts}")
set(YCM_VERSION "${YCM_VERSION_SHORT}")
set(YCM_VERSION_FULL "${YCM_VERSION_SHORT}")
else()
# Same commit as latest tag.
# Nothing to do
endif()
# Include information about the "dirty" status.
if(YCM_GIT_WT_DIRTY)
set(YCM_VERSION_DIRTY "dirty")
set(YCM_VERSION "${YCM_VERSION}+${YCM_VERSION_DIRTY}")
set(YCM_VERSION_FULL "${YCM_VERSION}+${YCM_VERSION_DIRTY}")
endif()
else()
# This is not a git repository or git is missing.
Expand All @@ -97,7 +89,7 @@ else()
# Add some random information.
string(TIMESTAMP YCM_VERSION_PATCH "%Y%m%d")
set(YCM_VERSION_SHORT "${YCM_VERSION_MAJOR}.${YCM_VERSION_MINOR}.${YCM_VERSION_PATCH}")
set(YCM_VERSION "${YCM_VERSION_SHORT}~dev")
set(YCM_VERSION_FULL "${YCM_VERSION_SHORT}~dev")
else()
# We assume that this is a release, there is not much that we can do if it's
# not.
Expand All @@ -111,6 +103,7 @@ if(YCM_VERSION_DEBUG)
YCM_VERSION_SHORT
YCM_VERSION_MAJOR
YCM_VERSION_MINOR
YCM_VERSION_FULL
YCM_VERSION_PATCH
YCM_VERSION_REVISION
YCM_VERSION_DATE
Expand All @@ -122,4 +115,4 @@ if(YCM_VERSION_DEBUG)
endforeach()
endif()

message(STATUS "YCM Version: ${YCM_VERSION} (${YCM_VERSION_SHORT})")
message(STATUS "YCM Version: ${YCM_VERSION_FULL} (${YCM_VERSION_SHORT})")
9 changes: 1 addition & 8 deletions tools/YCMBootstrapFetch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,4 @@ FetchContent_Declare(YCM
GIT_REPOSITORY https://github.com/${YCM_FETCHCONTENT_REPOSITORY}
GIT_TAG ${YCM_FETCHCONTENT_TAG})

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()

FetchContent_MakeAvailable(YCM)

0 comments on commit b1c62ba

Please sign in to comment.