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

Use find_package instead of adding include directories 1 by 1 #4309

Merged
merged 15 commits into from
Apr 26, 2024
Merged
Changes from 6 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
38 changes: 16 additions & 22 deletions content/en/docs/languages/cpp/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ using CMake, following these steps:
```

4. In the `build` directory run CMake, to configure and generate the build
system.
system without enabling tests:

```bash
cmake ..
cmake -DBUILD_TESTING=OFF ..
```

Or, if the `cmake --build` fails, you can also try:

```bash
cmake -DWITH_ABSEIL=ON ..
cmake -DBUILD_TESTING=OFF -DWITH_ABSEIL=ON ..
```

5. Execute the build process.
5. Execute the build process:

```bash
cmake --build .
Expand All @@ -140,8 +140,9 @@ In your `otel-cpp-starter` folder, create a subfolder `roll-dice`, where the
Oat++ library will be used by referencing the oatpp headers and linking them
when compiling your project.

Create a file called `CMakeLists.txt` to define the Oat++ library directories,
include paths, and link against Oat++ during the compilation process.
Create a file called `CMakeLists.txt` inside `roll-dice` to define the Oat++
library directories, include paths, and link against Oat++ during the
compilation process.

```cmake
project(RollDiceServer)
Expand Down Expand Up @@ -267,23 +268,16 @@ endif()
# set the path to the directory containing "oatpp" package configuration files
include_directories(${OATPP_ROOT}/src)

include_directories(${OPENTELEMETRY_ROOT}/api/include)
include_directories(${OPENTELEMETRY_ROOT}/sdk/include)
include_directories(${OPENTELEMETRY_ROOT}/sdk/src)
include_directories(${OPENTELEMETRY_ROOT}/exporters/ostream/include)

find_library(OPENTELEMETRY_COMMON_LIB NAMES libopentelemetry_common.a HINTS "${OPENTELEMETRY_ROOT}/build/sdk/src/common" NO_DEFAULT_PATH)
find_library(OPENTELEMETRY_TRACE_LIB NAMES libopentelemetry_trace.a HINTS "${OPENTELEMETRY_ROOT}/build/sdk/src/trace" NO_DEFAULT_PATH)
find_library(OPENTELEMETRY_EXPORTER_LIB NAMES libopentelemetry_exporter_ostream_span.a HINTS "${OPENTELEMETRY_ROOT}/build/exporters/ostream" NO_DEFAULT_PATH)
find_library(OPENTELEMETRY_RESOURCE_LIB NAMES libopentelemetry_resources.a HINTS "${OPENTELEMETRY_ROOT}/build/sdk/src/resource" NO_DEFAULT_PATH)

if(OPENTELEMETRY_COMMON_LIB AND OPENTELEMETRY_TRACE_LIB AND OPENTELEMETRY_EXPORTER_LIB AND OPENTELEMETRY_RESOURCE_LIB)
message(STATUS "Found opentelemetry libraries")
else()
message(SEND_ERROR "Did not find opentelemetry libraries")
endif()
# Use find_package to include OpenTelemetry C++
find_package(opentelemetry-cpp CONFIG REQUIRED)
ricardoamaro marked this conversation as resolved.
Show resolved Hide resolved
svrnm marked this conversation as resolved.
Show resolved Hide resolved
ricardoamaro marked this conversation as resolved.
Show resolved Hide resolved

target_link_libraries(dice-server PRIVATE ${OATPP_LIB} ${OPENTELEMETRY_COMMON_LIB} ${OPENTELEMETRY_TRACE_LIB} ${OPENTELEMETRY_EXPORTER_LIB} ${OPENTELEMETRY_RESOURCE_LIB})
# Link against each OpenTelemetry C++ library
target_link_libraries(dice-server PRIVATE
${OATPP_LIB}
opentelemetry-cpp::api
opentelemetry-cpp::sdk
opentelemetry-cpp::trace
opentelemetry-cpp::ostream_span_exporter)
```

Update the `main.cpp` file with the following code to initialize a tracer and to
Expand Down