From af81dddb1bef50ca11c48453283862725ec09c2b Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Mon, 23 Dec 2024 13:31:22 -0700 Subject: [PATCH 1/5] add cmake components to group targets --- CMakeLists.txt | 11 -- INSTALL.md | 63 +++++++ api/CMakeLists.txt | 8 +- cmake/opentelemetry-cpp-config.cmake.in | 241 +++++++++++++++++------- cmake/opentelemetry-proto.cmake | 13 +- exporters/elasticsearch/CMakeLists.txt | 9 +- exporters/etw/CMakeLists.txt | 8 +- exporters/memory/CMakeLists.txt | 9 +- exporters/ostream/CMakeLists.txt | 47 ++--- exporters/otlp/CMakeLists.txt | 82 ++++++-- exporters/prometheus/CMakeLists.txt | 8 +- exporters/zipkin/CMakeLists.txt | 12 +- ext/CMakeLists.txt | 9 +- ext/src/dll/CMakeLists.txt | 3 +- ext/src/http/client/curl/CMakeLists.txt | 3 +- opentracing-shim/CMakeLists.txt | 8 +- sdk/CMakeLists.txt | 9 +- sdk/src/common/CMakeLists.txt | 2 +- sdk/src/logs/CMakeLists.txt | 2 +- sdk/src/metrics/CMakeLists.txt | 2 +- sdk/src/resource/CMakeLists.txt | 2 +- sdk/src/trace/CMakeLists.txt | 2 +- sdk/src/version/CMakeLists.txt | 2 +- 23 files changed, 411 insertions(+), 144 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 408ee43046..2fe237916d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -774,17 +774,6 @@ if(OPENTELEMETRY_INSTALL) "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config-version.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") - # Export all components - export( - EXPORT "${PROJECT_NAME}-target" - NAMESPACE "${PROJECT_NAME}::" - FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-target.cmake" - ) - install( - EXPORT "${PROJECT_NAME}-target" - NAMESPACE "${PROJECT_NAME}::" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") - if(BUILD_PACKAGE) include(cmake/package.cmake) include(CPack) diff --git a/INSTALL.md b/INSTALL.md index b528181aa2..89fc8e0661 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -145,6 +145,69 @@ target_include_directories(foo PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS}) target_link_libraries(foo PRIVATE ${OPENTELEMETRY_CPP_LIBRARIES}) ``` +#### Using opentelemetry-cpp package components + +> **Note:** `opentelemetry-cpp` CMake package components were introduced in `v.TODO`. **Status:** [`Development`](https://opentelemetry.io/docs/specs/otel/document-status/) + +The `opentelemetry-cpp` package includes components to enable selective inclusion of its CMake targets and their dependencies using the `COMPONENTS` argument to `find_package`. The following example illustrates using this feature to include and link the `api` header only target to an instrumented `foo_lib` while only including and linking the `sdk` and `otlp_grpc_exporter` targets to the `foo_app`. + +```cmake +# foo_lib/CMakeLists.txt +find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS api) +add_library(foo_lib foo.cpp) +target_link_libraries(foo_lib PRIVATE opentelemetry-cpp::api) +``` + +```cmake +# foo_app/CMakeLists.txt +find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS api sdk exporters_otlp_grpc) +add_executable(foo_app main.cpp) +target_link_libraries(foo_app PRIVATE foo_lib opentelemetry-cpp::api opentelemetry-cpp::sdk opentelemetry-cpp::otlp_grpc_exporter ) +``` +The following table provides the mapping between components and targets. Components and targets available in the installation depends on the opentelemetry-cpp package build configuration. + +| Component | Targets | +|----------------------------|---------------------------------------------------------------------------------------------------| +| **api** | opentelemetry-cpp::api | +| **sdk** | opentelemetry-cpp::sdk | +| | opentelemetry-cpp::version | +| | opentelemetry-cpp::common | +| | opentelemetry-cpp::resources | +| | opentelemetry-cpp::trace | +| | opentelemetry-cpp::metrics | +| | opentelemetry-cpp::logs | +| **ext** | opentelemetry-cpp::ext | +| | opentelemetry-cpp::http_client_curl | +| | opentelemetry-cpp::opentelemetry_cpp | +| **exporters_in_memory** | opentelemetry-cpp::in_memory_span_exporter | +| | opentelemetry-cpp::in_memory_metric_exporter | +| **exporters_ostream** | opentelemetry-cpp::ostream_log_record_exporter | +| | opentelemetry-cpp::ostream_metrics_exporter | +| | opentelemetry-cpp::ostream_span_exporter | +| **exporters_otlp_common** | opentelemetry-cpp::proto | +| | opentelemetry-cpp::otlp_recordable | +| **exporters_otlp_file** | opentelemetry-cpp::otlp_file_client | +| | opentelemetry-cpp::otlp_file_exporter | +| | opentelemetry-cpp::otlp_file_log_record_exporter | +| | opentelemetry-cpp::otlp_file_metric_exporter | +| **exporters_otlp_grpc** | opentelemetry-cpp::proto_grpc | +| | opentelemetry-cpp::otlp_grpc_client | +| | opentelemetry-cpp::otlp_grpc_exporter | +| | opentelemetry-cpp::otlp_grpc_log_record_exporter | +| | opentelemetry-cpp::otlp_grpc_metrics_exporter | +| **exporters_otlp_http** | opentelemetry-cpp::otlp_http_client | +| | opentelemetry-cpp::otlp_http_exporter | +| | opentelemetry-cpp::otlp_http_log_record_exporter | +| | opentelemetry-cpp::otlp_http_metric_exporter | +| **exporters_prometheus** | opentelemetry-cpp::prometheus_exporter | +| **exporters_elasticsearch**| opentelemetry-cpp::elasticsearch_log_record_exporter | +| **exporters_etw** | opentelemetry-cpp::etw_exporter | +| **exporters_zipkin** | opentelemetry-cpp::zipkin_trace_exporter | +| **shims_opentracing** | opentelemetry-cpp::opentracing_shim | + + + + ## Build instructions using Bazel NOTE: Experimental, and not supported for all the components. Make sure the diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 78e97ad029..74c91c0eac 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -12,7 +12,7 @@ set_target_properties(opentelemetry_api PROPERTIES EXPORT_NAME api) if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_api - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-api-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) @@ -23,6 +23,12 @@ if(OPENTELEMETRY_INSTALL) FILES_MATCHING PATTERN "*.h") + install( + EXPORT "${PROJECT_NAME}-api-target" + FILE "${PROJECT_NAME}-api-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + unset(TARGET_DEPS) endif() diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/opentelemetry-cpp-config.cmake.in index 254bcc662b..d0fe97e0d4 100644 --- a/cmake/opentelemetry-cpp-config.cmake.in +++ b/cmake/opentelemetry-cpp-config.cmake.in @@ -22,35 +22,64 @@ # OPENTELEMETRY_VERSION - Version of opentelemetry-cpp. # # :: -# opentelemetry-cpp::api - Imported target of opentelemetry-cpp::api -# opentelemetry-cpp::sdk - Imported target of opentelemetry-cpp::sdk -# opentelemetry-cpp::ext - Imported target of opentelemetry-cpp::ext -# opentelemetry-cpp::version - Imported target of opentelemetry-cpp::version -# opentelemetry-cpp::common - Imported target of opentelemetry-cpp::common -# opentelemetry-cpp::trace - Imported target of opentelemetry-cpp::trace -# opentelemetry-cpp::metrics - Imported target of opentelemetry-cpp::metrics -# opentelemetry-cpp::logs - Imported target of opentelemetry-cpp::logs -# opentelemetry-cpp::in_memory_span_exporter - Imported target of opentelemetry-cpp::in_memory_span_exporter -# opentelemetry-cpp::otlp_grpc_client - Imported target of opentelemetry-cpp::otlp_grpc_client -# opentelemetry-cpp::otlp_recordable - Imported target of opentelemetry-cpp::otlp_recordable -# opentelemetry-cpp::otlp_grpc_exporter - Imported target of opentelemetry-cpp::otlp_grpc_exporter -# opentelemetry-cpp::otlp_grpc_log_record_exporter - Imported target of opentelemetry-cpp::otlp_grpc_log_record_exporter -# opentelemetry-cpp::otlp_grpc_metrics_exporter - Imported target of opentelemetry-cpp::otlp_grpc_metrics_exporter -# opentelemetry-cpp::otlp_http_client - Imported target of opentelemetry-cpp::otlp_http_client -# opentelemetry-cpp::otlp_http_exporter - Imported target of opentelemetry-cpp::otlp_http_exporter -# opentelemetry-cpp::otlp_http_log_record_exporter - Imported target of opentelemetry-cpp::otlp_http_log_record_exporter -# opentelemetry-cpp::otlp_http_metric_exporter - Imported target of opentelemetry-cpp::otlp_http_metric_exporter -# opentelemetry-cpp::otlp_file_client - Imported target of opentelemetry-cpp::otlp_file_client -# opentelemetry-cpp::otlp_file_exporter - Imported target of opentelemetry-cpp::otlp_file_exporter -# opentelemetry-cpp::otlp_file_log_record_exporter - Imported target of opentelemetry-cpp::otlp_file_log_record_exporter -# opentelemetry-cpp::otlp_file_metric_exporter - Imported target of opentelemetry-cpp::otlp_file_metric_exporter -# opentelemetry-cpp::ostream_log_record_exporter - Imported target of opentelemetry-cpp::ostream_log_record_exporter -# opentelemetry-cpp::ostream_metrics_exporter - Imported target of opentelemetry-cpp::ostream_metrics_exporter -# opentelemetry-cpp::ostream_span_exporter - Imported target of opentelemetry-cpp::ostream_span_exporter -# opentelemetry-cpp::elasticsearch_log_record_exporter - Imported target of opentelemetry-cpp::elasticsearch_log_record_exporter -# opentelemetry-cpp::etw_exporter - Imported target of opentelemetry-cpp::etw_exporter -# opentelemetry-cpp::http_client_curl - Imported target of opentelemetry-cpp::http_client_curl -# opentelemetry-cpp::opentracing_shim - Imported target of opentelemetry-cpp::opentracing_shim +# +# This module includes the following components for use with `find_package(opentelemetry-cpp COMPONENTS ...)` +# +# COMPONENTS +# api +# sdk +# ext +# exporters_in_memory +# exporters_ostream +# exporters_otlp_common +# exporters_otlp_file +# exporters_otlp_grpc +# exporters_otlp_http +# exporters_prometheus +# exporters_elasticsearch +# exporters_etw +# exporters_zipkin +# shims_opentracing +# +# :: +# +# TARGETS +# opentelemetry-cpp::api - Imported target of COMPONENT api +# opentelemetry-cpp::sdk - Imported target of COMPONENT sdk +# opentelemetry-cpp::version - Imported target of COMPONENT sdk +# opentelemetry-cpp::common - Imported target of COMPONENT sdk +# opentelemetry-cpp::resources - Imported target of COMPONENT sdk +# opentelemetry-cpp::trace - Imported target of COMPONENT sdk +# opentelemetry-cpp::metrics - Imported target of COMPONENT sdk +# opentelemetry-cpp::logs - Imported target of COMPONENT sdk +# opentelemetry-cpp::ext - Imported target of COMPONENT ext +# opentelemetry-cpp::http_client_curl - Imported target of COMPONENT ext +# opentelemetry-cpp::opentelemetry_cpp - Imported target of COMPONENT ext (from ext/dll) +# opentelemetry-cpp::in_memory_span_exporter - Imported target of COMPONENT exporters_in_memory +# opentelemetry-cpp::in_memory_metric_exporter - Imported target of COMPONENT exporters_in_memory +# opentelemetry-cpp::ostream_log_record_exporter - Imported target of COMPONENT exporters_ostream +# opentelemetry-cpp::ostream_metrics_exporter - Imported target of COMPONENT exporters_ostream +# opentelemetry-cpp::ostream_span_exporter - Imported target of COMPONENT exporters_ostream +# opentelemetry-cpp::proto - Imported target of COMPONENT exporters_otlp_common +# opentelemetry-cpp::otlp_recordable - Imported target of COMPONENT exporters_otlp_common +# opentelemetry-cpp::otlp_file_client - Imported target of COMPONENT exporters_otlp_file +# opentelemetry-cpp::otlp_file_exporter - Imported target of COMPONENT exporters_otlp_file +# opentelemetry-cpp::otlp_file_log_record_exporter - Imported target of COMPONENT exporters_otlp_file +# opentelemetry-cpp::otlp_file_metric_exporter - Imported target of COMPONENT exporters_otlp_file +# opentelemetry-cpp::proto_grpc - Imported target of COMPONENT exporters_otlp_grpc +# opentelemetry-cpp::otlp_grpc_client - Imported target of COMPONENT exporters_otlp_grpc +# opentelemetry-cpp::otlp_grpc_exporter - Imported target of COMPONENT exporters_otlp_grpc +# opentelemetry-cpp::otlp_grpc_log_record_exporter - Imported target of COMPONENT exporters_otlp_grpc +# opentelemetry-cpp::otlp_grpc_metrics_exporter - Imported target of COMPONENT exporters_otlp_grpc +# opentelemetry-cpp::otlp_http_client - Imported target of COMPONENT exporters_otlp_http +# opentelemetry-cpp::otlp_http_exporter - Imported target of COMPONENT exporters_otlp_http +# opentelemetry-cpp::otlp_http_log_record_exporter - Imported target of COMPONENT exporters_otlp_http +# opentelemetry-cpp::otlp_http_metric_exporter - Imported target of COMPONENT exporters_otlp_http +# opentelemetry-cpp::prometheus_exporter - Imported target of COMPONENT exporters_prometheus +# opentelemetry-cpp::elasticsearch_log_record_exporter - Imported target of COMPONENT exporters_elasticsearch +# opentelemetry-cpp::etw_exporter - Imported target of COMPONENT exporters_etw +# opentelemetry-cpp::zipkin_trace_exporter - Imported target of COMPONENT exporters_zipkin +# opentelemetry-cpp::opentracing_shim - Imported target of COMPONENT shims_opentracing # # ============================================================================= @@ -68,6 +97,89 @@ set(OPENTELEMETRY_VERSION @PACKAGE_INIT@ # ############################################################################## +# List all possible opentelemetry-cpp component targets. Some may not be supported by this install + + +set(_OPENTELEMETRY_CPP_COMPONENTS + api + sdk + ext + exporters_in_memory + exporters_ostream + exporters_otlp_common + exporters_otlp_file + exporters_otlp_grpc + exporters_otlp_http + exporters_prometheus + exporters_elasticsearch + exporters_etw + exporters_zipkin + shims_opentracing) + +set(_OPENTELEMETRY_CPP_TARGETS + api + sdk + version + common + resources + trace + metrics + logs + ext + http_client_curl + in_memory_span_exporter + in_memory_metric_exporter + otlp_recordable + otlp_grpc_client + otlp_grpc_exporter + otlp_grpc_log_record_exporter + otlp_grpc_metrics_exporter + otlp_http_client + otlp_http_exporter + otlp_http_log_record_exporter + otlp_http_metric_exporter + otlp_file_client + otlp_file_exporter + otlp_file_log_record_exporter + otlp_file_metric_exporter + ostream_log_record_exporter + ostream_metrics_exporter + ostream_span_exporter + prometheus_exporter + elasticsearch_log_record_exporter + etw_exporter + zipkin_trace_exporter + opentracing_shim) + + +# ############################################################################## + +# Create the list of requested components. Either all installed or a set passed to find_package( opentelemetry-cpp COMPONENTS ...) + +set(_FIND_ALL_COMPONENTS TRUE) + +if(NOT DEFINED opentelemetry-cpp_FIND_COMPONENTS OR opentelemetry-cpp_FIND_COMPONENTS STREQUAL "") + # if no components are requested then find all installed components + set(_OPENTELEMETRY_CPP_REQUESTED_COMPONENTS ${_OPENTELEMETRY_CPP_COMPONENTS}) +else() + set(_FIND_ALL_COMPONENTS FALSE) + # check that the requested components are valid and installed + + foreach(_COMPONENT IN LISTS opentelemetry-cpp_FIND_COMPONENTS) + if(NOT ${_COMPONENT} IN_LIST _OPENTELEMETRY_CPP_COMPONENTS) + message(FATAL_ERROR "The `${_COMPONENT}` component is not a supported component of the opentelemetry-cpp package. Supported components include: ${_OPENTELEMETRY_CPP_COMPONENTS}") + endif() + endforeach() + + foreach(_COMPONENT IN LISTS _OPENTELEMETRY_CPP_COMPONENTS) + if(${_COMPONENT} IN_LIST opentelemetry-cpp_FIND_COMPONENTS) + list(APPEND _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS ${_COMPONENT}) + endif() + endforeach() +endif() + +# _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS only contains valid components. However they may not all be installed in this package +# Find dependencies based on the requested components list. include(CMakeFindDependencyMacro) @@ -78,28 +190,45 @@ if(@WITH_ABSEIL@) endif() if(@WITH_OTLP_GRPC@) - find_dependency(gRPC) + if("exporters_otlp_grpc" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) + find_dependency(gRPC) + endif() endif() if("@OpenTracing_FOUND@") - find_dependency(OpenTracing) + if("shims_opentracing" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) + find_dependency(OpenTracing) + endif() endif() if("@prometheus-cpp_FOUND@") - find_dependency(prometheus-cpp) + if("exporters_prometheus" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) + find_dependency(prometheus-cpp) + endif() endif() if("@Protobuf_FOUND@" OR "@PROTOBUF_FOUND@") - find_dependency(Protobuf) + if( + "exporters_otlp_common" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS OR + "exporters_otlp_grpc" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS OR + "exporters_otlp_file" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS OR + "exporters_otlp_http" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS + ) + find_dependency(Protobuf) + endif() endif() if (@WITH_HTTP_CLIENT_CURL@ AND NOT @BUILD_SHARED_LIBS@) if("@CURL_FOUND@") - find_dependency(CURL) + if("ext" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) + find_dependency(CURL) + endif() endif() if("@ZLIB_FOUND@") - find_dependency(ZLIB) + if("ext" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) + find_dependency(ZLIB) + endif() endif() endif() @@ -114,41 +243,17 @@ endif() set_and_check(OPENTELEMETRY_CPP_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@") set_and_check(OPENTELEMETRY_CPP_LIBRARY_DIRS "@PACKAGE_CMAKE_INSTALL_LIBDIR@") -include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-target.cmake") +# include the target files selected. + +foreach(_COMPONENT IN LISTS _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) + include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-${_COMPONENT}-target.cmake") +endforeach() + +# Set OPENTELEMETRY_CPP_* variables to preserve legacy CMake style set(OPENTELEMETRY_CPP_LIBRARIES) -set(_OPENTELEMETRY_CPP_LIBRARIES_TEST_TARGETS - api - sdk - ext - version - common - trace - metrics - logs - in_memory_span_exporter - otlp_recordable - otlp_grpc_client - otlp_grpc_exporter - otlp_grpc_log_record_exporter - otlp_grpc_metrics_exporter - otlp_http_client - otlp_http_exporter - otlp_http_log_record_exporter - otlp_http_metric_exporter - otlp_file_client - otlp_file_exporter - otlp_file_log_record_exporter - otlp_file_metric_exporter - ostream_log_record_exporter - ostream_metrics_exporter - ostream_span_exporter - prometheus_exporter - elasticsearch_log_record_exporter - etw_exporter - http_client_curl - opentracing_shim) -foreach(_TEST_TARGET IN LISTS _OPENTELEMETRY_CPP_LIBRARIES_TEST_TARGETS) + +foreach(_TEST_TARGET IN LISTS _OPENTELEMETRY_CPP_TARGETS) if(TARGET opentelemetry-cpp::${_TEST_TARGET}) list(APPEND OPENTELEMETRY_CPP_LIBRARIES opentelemetry-cpp::${_TEST_TARGET}) endif() diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index 0ff346d249..d57a2a0c4c 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -369,12 +369,21 @@ patch_protobuf_targets(opentelemetry_proto) if(OPENTELEMETRY_INSTALL) install( - TARGETS ${OPENTELEMETRY_PROTO_TARGETS} - EXPORT "${PROJECT_NAME}-target" + TARGETS opentelemetry_proto + EXPORT "${PROJECT_NAME}-exporters_otlp_common-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + if(WITH_OTLP_GRPC) + install( + TARGETS opentelemetry_proto_grpc + EXPORT "${PROJECT_NAME}-exporters_otlp_grpc-target" + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + install( DIRECTORY ${GENERATED_PROTOBUF_PATH}/opentelemetry DESTINATION include diff --git a/exporters/elasticsearch/CMakeLists.txt b/exporters/elasticsearch/CMakeLists.txt index e91b53f1c6..4ca61476b6 100644 --- a/exporters/elasticsearch/CMakeLists.txt +++ b/exporters/elasticsearch/CMakeLists.txt @@ -21,7 +21,7 @@ target_link_libraries( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_exporter_elasticsearch_logs - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-exporters_elasticsearch-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) @@ -32,6 +32,13 @@ if(OPENTELEMETRY_INSTALL) FILES_MATCHING PATTERN "*.h" PATTERN "es_log_recordable.h" EXCLUDE) + + install( + EXPORT "${PROJECT_NAME}-exporters_elasticsearch-target" + FILE "${PROJECT_NAME}-exporters_elasticsearch-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + endif() if(BUILD_TESTING) diff --git a/exporters/etw/CMakeLists.txt b/exporters/etw/CMakeLists.txt index 947e390dd9..837b9f46a3 100644 --- a/exporters/etw/CMakeLists.txt +++ b/exporters/etw/CMakeLists.txt @@ -22,7 +22,7 @@ endif() if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_exporter_etw - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-exporters_etw-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) @@ -32,6 +32,12 @@ if(OPENTELEMETRY_INSTALL) DESTINATION include/opentelemetry/exporters FILES_MATCHING PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-exporters_etw-target" + FILE "${PROJECT_NAME}-exporters_etw-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") endif() if(BUILD_TESTING) diff --git a/exporters/memory/CMakeLists.txt b/exporters/memory/CMakeLists.txt index 0738759a96..f15d58f514 100644 --- a/exporters/memory/CMakeLists.txt +++ b/exporters/memory/CMakeLists.txt @@ -36,7 +36,7 @@ if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_exporter_in_memory opentelemetry_exporter_in_memory_metric - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-exporters_in_memory-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) @@ -46,6 +46,13 @@ if(OPENTELEMETRY_INSTALL) DESTINATION include/opentelemetry/exporters FILES_MATCHING PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-exporters_in_memory-target" + FILE "${PROJECT_NAME}-exporters_in_memory-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + endif() if(BUILD_TESTING) diff --git a/exporters/ostream/CMakeLists.txt b/exporters/ostream/CMakeLists.txt index e08d6592a3..b566a4f322 100644 --- a/exporters/ostream/CMakeLists.txt +++ b/exporters/ostream/CMakeLists.txt @@ -15,20 +15,7 @@ target_include_directories( target_link_libraries(opentelemetry_exporter_ostream_span PUBLIC opentelemetry_trace) -if(OPENTELEMETRY_INSTALL) - install( - TARGETS opentelemetry_exporter_ostream_span - EXPORT "${PROJECT_NAME}-target" - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - - install( - DIRECTORY include/opentelemetry/exporters/ostream - DESTINATION include/opentelemetry/exporters - PATTERN "*.h" - PATTERN "log_record_exporter.h" EXCLUDE) -endif() +list(APPEND OPENTELEMETRY_OSTREAM_TARGETS opentelemetry_exporter_ostream_span) if(BUILD_TESTING) add_executable(ostream_span_test test/ostream_span_test.cc) @@ -52,18 +39,8 @@ target_include_directories( target_link_libraries(opentelemetry_exporter_ostream_metrics PUBLIC opentelemetry_metrics) -if(OPENTELEMETRY_INSTALL) - install( - TARGETS opentelemetry_exporter_ostream_metrics - EXPORT "${PROJECT_NAME}-target" - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - install( - DIRECTORY include/opentelemetry/exporters/ostream - DESTINATION include/opentelemetry/exporters - PATTERN "metric_exporter.h") -endif() +list(APPEND OPENTELEMETRY_OSTREAM_TARGETS + opentelemetry_exporter_ostream_metrics) if(BUILD_TESTING) add_executable(ostream_metric_test test/ostream_metric_test.cc) @@ -87,19 +64,25 @@ target_include_directories( PUBLIC "$") target_link_libraries(opentelemetry_exporter_ostream_logs PUBLIC opentelemetry_logs) +list(APPEND OPENTELEMETRY_OSTREAM_TARGETS opentelemetry_exporter_ostream_logs) if(OPENTELEMETRY_INSTALL) install( - TARGETS opentelemetry_exporter_ostream_logs - EXPORT "${PROJECT_NAME}-target" + TARGETS ${OPENTELEMETRY_OSTREAM_TARGETS} + EXPORT "${PROJECT_NAME}-exporters_ostream-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) install( - FILES - "include/opentelemetry/exporters/ostream/log_record_exporter.h" - "include/opentelemetry/exporters/ostream/log_record_exporter_factory.h" - DESTINATION include/opentelemetry/exporters/ostream) + DIRECTORY include/opentelemetry/exporters/ostream + DESTINATION include/opentelemetry/exporters + PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-exporters_ostream-target" + FILE "${PROJECT_NAME}-exporters_ostream-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") endif() if(BUILD_TESTING) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index cd4e1b62fa..512876aaec 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -55,7 +55,7 @@ if(WITH_OTLP_GRPC) PUBLIC "$" "$") - list(APPEND OPENTELEMETRY_OTLP_TARGETS + list(APPEND OPENTELEMETRY_OTLP_GRPC_TARGETS opentelemetry_exporter_otlp_grpc_client) add_library( @@ -72,7 +72,7 @@ if(WITH_OTLP_GRPC) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_grpc_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_grpc) + list(APPEND OPENTELEMETRY_OTLP_GRPC_TARGETS opentelemetry_exporter_otlp_grpc) add_library( opentelemetry_exporter_otlp_grpc_log @@ -89,7 +89,8 @@ if(WITH_OTLP_GRPC) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_grpc_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_grpc_log) + list(APPEND OPENTELEMETRY_OTLP_GRPC_TARGETS + opentelemetry_exporter_otlp_grpc_log) add_library( opentelemetry_exporter_otlp_grpc_metrics @@ -105,7 +106,7 @@ if(WITH_OTLP_GRPC) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_grpc_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS + list(APPEND OPENTELEMETRY_OTLP_GRPC_TARGETS opentelemetry_exporter_otlp_grpc_metrics) endif() @@ -134,7 +135,7 @@ if(WITH_OTLP_HTTP) PUBLIC "$" "$") - list(APPEND OPENTELEMETRY_OTLP_TARGETS + list(APPEND OPENTELEMETRY_OTLP_HTTP_TARGETS opentelemetry_exporter_otlp_http_client) add_library( @@ -151,7 +152,7 @@ if(WITH_OTLP_HTTP) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_http_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http) + list(APPEND OPENTELEMETRY_OTLP_HTTP_TARGETS opentelemetry_exporter_otlp_http) add_library( opentelemetry_exporter_otlp_http_log @@ -168,7 +169,8 @@ if(WITH_OTLP_HTTP) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_http_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http_log) + list(APPEND OPENTELEMETRY_OTLP_HTTP_TARGETS + opentelemetry_exporter_otlp_http_log) add_library( opentelemetry_exporter_otlp_http_metric @@ -184,7 +186,7 @@ if(WITH_OTLP_HTTP) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_http_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS + list(APPEND OPENTELEMETRY_OTLP_HTTP_TARGETS opentelemetry_exporter_otlp_http_metric) endif() @@ -211,7 +213,7 @@ if(WITH_OTLP_FILE) PUBLIC "$" "$") - list(APPEND OPENTELEMETRY_OTLP_TARGETS + list(APPEND OPENTELEMETRY_OTLP_FILE_TARGETS opentelemetry_exporter_otlp_file_client) add_library( @@ -228,7 +230,7 @@ if(WITH_OTLP_FILE) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_file_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_file) + list(APPEND OPENTELEMETRY_OTLP_FILE_TARGETS opentelemetry_exporter_otlp_file) add_library( opentelemetry_exporter_otlp_file_log @@ -245,7 +247,8 @@ if(WITH_OTLP_FILE) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_file_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_file_log) + list(APPEND OPENTELEMETRY_OTLP_FILE_TARGETS + opentelemetry_exporter_otlp_file_log) add_library( opentelemetry_exporter_otlp_file_metric @@ -261,7 +264,7 @@ if(WITH_OTLP_FILE) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_file_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS + list(APPEND OPENTELEMETRY_OTLP_FILE_TARGETS opentelemetry_exporter_otlp_file_metric) endif() @@ -271,8 +274,8 @@ target_link_libraries( if(OPENTELEMETRY_INSTALL) install( - TARGETS ${OPENTELEMETRY_OTLP_TARGETS} - EXPORT "${PROJECT_NAME}-target" + TARGETS opentelemetry_otlp_recordable + EXPORT "${PROJECT_NAME}-exporters_otlp_common-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) @@ -282,6 +285,57 @@ if(OPENTELEMETRY_INSTALL) DESTINATION include/opentelemetry/exporters FILES_MATCHING PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-exporters_otlp_common-target" + FILE "${PROJECT_NAME}-exporters_otlp_common-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + + if(WITH_OTLP_GRPC) + install( + TARGETS ${OPENTELEMETRY_OTLP_GRPC_TARGETS} + EXPORT "${PROJECT_NAME}-exporters_otlp_grpc-target" + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + install( + EXPORT "${PROJECT_NAME}-exporters_otlp_grpc-target" + FILE "${PROJECT_NAME}-exporters_otlp_grpc-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + endif() + + if(WITH_OTLP_FILE) + install( + TARGETS ${OPENTELEMETRY_OTLP_FILE_TARGETS} + EXPORT "${PROJECT_NAME}-exporters_otlp_file-target" + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + install( + EXPORT "${PROJECT_NAME}-exporters_otlp_file-target" + FILE "${PROJECT_NAME}-exporters_otlp_file-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + endif() + + if(WITH_OTLP_HTTP) + install( + TARGETS ${OPENTELEMETRY_OTLP_HTTP_TARGETS} + EXPORT "${PROJECT_NAME}-exporters_otlp_http-target" + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + install( + EXPORT "${PROJECT_NAME}-exporters_otlp_http-target" + FILE "${PROJECT_NAME}-exporters_otlp_http-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + endif() endif() if(BUILD_TESTING) diff --git a/exporters/prometheus/CMakeLists.txt b/exporters/prometheus/CMakeLists.txt index 6c872be3ab..6dc392e42a 100644 --- a/exporters/prometheus/CMakeLists.txt +++ b/exporters/prometheus/CMakeLists.txt @@ -40,7 +40,7 @@ target_link_libraries(opentelemetry_exporter_prometheus if(OPENTELEMETRY_INSTALL) install( TARGETS ${PROMETHEUS_EXPORTER_TARGETS} - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-exporters_prometheus-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) @@ -50,6 +50,12 @@ if(OPENTELEMETRY_INSTALL) DESTINATION include/opentelemetry/exporters/ FILES_MATCHING PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-exporters_prometheus-target" + FILE "${PROJECT_NAME}-exporters_prometheus-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") endif() if(BUILD_TESTING) diff --git a/exporters/zipkin/CMakeLists.txt b/exporters/zipkin/CMakeLists.txt index 5944258ca3..6c2d635793 100644 --- a/exporters/zipkin/CMakeLists.txt +++ b/exporters/zipkin/CMakeLists.txt @@ -12,6 +12,9 @@ target_include_directories( PUBLIC "$" "$") +set_target_properties(opentelemetry_exporter_zipkin_trace + PROPERTIES EXPORT_NAME zipkin_trace_exporter) + set_target_version(opentelemetry_exporter_zipkin_trace) target_link_libraries( @@ -22,7 +25,7 @@ target_link_libraries( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_exporter_zipkin_trace - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-exporters_zipkin-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) @@ -33,6 +36,13 @@ if(OPENTELEMETRY_INSTALL) FILES_MATCHING PATTERN "*.h" PATTERN "recordable.h" EXCLUDE) + + install( + EXPORT "${PROJECT_NAME}-exporters_zipkin-target" + FILE "${PROJECT_NAME}-exporters_zipkin-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + endif() if(BUILD_TESTING) diff --git a/ext/CMakeLists.txt b/ext/CMakeLists.txt index bae59e3040..cfd298ea9d 100644 --- a/ext/CMakeLists.txt +++ b/ext/CMakeLists.txt @@ -13,7 +13,7 @@ target_link_libraries(opentelemetry_ext INTERFACE opentelemetry_api) if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_ext - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-ext-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) @@ -23,6 +23,13 @@ if(OPENTELEMETRY_INSTALL) DESTINATION include/opentelemetry/ FILES_MATCHING PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-ext-target" + FILE "${PROJECT_NAME}-ext-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + endif() add_subdirectory(src) diff --git a/ext/src/dll/CMakeLists.txt b/ext/src/dll/CMakeLists.txt index e6772b839f..653bc2b180 100644 --- a/ext/src/dll/CMakeLists.txt +++ b/ext/src/dll/CMakeLists.txt @@ -103,8 +103,9 @@ add_custom_command( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_cpp - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-ext-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() diff --git a/ext/src/http/client/curl/CMakeLists.txt b/ext/src/http/client/curl/CMakeLists.txt index c812fcefbf..e1ed24a44f 100644 --- a/ext/src/http/client/curl/CMakeLists.txt +++ b/ext/src/http/client/curl/CMakeLists.txt @@ -48,8 +48,9 @@ endif() if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_http_client_curl - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-ext-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() diff --git a/opentracing-shim/CMakeLists.txt b/opentracing-shim/CMakeLists.txt index b77b9c1985..494fd67267 100644 --- a/opentracing-shim/CMakeLists.txt +++ b/opentracing-shim/CMakeLists.txt @@ -30,7 +30,7 @@ endif() if(OPENTELEMETRY_INSTALL) install( TARGETS ${this_target} - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-shims_opentracing-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) @@ -40,6 +40,12 @@ if(OPENTELEMETRY_INSTALL) DESTINATION include/opentelemetry FILES_MATCHING PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-shims_opentracing-target" + FILE "${PROJECT_NAME}-shims_opentracing-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") endif() if(BUILD_TESTING) diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index 90d07a984a..b063cf6548 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -12,7 +12,7 @@ set_target_properties(opentelemetry_sdk PROPERTIES EXPORT_NAME sdk) if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_sdk - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-sdk-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) @@ -28,6 +28,13 @@ if(OPENTELEMETRY_INSTALL) DESTINATION include/opentelemetry FILES_MATCHING PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-sdk-target" + FILE "${PROJECT_NAME}-sdk-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + endif() add_subdirectory(src) diff --git a/sdk/src/common/CMakeLists.txt b/sdk/src/common/CMakeLists.txt index 16229e0820..500eb8e0bc 100644 --- a/sdk/src/common/CMakeLists.txt +++ b/sdk/src/common/CMakeLists.txt @@ -24,7 +24,7 @@ endif() if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_common - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-sdk-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/sdk/src/logs/CMakeLists.txt b/sdk/src/logs/CMakeLists.txt index 71679a9a48..47fc1dd09c 100644 --- a/sdk/src/logs/CMakeLists.txt +++ b/sdk/src/logs/CMakeLists.txt @@ -35,7 +35,7 @@ target_include_directories( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_logs - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-sdk-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/sdk/src/metrics/CMakeLists.txt b/sdk/src/metrics/CMakeLists.txt index 15611d1cab..c0235bf622 100644 --- a/sdk/src/metrics/CMakeLists.txt +++ b/sdk/src/metrics/CMakeLists.txt @@ -43,7 +43,7 @@ target_include_directories( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_metrics - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-sdk-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/sdk/src/resource/CMakeLists.txt b/sdk/src/resource/CMakeLists.txt index 7ccb9b491e..ac28033fcf 100644 --- a/sdk/src/resource/CMakeLists.txt +++ b/sdk/src/resource/CMakeLists.txt @@ -15,7 +15,7 @@ target_include_directories( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_resources - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-sdk-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/sdk/src/trace/CMakeLists.txt b/sdk/src/trace/CMakeLists.txt index 939a6ed2bc..590ec78885 100644 --- a/sdk/src/trace/CMakeLists.txt +++ b/sdk/src/trace/CMakeLists.txt @@ -35,7 +35,7 @@ target_include_directories( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_trace - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-sdk-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/sdk/src/version/CMakeLists.txt b/sdk/src/version/CMakeLists.txt index 4818a4ec63..53ffdea436 100644 --- a/sdk/src/version/CMakeLists.txt +++ b/sdk/src/version/CMakeLists.txt @@ -16,7 +16,7 @@ target_include_directories( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_version - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-sdk-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) From bd6685df00e694ff282e9185ed4801b6aedcc228 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Mon, 23 Dec 2024 14:40:26 -0700 Subject: [PATCH 2/5] fix markdown lint errors --- INSTALL.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 89fc8e0661..9fc095e1f2 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -147,9 +147,14 @@ target_link_libraries(foo PRIVATE ${OPENTELEMETRY_CPP_LIBRARIES}) #### Using opentelemetry-cpp package components -> **Note:** `opentelemetry-cpp` CMake package components were introduced in `v.TODO`. **Status:** [`Development`](https://opentelemetry.io/docs/specs/otel/document-status/) +> **Note:** `opentelemetry-cpp` CMake package components were introduced in `v.TODO`. +> **Status:** [`Development`](https://opentelemetry.io/docs/specs/otel/document-status/) -The `opentelemetry-cpp` package includes components to enable selective inclusion of its CMake targets and their dependencies using the `COMPONENTS` argument to `find_package`. The following example illustrates using this feature to include and link the `api` header only target to an instrumented `foo_lib` while only including and linking the `sdk` and `otlp_grpc_exporter` targets to the `foo_app`. +The `opentelemetry-cpp` package includes components to enable selective inclusion +of its CMake targets and their dependencies using the `COMPONENTS` argument to +`find_package`. The following example illustrates using this feature to include +and link the `api` header only target to an instrumented `foo_lib` while only including +and linking the `sdk` and `otlp_grpc_exporter` targets to the `foo_app`. ```cmake # foo_lib/CMakeLists.txt @@ -164,7 +169,10 @@ find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS api sdk exporters_otlp add_executable(foo_app main.cpp) target_link_libraries(foo_app PRIVATE foo_lib opentelemetry-cpp::api opentelemetry-cpp::sdk opentelemetry-cpp::otlp_grpc_exporter ) ``` -The following table provides the mapping between components and targets. Components and targets available in the installation depends on the opentelemetry-cpp package build configuration. + +The following table provides the mapping between components and targets. Components +and targets available in the installation depends on the opentelemetry-cpp package +build configuration. | Component | Targets | |----------------------------|---------------------------------------------------------------------------------------------------| @@ -205,9 +213,6 @@ The following table provides the mapping between components and targets. Compone | **exporters_zipkin** | opentelemetry-cpp::zipkin_trace_exporter | | **shims_opentracing** | opentelemetry-cpp::opentracing_shim | - - - ## Build instructions using Bazel NOTE: Experimental, and not supported for all the components. Make sure the From 4cef852ad75e72f267660faf1bada1203e165fa7 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Mon, 23 Dec 2024 16:54:02 -0700 Subject: [PATCH 3/5] fix default case to include all components in the package --- cmake/opentelemetry-cpp-config.cmake.in | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/opentelemetry-cpp-config.cmake.in index d0fe97e0d4..2b4c655f67 100644 --- a/cmake/opentelemetry-cpp-config.cmake.in +++ b/cmake/opentelemetry-cpp-config.cmake.in @@ -158,9 +158,20 @@ set(_OPENTELEMETRY_CPP_TARGETS set(_FIND_ALL_COMPONENTS TRUE) +set(_OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) + if(NOT DEFINED opentelemetry-cpp_FIND_COMPONENTS OR opentelemetry-cpp_FIND_COMPONENTS STREQUAL "") # if no components are requested then find all installed components - set(_OPENTELEMETRY_CPP_REQUESTED_COMPONENTS ${_OPENTELEMETRY_CPP_COMPONENTS}) + + set(_TARGET_FILES_DIR "${CMAKE_CURRENT_LIST_DIR}") + + foreach(_COMPONENT IN LISTS _OPENTELEMETRY_CPP_COMPONENTS) + set(_COMPONENT_TARGET_FILE "${_TARGET_FILES_DIR}/opentelemetry-cpp-${_COMPONENT}-target.cmake") + if(EXISTS "${_COMPONENT_TARGET_FILE}") + list(APPEND _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS ${_COMPONENT}) + endif() + endforeach() + else() set(_FIND_ALL_COMPONENTS FALSE) # check that the requested components are valid and installed From 80a3cb385db9e85ba13690229b112fb759ded56d Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Mon, 23 Dec 2024 17:33:57 -0700 Subject: [PATCH 4/5] remove unused opentelemetry_ext dependency from the otlp grpc client --- exporters/otlp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 512876aaec..918feaeb97 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -38,7 +38,7 @@ if(WITH_OTLP_GRPC) # targets that depend on opentelemetry_proto_grpc. target_link_libraries( opentelemetry_exporter_otlp_grpc_client - PUBLIC opentelemetry_sdk opentelemetry_common opentelemetry_ext + PUBLIC opentelemetry_sdk opentelemetry_common # gRPC::grpc++ must be linked before opentelemetry_proto_grpc. opentelemetry_proto_grpc PRIVATE gRPC::grpc++) From 6d6c2c935376a95a12d4b577dd2f34046837657d Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 8 Jan 2025 12:37:31 -0700 Subject: [PATCH 5/5] the ext target is used by the grpc client but can be private --- exporters/otlp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 918feaeb97..d8ec497e2b 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -41,7 +41,7 @@ if(WITH_OTLP_GRPC) PUBLIC opentelemetry_sdk opentelemetry_common # gRPC::grpc++ must be linked before opentelemetry_proto_grpc. opentelemetry_proto_grpc - PRIVATE gRPC::grpc++) + PRIVATE gRPC::grpc++ opentelemetry_ext) get_target_property(GRPC_INCLUDE_DIRECTORY gRPC::grpc++ INTERFACE_INCLUDE_DIRECTORIES)