Skip to content

Commit 6c4d45c

Browse files
authored
[CMAKE] Switch opentelemetry-proto to use FetchContent (#3524)
1 parent 1ad6674 commit 6c4d45c

File tree

2 files changed

+36
-56
lines changed

2 files changed

+36
-56
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,12 @@ endif()
640640
if(absl_FOUND)
641641
message(STATUS "Abseil: ${absl_VERSION}")
642642
endif()
643+
if(opentelemetry-proto_VERSION)
644+
message(
645+
STATUS
646+
"opentelemetry-proto: ${opentelemetry-proto_VERSION} (${opentelemetry-proto_PROVIDER})"
647+
)
648+
endif()
643649
if(Protobuf_FOUND)
644650
message(STATUS "Protobuf: ${Protobuf_VERSION}")
645651
endif()

cmake/opentelemetry-proto.cmake

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,54 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
#
5-
# The dependency on opentelemetry-proto can be provided different ways. By order
5+
# The dependency on opentelemetry-proto can be provided by order
66
# of decreasing priority, options are:
77
#
8-
# 1 - Use a provided package
8+
# 1 - Fetch from local source directory defined by the OTELCPP_PROTO_PATH variable
99
#
10-
# This is useful to build opentelemetry-cpp as part of a super project.
10+
# 2 - Fetch from the opentelemetry-proto git submodule (opentelemetry-cpp/third_party/opentelemetry-proto)
1111
#
12-
# The super project provides the path to the opentelemetry-proto source code
13-
# using variable ${OTELCPP_PROTO_PATH}
14-
#
15-
# 2 - Search for a opentelemetry-proto git submodule
16-
#
17-
# When git submodule is used, the opentelemetry-proto code is located in:
18-
# third_party/opentelemetry-proto
19-
#
20-
# 3 - Download opentelemetry-proto from github
21-
#
22-
# Code from the required version is used, unless a specific release tag is
23-
# provided in variable ${opentelemetry-proto}
12+
# 3 - Fetch from github using the git tag set in opentelemetry-cpp/third_party_release
2413
#
2514

15+
set(OPENTELEMETRY_PROTO_SUBMODULE "${opentelemetry-cpp_SOURCE_DIR}/third_party/opentelemetry-proto")
16+
2617
if(OTELCPP_PROTO_PATH)
2718
if(NOT EXISTS
2819
"${OTELCPP_PROTO_PATH}/opentelemetry/proto/common/v1/common.proto")
2920
message(
3021
FATAL_ERROR
3122
"OTELCPP_PROTO_PATH does not point to a opentelemetry-proto repository")
3223
endif()
33-
message(STATUS "opentelemetry-proto dependency satisfied by: external path")
34-
set(PROTO_PATH ${OTELCPP_PROTO_PATH})
35-
set(needs_proto_download FALSE)
24+
message(STATUS "fetching opentelemetry-proto from OTELCPP_PROTO_PATH=${OTELCPP_PROTO_PATH}")
25+
FetchContent_Declare(
26+
opentelemetry-proto
27+
SOURCE_DIR ${OTELCPP_PROTO_PATH}
28+
)
29+
set(opentelemetry-proto_PROVIDER "fetch_source")
30+
# If the opentelemetry-proto directory is a general directory then we don't have a good way to determine the version. Set it as unknown.
31+
set(opentelemetry-proto_VERSION "unknown")
32+
elseif(EXISTS ${OPENTELEMETRY_PROTO_SUBMODULE}/.git)
33+
message(STATUS "fetching opentelemetry-proto from git submodule")
34+
FetchContent_Declare(
35+
opentelemetry-proto
36+
SOURCE_DIR ${OPENTELEMETRY_PROTO_SUBMODULE}
37+
)
38+
set(opentelemetry-proto_PROVIDER "fetch_source")
39+
string(REGEX REPLACE "^v([0-9]+\\.[0-9]+\\.[0-9]+)$" "\\1" opentelemetry-proto_VERSION "${opentelemetry-proto_GIT_TAG}")
3640
else()
37-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/opentelemetry-proto/.git)
38-
message(STATUS "opentelemetry-proto dependency satisfied by: git submodule")
39-
set(PROTO_PATH
40-
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/opentelemetry-proto")
41-
set(needs_proto_download FALSE)
42-
else()
43-
message(
44-
STATUS "opentelemetry-proto dependency satisfied by: github download")
45-
if("${opentelemetry-proto}" STREQUAL "")
46-
file(READ "${CMAKE_CURRENT_LIST_DIR}/../third_party_release"
47-
OTELCPP_THIRD_PARTY_RELEASE_CONTENT)
48-
if(OTELCPP_THIRD_PARTY_RELEASE_CONTENT MATCHES
49-
"opentelemetry-proto=[ \\t]*([A-Za-z0-9_\\.\\-]+)")
50-
set(opentelemetry-proto "${CMAKE_MATCH_1}")
51-
else()
52-
set(opentelemetry-proto "v1.7.0")
53-
endif()
54-
unset(OTELCPP_THIRD_PARTY_RELEASE_CONTENT)
55-
endif()
56-
include(ExternalProject)
57-
ExternalProject_Add(
41+
FetchContent_Declare(
5842
opentelemetry-proto
5943
GIT_REPOSITORY https://github.com/open-telemetry/opentelemetry-proto.git
60-
GIT_TAG "${opentelemetry-proto_GIT_TAG}"
61-
UPDATE_COMMAND ""
62-
BUILD_COMMAND ""
63-
INSTALL_COMMAND ""
64-
CONFIGURE_COMMAND ""
65-
TEST_AFTER_INSTALL 0
66-
DOWNLOAD_NO_PROGRESS 1
67-
LOG_CONFIGURE 1
68-
LOG_BUILD 1
69-
LOG_INSTALL 1)
70-
ExternalProject_Get_Property(opentelemetry-proto INSTALL_DIR)
71-
set(PROTO_PATH "${INSTALL_DIR}/src/opentelemetry-proto")
72-
set(needs_proto_download TRUE)
73-
endif()
44+
GIT_TAG "${opentelemetry-proto_GIT_TAG}")
45+
set(opentelemetry-proto_PROVIDER "fetch_repository")
46+
string(REGEX REPLACE "^v([0-9]+\\.[0-9]+\\.[0-9]+)$" "\\1" opentelemetry-proto_VERSION "${opentelemetry-proto_GIT_TAG}")
7447
endif()
7548

49+
FetchContent_MakeAvailable(opentelemetry-proto)
50+
51+
set(PROTO_PATH "${opentelemetry-proto_SOURCE_DIR}")
52+
7653
set(COMMON_PROTO "${PROTO_PATH}/opentelemetry/proto/common/v1/common.proto")
7754
set(RESOURCE_PROTO
7855
"${PROTO_PATH}/opentelemetry/proto/resource/v1/resource.proto")
@@ -387,9 +364,6 @@ if(WITH_OTLP_GRPC)
387364
endif()
388365
endif()
389366

390-
if(needs_proto_download)
391-
add_dependencies(opentelemetry_proto opentelemetry-proto)
392-
endif()
393367
set_target_properties(opentelemetry_proto PROPERTIES EXPORT_NAME proto)
394368
patch_protobuf_targets(opentelemetry_proto)
395369

0 commit comments

Comments
 (0)