Skip to content

cmake does not find the includes #3470

Open
@NahuFigueroa97

Description

@NahuFigueroa97

I'm incorporating the OpenTelemetry C++ library (v1.8.3) into my project using a CMake helper that creates "imported static" targets with their own include paths and .a files. However, when I link the opentelemetry-cpp::metrics target into a metrics submodule of my engine, the compiler can't find the OpenTelemetry SDK headers.

Makefile rule


### opentelemetry ###
${OPENTELEMETRY_LIB}:
	cd $(EXTERNAL_OPENTELEMETRY) && mkdir -p build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DWITH_EXAMPLES=OFF -DOPENTELEMETRY_INSTALL=ON -DWITH_ABSEIL=OFF -DWITH_STL=ON -DWITH_BENCHMARK=OFF && ${MAKE}
/ruta/al/proyecto/
├── external/
│   └── opentelemetry-cpp-1_8_3/
│       ├── opentelemetry-cpp-1.8.3/
│       │   ├── api/
│       │   │   └── include/opentelemetry/…
│       │   └── sdk/
│       │       └── include/opentelemetry/sdk/metrics/…
│       └── build/
│           └── sdk/src/metrics/libopentelemetry_metrics.a
├── engine/                                    # target de nivel superior
│   ├── CMakeLists.txt                         # Here I define the helper
│   └── metrics/                               # submodule “metrics”
│       └── CMakeLists.txt                     # Here I link against OpenTelemetry
├── Makefile

Helper

function(add_manual_imported alias header_dir static_lib)
  string(REPLACE "::" "_" internal "${alias}")
  if(static_lib)
    add_library(${internal} STATIC IMPORTED GLOBAL)
    set_target_properties(${internal} PROPERTIES
      IMPORTED_LOCATION           "${static_lib}"
      INTERFACE_INCLUDE_DIRECTORIES "${header_dir}"
    )
  else()
    add_library(${internal} INTERFACE IMPORTED GLOBAL)
    set_target_properties(${internal} PROPERTIES
      INTERFACE_INCLUDE_DIRECTORIES "${header_dir}"
    )
  endif()
  add_library(${alias} ALIAS ${internal})
endfunction()

add_manual_imported(
  opentelemetry-cpp::metrics
  "${PROJECT_SOURCE_DIR}/../external/opentelemetry-cpp-1_8_3/opentelemetry-cpp-1.8.3/sdk/include"
  "${PROJECT_SOURCE_DIR}/../external/opentelemetry-cpp-1_8_3/opentelemetry-cpp-1.8.3/build/sdk/src/metrics/libopentelemetry_metrics.a"
)

so I link in the submodule engine/metrics/CMakeLists.txt

target_link_libraries(metrics
  PUBLIC
    metrics::imetrics
    base
  PRIVATE
    opentelemetry-cpp::metrics    # Here I use the imported target
)

Observed behavior

When compiling the metrics submodule, any line like

#include <opentelemetry/sdk/metrics/push_metric_exporter.h>

produces a “file not found” error

Additional Information

CMake Version: 3.24

Platform: Ubuntu 22.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage/needs-informationIndicates an issue needs more information in order to work on it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions