@@ -346,83 +346,23 @@ if(WITH_PROMETHEUS)
346346 include ("${opentelemetry-cpp_SOURCE_DIR}/cmake/prometheus-cpp.cmake" )
347347endif ()
348348
349+ #
350+ # Do we need protobuf and/or gRPC ?
351+ #
352+
349353if (WITH_OTLP_GRPC
350354 OR WITH_OTLP_HTTP
351355 OR WITH_OTLP_FILE)
352356
353- # Including the CMakeFindDependencyMacro resolves an error from
354- # gRPCConfig.cmake on some grpc versions. See
355- # https://github.com/grpc/grpc/pull/33361 for more details.
356- include (CMakeFindDependencyMacro)
357-
358- # Protobuf 3.22+ depends on abseil-cpp and must be found using the cmake
359- # find_package CONFIG search mode. The following attempts to find Protobuf
360- # using the CONFIG mode first, and if not found, falls back to the MODULE
361- # mode. See https://gitlab.kitware.com/cmake/cmake/-/issues/24321 for more
362- # details.
363- find_package (Protobuf CONFIG)
364- if (NOT Protobuf_FOUND)
365- find_package (Protobuf MODULE)
366- if (Protobuf_FOUND AND Protobuf_VERSION VERSION_GREATER_EQUAL "3.22.0" )
367- message (
368- WARNING
369- "Found Protobuf version ${Protobuf_VERSION} using MODULE mode. "
370- "Linking errors may occur. Protobuf 3.22+ depends on abseil-cpp "
371- "and should be found using the CONFIG mode." )
372- endif ()
373- endif ()
374-
357+ # find or fetch grpc before protobuf to allow protobuf to be built in-tree as
358+ # a grpc submodule.
375359 if (WITH_OTLP_GRPC)
376- find_package (gRPC CONFIG )
360+ include ( "${opentelemetry-cpp_SOURCE_DIR}/cmake/grpc.cmake" )
377361 endif ()
378- if ((NOT Protobuf_FOUND) OR (WITH_OTLP_GRPC AND NOT gRPC_FOUND))
379362
380- if (WIN32 AND (NOT DEFINED CMAKE_TOOLCHAIN_FILE))
381- message (FATAL_ERROR "Windows dependency installation failed!" )
382- endif ()
383- if (WIN32 )
384- include (${CMAKE_TOOLCHAIN_FILE} )
385- endif ()
386-
387- if (NOT Protobuf_FOUND)
388- find_package (Protobuf CONFIG REQUIRED)
389- endif ()
390- if (NOT gRPC_FOUND AND WITH_OTLP_GRPC)
391- find_package (gRPC CONFIG)
392- endif ()
393- if (WIN32 )
394- # Always use x64 protoc.exe
395- if (NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE} " )
396- set (Protobuf_PROTOC_EXECUTABLE
397- ${CMAKE_CURRENT_SOURCE_DIR} /tools/vcpkg/packages/protobuf_x64-windows/tools/protobuf/protoc.exe
398- )
399- endif ()
400- endif ()
401- endif ()
402- # Latest Protobuf imported targets and without legacy module support
403- if (TARGET protobuf::protoc)
404- if (CMAKE_CROSSCOMPILING AND Protobuf_PROTOC_EXECUTABLE)
405- set (PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE} )
406- else ()
407- project_build_tools_get_imported_location(PROTOBUF_PROTOC_EXECUTABLE
408- protobuf::protoc)
409- # If protobuf::protoc is not a imported target, then we use the target
410- # directly for fallback
411- if (NOT PROTOBUF_PROTOC_EXECUTABLE)
412- set (PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc)
413- endif ()
414- endif ()
415- elseif (Protobuf_PROTOC_EXECUTABLE)
416- # Some versions of FindProtobuf.cmake uses mixed case instead of uppercase
417- set (PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE} )
418- endif ()
419- include (CMakeDependentOption)
363+ include ("${opentelemetry-cpp_SOURCE_DIR}/cmake/protobuf.cmake" )
420364
421- message (STATUS "PROTOBUF_PROTOC_EXECUTABLE=${PROTOBUF_PROTOC_EXECUTABLE} " )
422- set (SAVED_CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY} )
423- set (CMAKE_CXX_CLANG_TIDY "" )
424365 include ("${opentelemetry-cpp_SOURCE_DIR}/cmake/opentelemetry-proto.cmake" )
425- set (CMAKE_CXX_CLANG_TIDY ${SAVED_CMAKE_CXX_CLANG_TIDY} )
426366endif ()
427367
428368#
@@ -658,11 +598,14 @@ if(opentelemetry-proto_VERSION)
658598 "opentelemetry-proto: ${opentelemetry-proto_VERSION} (${opentelemetry-proto_PROVIDER})"
659599 )
660600endif ()
661- if (Protobuf_FOUND)
662- message (STATUS "Protobuf: ${Protobuf_VERSION} " )
601+ if (Protobuf_VERSION)
602+ message (
603+ STATUS
604+ "Protobuf: ${Protobuf_VERSION} (${Protobuf_PROVIDER} - ${protobuf_lib_type} )"
605+ )
663606endif ()
664- if (gRPC_FOUND )
665- message (STATUS "gRPC: ${gRPC_VERSION} " )
607+ if (gRPC_VERSION )
608+ message (STATUS "gRPC: ${gRPC_VERSION} ( ${gRPC_PROVIDER} - ${grpc_lib_type} ) " )
666609endif ()
667610if (CURL_VERSION)
668611 message (STATUS "CURL: ${CURL_VERSION} (${CURL_PROVIDER} )" )
0 commit comments