conan-io / conan-center-index

Recipes for the ConanCenter repository
https://conan.io/center
MIT License
928 stars 1.67k forks source link

[question] How to properly inject another package component the other package's namespace (e.g. `Boost::`) #6682

Open leha-bot opened 2 years ago

leha-bot commented 2 years ago

I made a recipe for fork of the removed Boost.SIMD library (I archived it too here) (not planned for conan-center as library until it will be requested 😉).

Some exposition: Boost.SIMD is a portable SIMD library that was proposed as a Boost library, but did not accepted. It injects its exported CMake target into the Boost:: namespace and recursively includes the FindBoost.cmake in its generated files to "wrap" the upstream Boost components.

I modelled this injection like the Conan-Center's boost-ext-ut, capitalizing the cmake_find_package[_multi].name to Boost, and in test consumer case the Boost.SIMD (for brevity I copied the package_info() method here):

def package_info(self):
        self.cpp_info.names["cmake_find_package"] = "Boost"
        self.cpp_info.names["cmake_find_package_multi"] = "Boost"
        self.cpp_info.filenames["cmake_find_package"] = "Boost.SIMD" # the original find_package() name
        self.cpp_info.filenames["cmake_find_package_multi"] = "Boost.SIMD"
        self.cpp_info.components["SIMD"].names["cmake_find_package"] = "SIMD"
        self.cpp_info.components["SIMD"].names["cmake_find_package_multi"] = "SIMD"
        self.cpp_info.components["SIMD"].requires = ["boost::headers"]

and the main Boost didn't compose into the one namespace (the generated FindBoost.cmake overrides the FindBoost.SIMD.cmake logic, so this CMake snippet won't work:

find_package(Boost.SIMD)
find_package(Boost COMPONENTS date_time SIMD)
add_executable(test-simd some-test.cpp)
target_link_libraries(test-simd Boost::date_time Boost::SIMD)
find_package(Boost.SIMD)
# note that SIMD as component is not used in "parent" boost's find_package()
find_package(Boost COMPONENTS date_time # SIMD)
add_executable(test-simd some-test.cpp)
target_link_libraries(test-simd Boost::date_time Boost::SIMD)

I think that the conan upstream could provide some hooks to allow to compose the recipes into one big namespace (it could also helps with some huge frameworks like Qt, which has a lot of libraries outside the main distribution (e.g. QtPDF with exported CMake target Qt5::PDF, etc...), poco and another...)

Thanks for your attention!

P.s. boost-ext-ut has a bug with boost namespaces, I will report it in another issue and'll make an PR 😊 , if you don't mind

madebr commented 2 years ago

I don't think conan has such functionality (yet). This feature is useful though.

Perhaps open a question/feature request at conan's bug tracker (if such a question does not exist already).

leha-bot commented 2 years ago

Thanks for you advice, I'll make an issue in conan itself. Btw I think that the boost-ex-simd should live in conan center (as it has a lot of forks and thus it is used by many people), may I suggest my own recipe to conan-center? If you don't mind

madebr commented 2 years ago

Sure, don't hesitate to open a pr for it. I'm wondering, it looks like the original boost.simd is no longer maintained. See https://github.com/agenium-scale/boost.simd They say it is replaced by https://github.com/agenium-scale/nsimd.

You intend to use https://github.com/procxx/boost.simd as its homepage. Will that be a stable source/project?

leha-bot commented 2 years ago

Yes, I specially forked it into our own small C++ community organisation for archive purposes :)

leha-bot commented 2 years ago

The nsimd is pretty cool too, but it requires to codegen the sources. I'm currently experimenting with local recipe which do its codegen logic in source(), and will try to make an PR too