Repository: conan-io/conan-center-index

Issue:
[package] opentelemetry-cpp/1.8.3: incorrect dependency generated
### Description

While integarting conan into our build system, I've configured the opentelemetry package with the following settings:
```
def configure(self):
        self.options["opentelemetry-cpp/1.8.3"].with_stl=True
        self.options["opentelemetry-cpp/1.8.3"].with_gsl=True
        self.options["opentelemetry-cpp/1.8.3"].with_abseil=False
        self.options["opentelemetry-cpp/1.8.3"].with_otlp=False
        self.options["opentelemetry-cpp/1.8.3"].with_otlp_grpc=False
        self.options["opentelemetry-cpp/1.8.3"].with_otlp_http=False
        self.options["opentelemetry-cpp/1.8.3"].with_zipkin=False
        self.options["opentelemetry-cpp/1.8.3"].with_prometheus=False
        self.options["opentelemetry-cpp/1.8.3"].with_elasticsearch=False
        self.options["opentelemetry-cpp/1.8.3"].with_zpages=False
        self.options["opentelemetry-cpp/1.8.3"].with_jaeger=False
        self.options["opentelemetry-cpp/1.8.3"].with_no_getenv=False
        self.options["opentelemetry-cpp/1.8.3"].with_etw=False
        self.options["opentelemetry-cpp/1.8.3"].with_logs_preview=False
        self.options["opentelemetry-cpp/1.8.3"].with_async_export_preview=False
        self.options["opentelemetry-cpp/1.8.3"].with_metrics_exemplar_preview=False
```
This leads to the following CMake error:
```
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_http_client_curl'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_common'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_exporter_in_memory'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_resources'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_trace'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_version'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_metrics'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_exporter_ostream_metrics'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_exporter_ostream_span'
-- Conan: Target declared 'opentelemetry-cpp::opentelemetry-cpp'
CMake Error at conan/cmakedeps_macros.cmake:67 (message):
  Library 'opentelemetry_http_client_curl' not found in package.  If
  'opentelemetry_http_client_curl' is a system library, declare it with
  'cpp_info.system_libs' property
Call Stack (most recent call first):
  conan/opentelemetry-cpp-Target-release.cmake:24 (conan_package_library_targets)
  conan/opentelemetry-cppTargets.cmake:26 (include)
  conan/opentelemetry-cpp-config.cmake:16 (include)
  CMakeLists.txt:75 (find_package)


-- Configuring incomplete, errors occurred!
```
Since no http component was configured, there should be NO `opentelemetry_http_client_curl` target defined.

### Package and Environment Details

* Package Name/Version: **opentelemetry-cpp/1.8.3**
* Operating System+version: **Windows 10**
* Compiler+version: **msvc 192**
* conan version: 2.0.13
* python  version: 3.11.0
* python sys_version: 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
* used gerenrators: CMakeDeps + CMakeToolchain

### Conan profile

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=17
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=192
os=Windows


### Steps to reproduce

See description

### Logs

```
C:\work\git\x.git\conan>conan build .

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=17
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=192
os=Windows

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=17
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=192
os=Windows


======== Computing dependency graph ========
opentelemetry-cpp/1.8.3: WARN: opentelemetry-cpp/1.8.3:with_otlp option is deprecated, do not use anymore. Please, consider with_otlp_grpc or with_otlp_http instead.
Graph root
    conanfile.py (x/4.3.0.0`): C:\work\git\x.git\conan\conanfile.py
Requirements
    cryptopp/8.5.0#63635f18ae9830d740e3274d72df223f - Cache
    fmt/8.1.1#75ca545d275563b03150de8439ea0945 - Cache
    ms-gsl/4.0.0#60ed7b1ae7ff8fbfe0bf9a1c1f0443a8 - Cache
    nlohmann_json/3.11.3#45828be26eb619a2e04ca517bb7b828d - Cache
    opencv/4.5.2@aru/stable#f1d31c8de1a7511342a319f4b967b3d5 - Cache
    opentelemetry-cpp/1.8.3#375039dbea723453506ae4eaeca7b7ea - Cache
    rxcpp/4.1.1#7422b50d0bc981544662d47fa74acff4 - Cache
    spdlog/1.10.0#09b4ff6cef4476c47c27fa33c86ebada - Cache
    xsimd/7.5.0#1e3ebf2865fb4936021ec18bcda3c22f - Cache
    xtensor/0.23.10#6bada0ab34d7b7c3ec271c886a495dd6 - Cache
    xtl/0.7.5#09fbb7d54f9d50c029dbc73132d79cbc - Cache

======== Computing necessary packages ========
cryptopp/8.5.0: Checking 2 compatible configurations
cryptopp/8.5.0: Main binary package 'dfa8c31b225ffb8dfcf6a48ffd071f448777ae71' missing. Using compatible package '2401fa1d188d289bb25c37cfa3317e13e377a351': compiler.cppstd=14
fmt/8.1.1: Checking 2 compatible configurations
fmt/8.1.1: Main binary package '75b72f42a178117886718d4498a29ce3f102a2d9' missing. Using compatible package '31af49c57f22376679c3dfe0701a4ef767d42fd4': compiler.cppstd=14
spdlog/1.10.0: Checking 2 compatible configurations
spdlog/1.10.0: Main binary package 'ad2944e6fe261bc4a0c7eb4d6d23fd6f5eb5c72a' missing. Using compatible package 'ac0cc8fdba1e3209ab47b9de9b94af4c646be3cc': compiler.cppstd=14
Requirements
    cryptopp/8.5.0#63635f18ae9830d740e3274d72df223f:2401fa1d188d289bb25c37cfa3317e13e377a351#1b09dd0b4a5fafcbb4b7cde0996a508e - Cache
    fmt/8.1.1#75ca545d275563b03150de8439ea0945:31af49c57f22376679c3dfe0701a4ef767d42fd4#a3b1dbc7ea0dc8b9662a6d18329ba520 - Cache
    nlohmann_json/3.11.3#45828be26eb619a2e04ca517bb7b828d:da39a3ee5e6b4b0d3255bfef95601890afd80709#552828a2560333bcbeff9d087ce0af0f - Cache
    opencv/4.5.2@aru/stable#f1d31c8de1a7511342a319f4b967b3d5:50403a14ae7ffa7f16e59375c94b5b0598ef37d3#f71e54e18f62d97a2a2b607aa889e04d - Cache
    opentelemetry-cpp/1.8.3#375039dbea723453506ae4eaeca7b7ea:17e3793b567ad1b31703a874829b0307774c3104#af71296f961e2c894f7b235cdcd5cff6 - Cache
    rxcpp/4.1.1#7422b50d0bc981544662d47fa74acff4:da39a3ee5e6b4b0d3255bfef95601890afd80709#a7bd72a7733e09108a346c3e6695ffc1 - Cache
    spdlog/1.10.0#09b4ff6cef4476c47c27fa33c86ebada:ac0cc8fdba1e3209ab47b9de9b94af4c646be3cc#7f0997f456be56e1086f631f80b13bda - Cache
    xsimd/7.5.0#1e3ebf2865fb4936021ec18bcda3c22f:da39a3ee5e6b4b0d3255bfef95601890afd80709#252d2150986bf17b07043304c91b5096 - Cache
    xtensor/0.23.10#6bada0ab34d7b7c3ec271c886a495dd6:da39a3ee5e6b4b0d3255bfef95601890afd80709#1f6b3d10953a25d1844bc0cf4f7dfcb2 - Cache
    xtl/0.7.5#09fbb7d54f9d50c029dbc73132d79cbc:da39a3ee5e6b4b0d3255bfef95601890afd80709#42c8a4b906956c18fce78f08f7c8799a - Cache
Skipped binaries
    ms-gsl/4.0.0

