Skip to content

Commit b1c62ba

Browse files
authored
Permit to use FetchContent_MakeAvailable when YCM is used via FetchContent and other related changes (#463)
1 parent f40b0b7 commit b1c62ba

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33

44

55
cmake_minimum_required(VERSION 3.16)
6-
project(YCM NONE)
6+
project(YCM VERSION 0.17.0 LANGUAGES NONE)
7+
8+
# Check if the project is the main project or included via FetchContent
9+
if (NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
10+
# Project is included via FetchContent
11+
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/UseYCMFromSource.cmake)
12+
return()
13+
endif()
714

815
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/internal-modules")
916
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules")

YCMConfig.cmake.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
# SPDX-FileCopyrightText: 2012-2021 Istituto Italiano di Tecnologia (IIT)
22
# SPDX-License-Identifier: BSD-3-Clause
33

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

510
set(YCM_VERSION @YCM_VERSION@)
611
set(YCM_VERSION_MAJOR @YCM_VERSION_MAJOR@)
712
set(YCM_VERSION_MINOR @YCM_VERSION_MINOR@)
813
set(YCM_VERSION_PATCH @YCM_VERSION_PATCH@)
914
set(YCM_VERSION_REVISION @YCM_VERSION_REVISION@)
15+
variable_watch(YCM_VERSION_REVISION _ycm_deprecated_variable_warning)
1016
set(YCM_VERSION_DATE @YCM_VERSION_DATE@)
17+
variable_watch(YCM_VERSION_DATE _ycm_deprecated_variable_warning)
1118
set(YCM_VERSION_DATE_REVISION @YCM_VERSION_DATE_REVISION@)
19+
variable_watch(YCM_VERSION_DATE_REVISION _ycm_deprecated_variable_warning)
1220
set(YCM_VERSION_API @YCM_VERSION_API@)
21+
variable_watch(YCM_VERSION_API _ycm_deprecated_variable_warning)
1322
set(YCM_VERSION_SHORT @YCM_VERSION_SHORT@)
23+
variable_watch(YCM_VERSION_SHORT _ycm_deprecated_variable_warning)
1424
set(YCM_VERSION_SOURCE @YCM_VERSION_SOURCE@)
25+
variable_watch(YCM_VERSION_SOURCE _ycm_deprecated_variable_warning)
1526
set(YCM_VERSION_DIRTY @YCM_VERSION_DIRTY@)
27+
variable_watch(YCM_VERSION_DIRTY _ycm_deprecated_variable_warning)
1628

1729
@PACKAGE_INIT@
1830

internal-modules/YCMVersion.cmake

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ This module should not be used outside YCM.
1111
1212
Variables defined by this module::
1313
14-
YCM_VERSION - Full version, including git commit and dirty state.
15-
YCM_VERSION_MAJOR - YCM major version
16-
YCM_VERSION_MINOR - YCM minor version
17-
YCM_VERSION_PATCH - YCM patch version
14+
YCM_VERSION_FULL - Full version, including git commit and dirty state.
1815
YCM_VERSION_REVISION - Number of commits since latest release (git only)
1916
YCM_VERSION_DATE - Date of the latest commit (git only)
2017
YCM_VERSION_DATE_REVISION - Number of commits since of beginning of the day
@@ -30,13 +27,8 @@ Variables defined by this module::
3027

3128
include(GitInfo)
3229

33-
set(YCM_VERSION_MAJOR 0)
34-
set(YCM_VERSION_MINOR 16)
35-
set(YCM_VERSION_PATCH 9)
36-
3730
set(YCM_VERSION_API "${YCM_VERSION_MAJOR}.${YCM_VERSION_MINOR}")
3831
set(YCM_VERSION_SHORT "${YCM_VERSION_MAJOR}.${YCM_VERSION_MINOR}.${YCM_VERSION_PATCH}")
39-
set(YCM_VERSION "${YCM_VERSION_SHORT}")
4032

4133
unset(YCM_VERSION_SOURCE)
4234
unset(YCM_VERSION_DIRTY)
@@ -73,22 +65,22 @@ if(DEFINED YCM_GIT_WT_HASH)
7365
string(APPEND YCM_VERSION_SHORT ".${YCM_VERSION_REVISION}")
7466
endif()
7567
set(YCM_VERSION_SOURCE "${_date}+git${YCM_GIT_WT_HASH_SHORT}")
76-
set(YCM_VERSION "${YCM_VERSION_SHORT}-${YCM_VERSION_SOURCE}")
68+
set(YCM_VERSION_FULL "${YCM_VERSION_SHORT}-${YCM_VERSION_SOURCE}")
7769
elseif(NOT "${YCM_GIT_WT_TAG}" STREQUAL "v${YCM_VERSION_SHORT}")
7870
# This is the same commit as the latest tag, but the version different
7971
# Probably some work in progress...
8072
# Add some random information.
8173
string(TIMESTAMP _ts "%Y%m%d")
8274
string(APPEND YCM_VERSION_SHORT "~${_ts}")
83-
set(YCM_VERSION "${YCM_VERSION_SHORT}")
75+
set(YCM_VERSION_FULL "${YCM_VERSION_SHORT}")
8476
else()
8577
# Same commit as latest tag.
8678
# Nothing to do
8779
endif()
8880
# Include information about the "dirty" status.
8981
if(YCM_GIT_WT_DIRTY)
9082
set(YCM_VERSION_DIRTY "dirty")
91-
set(YCM_VERSION "${YCM_VERSION}+${YCM_VERSION_DIRTY}")
83+
set(YCM_VERSION_FULL "${YCM_VERSION}+${YCM_VERSION_DIRTY}")
9284
endif()
9385
else()
9486
# This is not a git repository or git is missing.
@@ -97,7 +89,7 @@ else()
9789
# Add some random information.
9890
string(TIMESTAMP YCM_VERSION_PATCH "%Y%m%d")
9991
set(YCM_VERSION_SHORT "${YCM_VERSION_MAJOR}.${YCM_VERSION_MINOR}.${YCM_VERSION_PATCH}")
100-
set(YCM_VERSION "${YCM_VERSION_SHORT}~dev")
92+
set(YCM_VERSION_FULL "${YCM_VERSION_SHORT}~dev")
10193
else()
10294
# We assume that this is a release, there is not much that we can do if it's
10395
# not.
@@ -111,6 +103,7 @@ if(YCM_VERSION_DEBUG)
111103
YCM_VERSION_SHORT
112104
YCM_VERSION_MAJOR
113105
YCM_VERSION_MINOR
106+
YCM_VERSION_FULL
114107
YCM_VERSION_PATCH
115108
YCM_VERSION_REVISION
116109
YCM_VERSION_DATE
@@ -122,4 +115,4 @@ if(YCM_VERSION_DEBUG)
122115
endforeach()
123116
endif()
124117

125-
message(STATUS "YCM Version: ${YCM_VERSION} (${YCM_VERSION_SHORT})")
118+
message(STATUS "YCM Version: ${YCM_VERSION_FULL} (${YCM_VERSION_SHORT})")

tools/YCMBootstrapFetch.cmake

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,4 @@ FetchContent_Declare(YCM
9797
GIT_REPOSITORY https://github.com/${YCM_FETCHCONTENT_REPOSITORY}
9898
GIT_TAG ${YCM_FETCHCONTENT_TAG})
9999

100-
FetchContent_GetProperties(YCM)
101-
if(NOT YCM_POPULATED)
102-
message(STATUS "Fetching YCM.")
103-
FetchContent_Populate(YCM)
104-
# Add YCM modules in CMAKE_MODULE_PATH
105-
include(${ycm_SOURCE_DIR}/tools/UseYCMFromSource.cmake)
106-
endif()
107-
100+
FetchContent_MakeAvailable(YCM)

0 commit comments

Comments
 (0)