Skip to content

Commit af98d87

Browse files
authored
[DOCS] Update CMake usage to reference explicit targets (#4552)
1 parent 5823ea6 commit af98d87

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎INSTALL.md‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,21 @@ There are two approaches to incoporate `opentelemetry-cpp` into
159159
1. Build and install `opentelemetry-cpp` then use `find_package`
160160
to import its targets
161161

162+
Example instrumentation library (using only the OTel C++ API)
163+
162164
```cmake
163-
# Find all installed components and link all imported targets
164165
find_package(opentelemetry-cpp CONFIG REQUIRED)
165166
...
166-
target_include_directories(foo PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS})
167-
target_link_libraries(foo PRIVATE ${OPENTELEMETRY_CPP_LIBRARIES})
167+
# Link just the API header only interface target
168+
target_link_libraries(foo_lib PRIVATE opentelemetry-cpp::api)
168169
```
169170

171+
Example application (using the OTel C++ SDK and exporters)
172+
170173
```cmake
171-
# Find a specific component and link its imported target(s)
172-
find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS api)
174+
find_package(opentelemetry-cpp CONFIG REQUIRED)
173175
...
174-
target_link_libraries(foo PRIVATE opentelemetry-cpp::api)
176+
target_link_libraries(foo_app PRIVATE opentelemetry-cpp::trace opentelemetry-cpp::ostream_span_exporter)
175177
```
176178

177179
2. Use CMake's [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html)
@@ -192,7 +194,7 @@ There are two approaches to incoporate `opentelemetry-cpp` into
192194
FetchContent_Declare(
193195
opentelemetry-cpp
194196
GIT_REPOSITORY https://github.com/open-telemetry/opentelemetry-cpp.git
195-
GIT_TAG v1.20.0)
197+
GIT_TAG <release tag or SHA>)
196198
FetchContent_MakeAvailable(opentelemetry-cpp)
197199
...
198200
target_link_libraries(foo PRIVATE opentelemetry-cpp::api)

0 commit comments

Comments
 (0)