======== Installing packages ========

======== Installing packages ========
cryptopp/8.5.0: Already installed! (1 of 10)
fmt/8.1.1: Already installed! (2 of 10)
nlohmann_json/3.11.3: Already installed! (3 of 10)
opencv/4.5.2@aru/stable: Already installed! (4 of 10)
rxcpp/4.1.1: Already installed! (5 of 10)
xsimd/7.5.0: Already installed! (6 of 10)
xtl/0.7.5: Already installed! (7 of 10)
opentelemetry-cpp/1.8.3: Already installed! (8 of 10)
spdlog/1.10.0: Already installed! (9 of 10)
xtensor/0.23.10: Already installed! (10 of 10)
WARN: deprecated: Usage of deprecated Conan 1.X features that will be removed in Conan 2.X:
WARN: deprecated:     'cpp_info.names' used in: spdlog/1.10.0, fmt/8.1.1, cryptopp/8.5.0
WARN: deprecated:     'cpp_info.build_modules' used in: cryptopp/8.5.0, xsimd/7.5.0, xtensor/0.23.10, xtl/0.7.5, opentelemetry-cpp/1.8.3

======== Finalizing install (deploy, generators) ========
conanfile.py (x/4.3.0.0`): Calling generate()
conanfile.py (x/4.3.0.0`): Generators folder: C:\work\git\x.git\conan
conanfile.py (x/4.3.0.0`): CMakeToolchain generated: conan_toolchain.cmake
conanfile.py (x/4.3.0.0`): Preset 'conan-default' added to CMakePresets.json. Invoke it manually using 'cmake --preset conan-default' if using CMake>=3.23
conanfile.py (x/4.3.0.0`): If your CMake version is not compatible with CMakePresets (<3.23) call cmake like: 'cmake <path> -G "Visual Studio 16 2019" -DCMAKE_TOOLCHAIN_FILE=C:\work\git\x.git\conan\conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW'
conanfile.py (x/4.3.0.0`): CMakeToolchain generated: CMakePresets.json
conanfile.py (x/4.3.0.0`): CMakeToolchain generated: ..\CMakeUserPresets.json
conanfile.py (x/4.3.0.0`): Generating aggregated env files
conanfile.py (x/4.3.0.0`): Generated aggregated env files: ['conanbuild.bat', 'conanrun.bat']

======== Calling build() ========
conanfile.py (x/4.3.0.0`): Calling build()
conanfile.py (x/4.3.0.0`): Running CMake.configure()
conanfile.py (x/4.3.0.0`): RUN: cmake -G "Visual Studio 16 2019" -DCMAKE_TOOLCHAIN_FILE="C:/work/git/x.git/conan/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/work/git/x.git/conan" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DSETUP_CONFIG_ENVIRONMENT="TESTENVIRONMENT" -DCMAKE_PREFIX_PATH="C:/Qt/6.5.0/msvc2019_64" -DCONAN_CMAKE_BUILD="ON" "C:\work\git\x.git"
-- Using Conan toolchain: C:/work/git/x.git/conan/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 17 with extensions OFF
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
-- Overriding cached values for TESTENVIRONMENT
-- Conan: Target declared 'opencv::opencv'
-- Conan: Target declared 'rxcpp::rxcpp'
-- Conan: Target declared 'xtensor'
-- Conan: Target declared 'xtl'
-- Conan: Target declared 'nlohmann_json::nlohmann_json'
-- Conan: Target declared 'xsimd'
-- Conan: Component target declared 'cryptopp::cryptopp'
-- crashpad::crashpad found in C:/work/git/x.git/thirdparty/crashpad
-- rxqt::rxqt found in C:/work/git/x.git/thirdparty/rxqt
-- tfwrapper found at: C:/work/git/x.git/thirdparty/tfwrapper
-- aws::aws found in C:/work/git/x.git/thirdparty/aws
-- ffmpeg found at: C:/work/git/x.git/thirdparty/ffmpeg
-- libjpeg::libjpeg found in C:/work/git/x.git/thirdparty/libjpeg
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_http_client_curl'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_common'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_exporter_in_memory'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_resources'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_trace'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_version'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_metrics'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_exporter_ostream_metrics'
-- Conan: Component target declared 'opentelemetry-cpp::opentelemetry_exporter_ostream_span'
-- Conan: Target declared 'opentelemetry-cpp::opentelemetry-cpp'
CMake Error at conan/cmakedeps_macros.cmake:67 (message):
  Library 'opentelemetry_http_client_curl' not found in package.  If
  'opentelemetry_http_client_curl' is a system library, declare it with
  'cpp_info.system_libs' property
Call Stack (most recent call first):
  conan/opentelemetry-cpp-Target-release.cmake:24 (conan_package_library_targets)
  conan/opentelemetry-cppTargets.cmake:26 (include)
  conan/opentelemetry-cpp-config.cmake:16 (include)
  CMakeLists.txt:75 (find_package)


-- Configuring incomplete, errors occurred!
```


Discussion:

Resolving patch:
diff --git a/recipes/opentelemetry-cpp/all/conanfile.py b/recipes/opentelemetry-cpp/all/conanfile.py
--- a/recipes/opentelemetry-cpp/all/conanfile.py
+++ b/recipes/opentelemetry-cpp/all/conanfile.py
@@ -235,14 +235,9 @@ def _patch_sources(self):
             replace_in_file(self, protos_cmake_path,
                             "if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/opentelemetry-proto/.git)",
                             "if(1)")
-            if Version(self.version) < "1.8.3":
-                replace_in_file(self, protos_cmake_path,
-                                'set(PROTO_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third_party/opentelemetry-proto")',
-                                f'set(PROTO_PATH "{protos_path}")')
-            else:
-                replace_in_file(self, protos_cmake_path,
-                                '"${CMAKE_CURRENT_SOURCE_DIR}/third_party/opentelemetry-proto")',
-                                f'"{protos_path}")')
+            replace_in_file(self, protos_cmake_path,
+                            '"${CMAKE_CURRENT_SOURCE_DIR}/third_party/opentelemetry-proto")',
+                            f'"{protos_path}")')
             if self.options.with_otlp_grpc and Version(self.version) < "1.9.1":
                 save(self, protos_cmake_path, "\ntarget_link_libraries(opentelemetry_proto PUBLIC gRPC::grpc++)", append=True)
 
@@ -284,7 +279,6 @@ def _http_client_name(self):
     @property
     def _otel_libraries(self):
         libraries = [
-            self._http_client_name,
             "opentelemetry_common",
             "opentelemetry_exporter_in_memory",
             "opentelemetry_exporter_ostream_span",
@@ -292,6 +286,9 @@ def _otel_libraries(self):
             "opentelemetry_trace",
             "opentelemetry_version",
         ]
+        if self.options.with_otlp_http or self.options.with_elasticsearch or self.options.get_safe("with_jaeger") or self.options.with_zipkin:
+            # https://github.com/open-telemetry/opentelemetry-cpp/blob/v1.12.0/CMakeLists.txt#L452-L460
+            libraries.append(self._http_client_name)
         if self.options.with_otlp_grpc or self.options.with_otlp_http:
             libraries.extend([
                 "opentelemetry_proto",
@@ -383,12 +380,6 @@ def package_info(self):
             ])
 
         if self.options.with_otlp_grpc:
-            if Version(self.version) <= "1.7.0":
-                self.cpp_info.components["opentelemetry_exporter_otlp_grpc"].requires.extend([
-                    "grpc::grpc++",
-                    "opentelemetry_otlp_recordable",
-                ])
-
             self.cpp_info.components["opentelemetry_exporter_otlp_grpc_client"].requires.extend([
                 "grpc::grpc++",
                 "opentelemetry_proto",


Test patch: