-
Notifications
You must be signed in to change notification settings - Fork 501
Description
It would be good if it works like alias target fallback of protoc. I know that the root cause is, from the fact that gRPC's cmake is not well written. But IMO it would be better to have it.
Describe your environment
- otel-cpp: latest (tried v1.22.2 and same code in main branch HEAD)
- compiler: GCC 15 (Fedora 42), 11 (RHEL 8)
- cmake: 3.29.x with ninja
- os: linux
Steps to reproduce
- Add absl, protobuf, gRPC as FetchContent
- Set
gRPC::
namespaced ALIAS targets to gRPC's
(as it is not defined so when it is used with add_subdirectory and similar things) - Configure & build it
I am attaching full cmake usage example all the way below.
What is the expected behavior?
Even with non-imported but aliased targets, it would be better to work without problem.
What is the actual behavior?
The (path) variable gRPC_CPP_PLUGIN_EXECUTABLE
which is from gRPC::grpc_cpp_plugin
becomes empty so protoc step of OTel-gRPC protos fail.
Additional context
It would be better if this gRPC cpp plugin discovery steps
opentelemetry-cpp/cmake/opentelemetry-proto.cmake
Lines 181 to 186 in c406864
if(TARGET gRPC::grpc_cpp_plugin) | |
project_build_tools_get_imported_location(gRPC_CPP_PLUGIN_EXECUTABLE | |
gRPC::grpc_cpp_plugin) | |
else() | |
find_program(gRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) | |
endif() |
works like this protoc discovery steps.
opentelemetry-cpp/CMakeLists.txt
Lines 401 to 412 in c406864
if(TARGET protobuf::protoc) | |
if(CMAKE_CROSSCOMPILING AND Protobuf_PROTOC_EXECUTABLE) | |
set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE}) | |
else() | |
project_build_tools_get_imported_location(PROTOBUF_PROTOC_EXECUTABLE | |
protobuf::protoc) | |
# If protobuf::protoc is not a imported target, then we use the target | |
# directly for fallback | |
if(NOT PROTOBUF_PROTOC_EXECUTABLE) | |
set(PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc) | |
endif() | |
endif() |
And below is the example of CMake-FetchContent usage.
message(STATUS "gRPC: Using FetchContent")
FetchContent_Declare(
absl
GIT_REPOSITORY https://github.com/grpc/grpc.git
GIT_TAG v1.39.1
SOURCE_SUBDIR third_party/abseil-cpp
EXCLUDE_FROM_ALL
OVERRIDE_FIND_PACKAGE
)
FetchContent_Declare(
protobuf
GIT_REPOSITORY https://github.com/grpc/grpc.git
GIT_TAG v1.39.1
SOURCE_SUBDIR third_party/protobuf/cmake
EXCLUDE_FROM_ALL
OVERRIDE_FIND_PACKAGE
)
FetchContent_Declare(
gRPC
GIT_REPOSITORY https://github.com/grpc/grpc.git
GIT_TAG v1.39.1
EXCLUDE_FROM_ALL
OVERRIDE_FIND_PACKAGE
)
set(gRPC_ABSL_PROVIDER "package")
set(gRPC_PROTOBUF_PROVIDER "package")
set(ABSL_PROPAGATE_CXX_STD ON)
set(RE2_BUILD_TESTING OFF)
set(gRPC_BUILD_TESTS OFF)
FetchContent_MakeAvailable(absl)
FetchContent_MakeAvailable(protobuf)
FetchContent_MakeAvailable(gRPC)
## grpc does not offer namespaced targets, so we create them
add_library(gRPC::grpc++ ALIAS grpc++)
add_library(gRPC::grpc++_reflection ALIAS grpc++_reflection)
add_executable(gRPC::grpc_cpp_plugin ALIAS grpc_cpp_plugin)
FetchContent_Declare(
opentelemetry-cpp
GIT_REPOSITORY https://github.com/open-telemetry/opentelemetry-cpp.git
GIT_TAG v1.22.2
OVERRIDE_FIND_PACKAGE
)
set(WITH_OTLP_GRPC ON)
set(WITH_OTLP_HTTP ON)
set(WITH_OTLP_FILE ON)
set(WITH_NO_DEPRECATED_CODE ON)
set(BUILD_TESTING OFF)
set(WITH_EXAMPLES OFF)
set(WITH_BENCHMARK OFF)
FetchContent_MakeAvailable(opentelemetry-cpp)