Skip to content

Adding opentelemetry-cpp to a CMAKE project not working? #3698

@gaure

Description

@gaure

Describe your environment
Rocky Linux 10 OS
CMAKE 3.30.5

Steps to reproduce

  1. Create the cmake file to fetch opentelemetry from git repo
# Install dependency opentelemetry-cpp
include(FetchContent)
set(WITH_STL ON)
set(BUILD_SHARED_LIBS ON)
set(BUILD_TESTING OFF)
FetchContent_Declare(
    opentelemetry-cpp
    GIT_REPOSITORY https://github.com/open-telemetry/opentelemetry-cpp.git
    GIT_TAG v1.23.0
)

FetchContent_MakeAvailable(opentelemetry-cpp)
  1. Add an include and a find_package() command to your CMAKE project to find and expose the opentelemetry-cpp targets
include(<bullet 1 .cmake file>)
find_package(opentelemetry-cpp CONFIG REQUIRED)
  1. Run cmake -B -S
    The command produces the following error:
CMake Error at src/CMakeLists.txt:26 (find_package):
  Could not find a package configuration file provided by "opentelemetry-cpp"
  with any of the following names:

    opentelemetry-cppConfig.cmake
    opentelemetry-cpp-config.cmake

  Add the installation prefix of "opentelemetry-cpp" to CMAKE_PREFIX_PATH or
  set "opentelemetry-cpp_DIR" to a directory containing one of the above
  files.  If "opentelemetry-cpp" provides a separate development package or
  SDK, be sure it has been installed.
  1. Couldn't find the opentelemetry-cpp-config.cmake file in the "build/_dep/opentelemetry-cpp-build" directory, was not created. Added the following entry to the fetch cmake file to force the file to be created
# opentelemetry creation of the cmake config file only happens if the OPENTELEMETRY_INSTALL is set to ON
set(OPENTELEMETRY_INSTALL ON)

The error stays the same.

  1. Append the "opentelemetry-cpp_BINARY_DIR" to the CMAKE_PREFIX_PATH, at this point and add this above the find_package() command.
list(APPEND CMAKE_PREFIX_PATH "${opentelemetry-cpp_BINARY_DIR}/cmake/opentelemetry-cpp")
find_package(opentelemetry-cpp CONFIG REQUIRED)

The above change, changed the error to:

CMake Error at build/_deps/opentelemetry-cpp-build/cmake/opentelemetry-cpp/opentelemetry-cpp-config.cmake:197 (include):
  include could not find requested file:

    /home/rocky/build-environment/build/_deps/opentelemetry-cpp-build/cmake/opentelemetry-cpp/find-package-support-functions.cmake
Call Stack (most recent call first):
  src/CMakeLists.txt:27 (find_package)

CMake Error at build/_deps/opentelemetry-cpp-build/cmake/opentelemetry-cpp/opentelemetry-cpp-config.cmake:200 (get_installed_components):
  Unknown CMake command "get_installed_components".
Call Stack (most recent call first):
  src/CMakeLists.txt:27 (find_package)
  1. Adding the "opentelemetry-cpp_SOURCE_DIR/cmake" to the CMAKE_MODULE_PATH not solved the above error
list(APPEND CMAKE_MODULE_PATH ${opentelemetry-cpp_SOURCE_DIR}/cmake)
message("OPENTELEMETRY SOURCE DIR: " "${opentelemetry-cpp_SOURCE_DIR}/cmake}")
list(APPEND CMAKE_PREFIX_PATH "${opentelemetry-cpp_BINARY_DIR}/cmake/opentelemetry-cpp")
find_package(opentelemetry-cpp CONFIG REQUIRED)

Same error as bullet '5'

What is the expected behavior?
Tha the find_package() command is found without having to set OPENTELEMETRY_INSTALL to ON and that, once founded the function "find-package-support-functions.cmake" included be in a location that the opentelemetry-cpp-config.cmake can parse.

What is the actual behavior?
Missing opentelemetry-cpp-config.cmake file and errors trying to include the find-package-support-functions.cmake with the code to expose the targets to my CMAKE project

Additional context
NA

Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions