Skip to content

Commit

Permalink
chore: update otel cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
leoparente committed Aug 1, 2024
1 parent dffbf7b commit 14ad554
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 12 deletions.
89 changes: 79 additions & 10 deletions cmake/opentelemetry-proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ else()
message(
STATUS "opentelemetry-proto dependency satisfied by: github download")
if("${opentelemetry-proto}" STREQUAL "")
set(opentelemetry-proto "v1.0.0")
file(READ "${CMAKE_CURRENT_LIST_DIR}/../third_party_release"
OTELCPP_THIRD_PARTY_RELEASE_CONTENT)
if(OTELCPP_THIRD_PARTY_RELEASE_CONTENT MATCHES
"opentelemetry-proto=[ \\t]*([A-Za-z0-9_\\.\\-]+)")
set(opentelemetry-proto "${CMAKE_MATCH_1}")
else()
set(opentelemetry-proto "v1.3.2")
endif()
unset(OTELCPP_THIRD_PARTY_RELEASE_CONTENT)
endif()
include(ExternalProject)
ExternalProject_Add(
Expand Down Expand Up @@ -72,6 +80,12 @@ set(TRACE_PROTO "${PROTO_PATH}/opentelemetry/proto/trace/v1/trace.proto")
set(LOGS_PROTO "${PROTO_PATH}/opentelemetry/proto/logs/v1/logs.proto")
set(METRICS_PROTO "${PROTO_PATH}/opentelemetry/proto/metrics/v1/metrics.proto")

set(PROFILES_PROTO
"${PROTO_PATH}/opentelemetry/proto/profiles/v1experimental/profiles.proto")
set(PROFILES_EXT_PROTO
"${PROTO_PATH}/opentelemetry/proto/profiles/v1experimental/pprofextended.proto"
)

set(TRACE_SERVICE_PROTO
"${PROTO_PATH}/opentelemetry/proto/collector/trace/v1/trace_service.proto")
set(LOGS_SERVICE_PROTO
Expand All @@ -80,6 +94,10 @@ set(METRICS_SERVICE_PROTO
"${PROTO_PATH}/opentelemetry/proto/collector/metrics/v1/metrics_service.proto"
)

set(PROFILES_SERVICE_PROTO
"${PROTO_PATH}/opentelemetry/proto/collector/profiles/v1experimental/profiles_service.proto"
)

set(GENERATED_PROTOBUF_PATH
"${CMAKE_BINARY_DIR}/generated/third_party/opentelemetry-proto")

Expand Down Expand Up @@ -112,6 +130,41 @@ set(TRACE_SERVICE_PB_CPP_FILE
set(TRACE_SERVICE_PB_H_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/trace/v1/trace_service.pb.h"
)

#
# Notes about the PROFILES signal: - *.proto files added in opentelemetry-proto
# 1.3.0 - C++ code is generated from proto files - The generated code is not
# used yet.
#

set(PROFILES_CPP_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/profiles/v1experimental/profiles.pb.cc"
)
set(PROFILES_H_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/profiles/v1experimental/profiles.pb.h"
)
set(PROFILES_EXT_CPP_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/profiles/v1experimental/pprofextended.pb.cc"
)
set(PROFILES_EXT_H_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/profiles/v1experimental/pprofextended.pb.h"
)
set(PROFILES_SERVICE_PB_H_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/profiles/v1experimental/profiles_service.pb.h"
)
set(PROFILES_SERVICE_PB_CPP_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/profiles/v1experimental/profiles_service.pb.cc"
)

if(WITH_OTLP_GRPC)
set(PROFILES_SERVICE_GRPC_PB_H_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/profiles/v1experimental/profiles_service.grpc.pb.h"
)
set(PROFILES_SERVICE_GRPC_PB_CPP_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/profiles/v1experimental/profiles_service.grpc.pb.cc"
)
endif()

if(WITH_OTLP_GRPC)
set(TRACE_SERVICE_GRPC_PB_CPP_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.cc"
Expand Down Expand Up @@ -188,12 +241,18 @@ set(PROTOBUF_GENERATED_FILES
${LOGS_PB_CPP_FILE}
${METRICS_PB_H_FILE}
${METRICS_PB_CPP_FILE}
${PROFILES_H_FILE}
${PROFILES_CPP_FILE}
${PROFILES_EXT_H_FILE}
${PROFILES_EXT_CPP_FILE}
${TRACE_SERVICE_PB_H_FILE}
${TRACE_SERVICE_PB_CPP_FILE}
${LOGS_SERVICE_PB_H_FILE}
${LOGS_SERVICE_PB_CPP_FILE}
${METRICS_SERVICE_PB_H_FILE}
${METRICS_SERVICE_PB_CPP_FILE})
${METRICS_SERVICE_PB_CPP_FILE}
${PROFILES_SERVICE_PB_H_FILE}
${PROFILES_SERVICE_PB_CPP_FILE})

if(WITH_OTLP_GRPC)
list(APPEND PROTOBUF_COMMON_FLAGS
Expand All @@ -208,7 +267,9 @@ if(WITH_OTLP_GRPC)
${LOGS_SERVICE_GRPC_PB_H_FILE}
${LOGS_SERVICE_GRPC_PB_CPP_FILE}
${METRICS_SERVICE_GRPC_PB_H_FILE}
${METRICS_SERVICE_GRPC_PB_CPP_FILE})
${METRICS_SERVICE_GRPC_PB_CPP_FILE}
${PROFILES_SERVICE_GRPC_PB_H_FILE}
${PROFILES_SERVICE_GRPC_PB_CPP_FILE})
endif()

set(PROTOBUF_RUN_PROTOC_COMMAND "\"${PROTOBUF_PROTOC_EXECUTABLE}\"")
Expand All @@ -221,9 +282,12 @@ foreach(
${TRACE_PROTO}
${LOGS_PROTO}
${METRICS_PROTO}
${PROFILES_PROTO}
${PROFILES_EXT_PROTO}
${TRACE_SERVICE_PROTO}
${LOGS_SERVICE_PROTO}
${METRICS_SERVICE_PROTO})
${METRICS_SERVICE_PROTO}
${PROFILES_SERVICE_PROTO})
set(PROTOBUF_RUN_PROTOC_COMMAND
"${PROTOBUF_RUN_PROTOC_COMMAND} \"${PROTOBUF_RUN_PROTOC_ARG}\"")
endforeach()
Expand All @@ -234,7 +298,8 @@ add_custom_command(
${PROTOBUF_PROTOC_EXECUTABLE} ${PROTOBUF_COMMON_FLAGS}
${PROTOBUF_INCLUDE_FLAGS} ${COMMON_PROTO} ${RESOURCE_PROTO} ${TRACE_PROTO}
${LOGS_PROTO} ${METRICS_PROTO} ${TRACE_SERVICE_PROTO} ${LOGS_SERVICE_PROTO}
${METRICS_SERVICE_PROTO}
${METRICS_SERVICE_PROTO} ${PROFILES_PROTO} ${PROFILES_EXT_PROTO}
${PROFILES_SERVICE_PROTO}
COMMENT "[Run]: ${PROTOBUF_RUN_PROTOC_COMMAND}")

include_directories("${GENERATED_PROTOBUF_PATH}")
Expand All @@ -261,6 +326,12 @@ add_library(
${LOGS_SERVICE_PB_CPP_FILE}
${METRICS_SERVICE_PB_CPP_FILE})

# Disable include-what-you-use on generated code.
set_target_properties(
opentelemetry_proto
PROPERTIES CXX_INCLUDE_WHAT_YOU_USE ""
)

if(WITH_ABSEIL)
target_link_libraries(opentelemetry_proto PUBLIC absl::bad_variant_access)
endif()
Expand All @@ -272,13 +343,11 @@ if(WITH_OTLP_GRPC)
${LOGS_SERVICE_GRPC_PB_CPP_FILE} ${METRICS_SERVICE_GRPC_PB_CPP_FILE})

list(APPEND OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto_grpc)
target_link_libraries(opentelemetry_proto_grpc
PUBLIC opentelemetry_proto)
target_link_libraries(opentelemetry_proto_grpc PUBLIC opentelemetry_proto)

get_target_property(grpc_lib_type gRPC::grpc++ TYPE)
if (grpc_lib_type STREQUAL "SHARED_LIBRARY")
target_link_libraries(opentelemetry_proto_grpc
PUBLIC gRPC::grpc++)
if(grpc_lib_type STREQUAL "SHARED_LIBRARY")
target_link_libraries(opentelemetry_proto_grpc PUBLIC gRPC::grpc++)
endif()
set_target_properties(opentelemetry_proto_grpc PROPERTIES EXPORT_NAME
proto_grpc)
Expand Down
101 changes: 99 additions & 2 deletions cmake/opentelemetry-tools.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

macro(check_append_cxx_compiler_flag OUTPUT_VAR)
foreach(CHECK_FLAG ${ARGN})
check_cxx_compiler_flag(${CHECK_FLAG}
Expand All @@ -11,7 +14,16 @@ endmacro()
if(NOT PATCH_PROTOBUF_SOURCES_OPTIONS_SET)
if(MSVC)
unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE)
set(PATCH_PROTOBUF_SOURCES_OPTIONS /wd4244 /wd4251 /wd4267 /wd4309 /wd4668 /wd4946 /wd6001 /wd6244 /wd6246)
set(PATCH_PROTOBUF_SOURCES_OPTIONS
/wd4244
/wd4251
/wd4267
/wd4309
/wd4668
/wd4946
/wd6001
/wd6244
/wd6246)

if(MSVC_VERSION GREATER_EQUAL 1922)
# see
Expand All @@ -31,7 +43,7 @@ if(NOT PATCH_PROTOBUF_SOURCES_OPTIONS_SET)
unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE)
include(CheckCXXCompilerFlag)
check_append_cxx_compiler_flag(
PATCH_PROTOBUF_SOURCES_OPTIONS -Wno-type-limits -Wno-missing-declarations
PATCH_PROTOBUF_SOURCES_OPTIONS -Wno-type-limits -Wno-missing-declarations
-Wno-deprecated-declarations -Wno-unused-parameter)
endif()
set(PATCH_PROTOBUF_SOURCES_OPTIONS_SET TRUE)
Expand Down Expand Up @@ -114,3 +126,88 @@ function(project_build_tools_get_imported_location OUTPUT_VAR_NAME TARGET_NAME)
PARENT_SCOPE)
endif()
endfunction()

#[[
If we build third party packages with a different CONFIG setting from building
otel-cpp, cmake may not find a suitable file in imported targets (#705, #1359)
when linking. But on some platforms, different CONFIG settings can be used when
these CONFIG settings have the same ABI. For example, on Linux, we can build
gRPC and protobuf with -DCMAKE_BUILD_TYPE=Release, but build otel-cpp with
-DCMAKE_BUILD_TYPE=Debug and link these libraries together.
The properties of imported targets can be found here:
https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#properties-on-targets
]]
function(project_build_tools_patch_default_imported_config)
set(PATCH_VARS
IMPORTED_IMPLIB
IMPORTED_LIBNAME
IMPORTED_LINK_DEPENDENT_LIBRARIES
IMPORTED_LINK_INTERFACE_LANGUAGES
IMPORTED_LINK_INTERFACE_LIBRARIES
IMPORTED_LINK_INTERFACE_MULTIPLICITY
IMPORTED_LOCATION
IMPORTED_NO_SONAME
IMPORTED_OBJECTS
IMPORTED_SONAME)
foreach(TARGET_NAME ${ARGN})
if(TARGET ${TARGET_NAME})
get_target_property(IS_IMPORTED_TARGET ${TARGET_NAME} IMPORTED)
if(NOT IS_IMPORTED_TARGET)
continue()
endif()

get_target_property(IS_ALIAS_TARGET ${TARGET_NAME} ALIASED_TARGET)
if(IS_ALIAS_TARGET)
continue()
endif()

if(CMAKE_VERSION VERSION_LESS "3.19.0")
get_target_property(TARGET_TYPE_NAME ${TARGET_NAME} TYPE)
if(TARGET_TYPE_NAME STREQUAL "INTERFACE_LIBRARY")
continue()
endif()
endif()

get_target_property(DO_NOT_OVERWRITE ${TARGET_NAME} IMPORTED_LOCATION)
if(DO_NOT_OVERWRITE)
continue()
endif()

# MSVC's STL and debug level must match the target, so we can only move
# out IMPORTED_LOCATION_NOCONFIG
if(MSVC)
set(PATCH_IMPORTED_CONFIGURATION "NOCONFIG")
else()
get_target_property(PATCH_IMPORTED_CONFIGURATION ${TARGET_NAME}
IMPORTED_CONFIGURATIONS)
endif()

if(NOT PATCH_IMPORTED_CONFIGURATION)
continue()
endif()

get_target_property(PATCH_TARGET_LOCATION ${TARGET_NAME}
"IMPORTED_LOCATION_${PATCH_IMPORTED_CONFIGURATION}")
if(NOT PATCH_TARGET_LOCATION)
continue()
endif()

foreach(PATCH_IMPORTED_KEY IN LISTS PATCH_VARS)
get_target_property(
PATCH_IMPORTED_VALUE ${TARGET_NAME}
"${PATCH_IMPORTED_KEY}_${PATCH_IMPORTED_CONFIGURATION}")
if(PATCH_IMPORTED_VALUE)
set_target_properties(
${TARGET_NAME} PROPERTIES "${PATCH_IMPORTED_KEY}"
"${PATCH_IMPORTED_VALUE}")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(
STATUS
"Patch: ${TARGET_NAME} ${PATCH_IMPORTED_KEY} will use ${PATCH_IMPORTED_KEY}_${PATCH_IMPORTED_CONFIGURATION}(\"${PATCH_IMPORTED_VALUE}\") by default."
)
endif()
endif()
endforeach()
endif()
endforeach()
endfunction()

0 comments on commit 14ad554

Please sign in to comment.