Conan: [bug] cmake + pkg_config generator: fail if pkgconfig components and conan 1.28.0

Created on 2 Aug 2020  路  5Comments  路  Source: conan-io/conan

Environment Details (include every applicable attribute)

  • Operating System+version: Windows 10
  • Compiler+version: Visual Studio 2019
  • Conan version: 1.28.0
  • Python version: 3.7.1

Steps to reproduce (Include if Applicable)

  • add pkgconfig components to brotli recipe in CCI using https://github.com/conan-io/conan-center-index/pull/2319:

      def package_info(self):
          includedir = os.path.join("include", "brotli")
          # brotlicommon
          self.cpp_info.components["brotlicommon"].names["pkg_config"] = "libbrotlicommon"
          self.cpp_info.components["brotlicommon"].includedirs.append(includedir)
          self.cpp_info.components["brotlicommon"].libs = [self._get_decorated_lib("brotlicommon")]
          # brotlidec
          self.cpp_info.components["brotlidec"].names["pkg_config"] = "libbrotlidec"
          self.cpp_info.components["brotlidec"].includedirs.append(includedir)
          self.cpp_info.components["brotlidec"].libs = [self._get_decorated_lib("brotlidec")]
          self.cpp_info.components["brotlidec"].requires = ["brotlicommon"]
          # brotlienc
          self.cpp_info.components["brotlienc"].names["pkg_config"] = "libbrotlienc"
          self.cpp_info.components["brotlienc"].includedirs.append(includedir)
          self.cpp_info.components["brotlienc"].libs = [self._get_decorated_lib("brotlienc")]
          self.cpp_info.components["brotlienc"].requires = ["brotlicommon"]
          if self.settings.os == "Linux":
              self.cpp_info.components["brotlienc"].system_libs = ["m"]
    
          if self.settings.os == "Windows" and self.options.shared:
              self.cpp_info.components["brotlicommon"].defines.append("BROTLI_SHARED_COMPILATION")
              self.cpp_info.components["brotlidec"].defines.append("BROTLI_SHARED_COMPILATION")
              self.cpp_info.components["brotlienc"].defines.append("BROTLI_SHARED_COMPILATION")
    
      def _get_decorated_lib(self, name):
          libname = name
          if not self.options.shared:
              libname += "-static"
          return libname
    
  • add pkg_config generator in test_package (and keep cmake generator)
  • conan create . brotli/1.0.7@

Logs (Executed commands with output) (Include/Attach if Applicable)

brotli/1.0.7 (test package): Generator pkg_config created libbrotlicommon.pc
brotli/1.0.7 (test package): Generator pkg_config created libbrotlienc.pc
brotli/1.0.7 (test package): Generator pkg_config created libbrotlidec.pc
brotli/1.0.7 (test package): Generator pkg_config created brotli.pc
brotli/1.0.7 (test package): ERROR: Generator cmake(file:conanbuildinfo.cmake) failed
'libbrotlicommon'
ERROR: 'libbrotlicommon'

If pkg_config generator is removed from test_package, cmake generator succeeds.

Most helpful comment

I've found the bug introduced by the pkg_config+components generator. I'll have a look to the ncurses one @madebr has just linked.

All 5 comments

most probably linked: when using cmake generator on a package requiring libpq, this error happens:

ERROR: Generator cmake(file:conanbuildinfo.cmake) failed
'pgcommon'
Traceback (most recent call last):
  File "/Users/runner/hostedtoolcache/Python/3.7.8/x64/lib/python3.7/site-packages/conans/client/generators/__init__.py", line 108, in write_generators
    content = generator.content
  File "/Users/runner/hostedtoolcache/Python/3.7.8/x64/lib/python3.7/site-packages/conans/client/generators/cmake.py", line 109, in content
    sections.extend(generate_targets_section(self.deps_build_info.dependencies, "cmake"))
  File "/Users/runner/hostedtoolcache/Python/3.7.8/x64/lib/python3.7/site-packages/conans/client/generators/cmake_common.py", line 224, in generate_targets_section
    use_deps = ["CONAN_PKG::%s" % dependencies_dict[d].get_name(generator_name) for d in dep_info.public_deps]
  File "/Users/runner/hostedtoolcache/Python/3.7.8/x64/lib/python3.7/site-packages/conans/client/generators/cmake_common.py", line 224, in <listcomp>
    use_deps = ["CONAN_PKG::%s" % dependencies_dict[d].get_name(generator_name) for d in dep_info.public_deps]
KeyError: 'pgcommon'

see also: https://github.com/conan-io/conan-center-index/pull/2382

also, when using cmake generator on a package requiring openssl, the following error happens:

 ERROR: Generator cmake(file:conanbuildinfo.cmake) failed
'libcrypto'
Traceback (most recent call last):
  File "/opt/pyenv/versions/3.7.5/lib/python3.7/site-packages/conans/client/generators/__init__.py", line 108, in write_generators
    content = generator.content
  File "/opt/pyenv/versions/3.7.5/lib/python3.7/site-packages/conans/client/generators/cmake.py", line 109, in content
    sections.extend(generate_targets_section(self.deps_build_info.dependencies, "cmake"))
  File "/opt/pyenv/versions/3.7.5/lib/python3.7/site-packages/conans/client/generators/cmake_common.py", line 224, in generate_targets_section
    use_deps = ["CONAN_PKG::%s" % dependencies_dict[d].get_name(generator_name) for d in dep_info.public_deps]
  File "/opt/pyenv/versions/3.7.5/lib/python3.7/site-packages/conans/client/generators/cmake_common.py", line 224, in <listcomp>
    use_deps = ["CONAN_PKG::%s" % dependencies_dict[d].get_name(generator_name) for d in dep_info.public_deps]
KeyError: 'libcrypto'

see also https://github.com/conan-io/conan-center-index/pull/2383

Last week, I was seeing something similar on Windows:
https://github.com/conan-io/conan-center-index/pull/2351#issuecomment-667236099

I've found the bug introduced by the pkg_config+components generator. I'll have a look to the ncurses one @madebr has just linked.

Last week, I was seeing something similar on Windows:
conan-io/conan-center-index#2351 (comment)

It is the same issue, pkg_config wrongly modifies cpp_info values.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tonka3000 picture tonka3000  路  3Comments

Adnn picture Adnn  路  3Comments

uilianries picture uilianries  路  3Comments

theodelrieu picture theodelrieu  路  3Comments

Polibif picture Polibif  路  3Comments