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

[question] PkgConfig.fill_cpp_info() Overwrite Existing self.cpp_info #17362

Open
1 task done
tianyi-lu-ocean opened this issue Nov 21, 2024 · 0 comments
Open
1 task done

Comments

@tianyi-lu-ocean
Copy link

tianyi-lu-ocean commented Nov 21, 2024

What is your question?

I have a producer package which uses a system library libcamera. To achieve that, I added the following lines in its CMakeLists.txt,

find_package(PkgConfig)
# Then try to find system libcamera to find the corresponding cameras
pkg_check_modules(LIBCAMERA REQUIRED IMPORTED_TARGET libcamera)
message(STATUS "libcamera library found:")
message(STATUS "    version: ${LIBCAMERA_VERSION}")
message(STATUS "    libraries: ${LIBCAMERA_LINK_LIBRARIES}")
message(STATUS "    include path: ${LIBCAMERA_INCLUDE_DIRS}")

however, in the consumer package's CMakeLists.txt, I have to do the same thing which is quite annoying. I know I can leverage find_dependency() in CMake, but as I rely on CMakeDeps generator, I don't know how to add that into the auto generated <PackageName>Config.cmake file.

After some investigation, I found a recipe tool PkgConfig in conan.tools.gnu category. So, I think I can do something in producer's recipe, like,

def package_info(self);
    pkg_config = PkgConfig(self, 'libcamera')
    pkg_config.fill_cpp_info(self.cpp_info, is_system = True)

and it probably will propagate the include path and library path into consumer. in which case I don't have to duplicate those CMake stuffs in consumer's CMakeLists.txt.

However, it doesn't work, because the PkgConfig.fill_cpp_info() will overwrite the self.cpp_info. I also looked into the source code of PkgConfig, it applies assignment operation for those lists in cpp_info, please see the line here, I guess line 116 could be a potential bug, because it tries to assign a different list to the cpp_info.cxxflags, or maybe the pkg-config does not support cxxflags? Another issue would be the comment of system_libs parameter in fill_cpp_info() which also affects the conan documentation, it seems like just copying the comments of 'is_system`.

Anyway, my questions are,

  • Is this an intentional implementation that will overwrite the incoming cpp_info anyway?
  • Is that possible to just append those lists into the existing lists in cpp_info?

Incidentally, I tried to pass a temporary cpp_info into it, but due to Python passing by reference feature, it will still overwrite the original self.cpp_info. Besides that, I also tried to copy.deepcopy(), but for some reason, it gives me a TypeError exception. So, my current solution is,

  • copy every lists in self.cpp_info into some temporary lists
  • invoke fill_cpp_info(self.cpp_info)
  • append those copied temporary lists back to the self.cpp_info

I don't think this is a decent solution, I would expect to do those in fill_cpp_info().

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant