Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INSTALL] add cmake components to the package #3220

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This export of the target file to the current binary directory appears unused and I've removed it. The PR only installs the target files for the components in the install directory.

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)
Expand Down
68 changes: 68 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,74 @@ 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
Expand Down
8 changes: 7 additions & 1 deletion api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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()

Expand Down
Loading
Loading