@@ -344,83 +344,23 @@ if(WITH_PROMETHEUS)
344344 include ("${opentelemetry-cpp_SOURCE_DIR}/cmake/prometheus-cpp.cmake" )
345345endif ()
346346
347+ #
348+ # Do we need protobuf and/or gRPC ?
349+ #
350+
347351if (WITH_OTLP_GRPC
348352 OR WITH_OTLP_HTTP
349353 OR WITH_OTLP_FILE)
350354
351- # Including the CMakeFindDependencyMacro resolves an error from
352- # gRPCConfig.cmake on some grpc versions. See
353- # https://github.com/grpc/grpc/pull/33361 for more details.
354- include (CMakeFindDependencyMacro)
355-
356- # Protobuf 3.22+ depends on abseil-cpp and must be found using the cmake
357- # find_package CONFIG search mode. The following attempts to find Protobuf
358- # using the CONFIG mode first, and if not found, falls back to the MODULE
359- # mode. See https://gitlab.kitware.com/cmake/cmake/-/issues/24321 for more
360- # details.
361- find_package (Protobuf CONFIG)
362- if (NOT Protobuf_FOUND)
363- find_package (Protobuf MODULE)
364- if (Protobuf_FOUND AND Protobuf_VERSION VERSION_GREATER_EQUAL "3.22.0" )
365- message (
366- WARNING
367- "Found Protobuf version ${Protobuf_VERSION} using MODULE mode. "
368- "Linking errors may occur. Protobuf 3.22+ depends on abseil-cpp "
369- "and should be found using the CONFIG mode." )
370- endif ()
371- endif ()
372-
355+ # find or fetch grpc before protobuf to allow protobuf to be built in-tree as
356+ # a grpc submodule.
373357 if (WITH_OTLP_GRPC)
374- find_package (gRPC CONFIG )
358+ include ( "${opentelemetry-cpp_SOURCE_DIR}/cmake/grpc.cmake" )
375359 endif ()
376- if ((NOT Protobuf_FOUND) OR (WITH_OTLP_GRPC AND NOT gRPC_FOUND))
377360
378- if (WIN32 AND (NOT DEFINED CMAKE_TOOLCHAIN_FILE))
379- message (FATAL_ERROR "Windows dependency installation failed!" )
380- endif ()
381- if (WIN32 )
382- include (${CMAKE_TOOLCHAIN_FILE} )
383- endif ()
384-
385- if (NOT Protobuf_FOUND)
386- find_package (Protobuf CONFIG REQUIRED)
387- endif ()
388- if (NOT gRPC_FOUND AND WITH_OTLP_GRPC)
389- find_package (gRPC CONFIG)
390- endif ()
391- if (WIN32 )
392- # Always use x64 protoc.exe
393- if (NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE} " )
394- set (Protobuf_PROTOC_EXECUTABLE
395- ${CMAKE_CURRENT_SOURCE_DIR} /tools/vcpkg/packages/protobuf_x64-windows/tools/protobuf/protoc.exe
396- )
397- endif ()
398- endif ()
399- endif ()
400- # Latest Protobuf imported targets and without legacy module support
401- if (TARGET protobuf::protoc)
402- if (CMAKE_CROSSCOMPILING AND Protobuf_PROTOC_EXECUTABLE)
403- set (PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE} )
404- else ()
405- project_build_tools_get_imported_location(PROTOBUF_PROTOC_EXECUTABLE
406- protobuf::protoc)
407- # If protobuf::protoc is not a imported target, then we use the target
408- # directly for fallback
409- if (NOT PROTOBUF_PROTOC_EXECUTABLE)
410- set (PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc)
411- endif ()
412- endif ()
413- elseif (Protobuf_PROTOC_EXECUTABLE)
414- # Some versions of FindProtobuf.cmake uses mixed case instead of uppercase
415- set (PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE} )
416- endif ()
417- include (CMakeDependentOption)
361+ include ("${opentelemetry-cpp_SOURCE_DIR}/cmake/protobuf.cmake" )
418362
419- message (STATUS "PROTOBUF_PROTOC_EXECUTABLE=${PROTOBUF_PROTOC_EXECUTABLE} " )
420- set (SAVED_CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY} )
421- set (CMAKE_CXX_CLANG_TIDY "" )
422363 include ("${opentelemetry-cpp_SOURCE_DIR}/cmake/opentelemetry-proto.cmake" )
423- set (CMAKE_CXX_CLANG_TIDY ${SAVED_CMAKE_CXX_CLANG_TIDY} )
424364endif ()
425365
426366#
@@ -644,11 +584,14 @@ if(opentelemetry-proto_VERSION)
644584 "opentelemetry-proto: ${opentelemetry-proto_VERSION} (${opentelemetry-proto_PROVIDER})"
645585 )
646586endif ()
647- if (Protobuf_FOUND)
648- message (STATUS "Protobuf: ${Protobuf_VERSION} " )
587+ if (Protobuf_VERSION)
588+ message (
589+ STATUS
590+ "Protobuf: ${Protobuf_VERSION} (${Protobuf_PROVIDER} - ${protobuf_lib_type} )"
591+ )
649592endif ()
650- if (gRPC_FOUND )
651- message (STATUS "gRPC: ${gRPC_VERSION} " )
593+ if (gRPC_VERSION )
594+ message (STATUS "gRPC: ${gRPC_VERSION} ( ${gRPC_PROVIDER} - ${grpc_lib_type} ) " )
652595endif ()
653596if (CURL_VERSION)
654597 message (STATUS "CURL: ${CURL_VERSION} (${CURL_PROVIDER} )" )
0 commit comments