Currect usage of pkgconfig / find_package(pkgconfig)
Hi all,
I have recipe A that builds a cmake project which, among other dependencies, also has "find_package(pkgconfig)", so, I inherited the pkgconfig class in the recipe. This cmake project is used by other projects since it builds a .so, thus I am also exporting the AConfig.cmake file, which contains the "find_package(pkgconfig)" call. This works well, the project is built and the pkg-config binary is in recipe-sysroot-native (as expected).
Recipe B builds another cmake project, which depends on the cmake project A. Thus, I added recipe A to recipe B's DEPENDS. As expected, this nicely copies everything needed from recipe A (the .so file, the headers, the AConfig.cmake and ATargets.cmake, etc.). However, (expectedly?) it does not copy the pkg-config binary along with it, thus building recipe B fails, because the "find_package(pkgconfig)" call from the AConfig.cmake file fails.
Is the above usage of PkgConfig correct? I understand the pkg-config binary from recipe A's recipe-sysroot-native should not be copied to recipe B's recipe-sysroot-native, but still don't understand how this all is supposed to work. Shouldn't all dependencies from recipe A also be available for recipe B?
It goes without saying, when I inherit the pkgconfig class in recipe B, everything works as expected (because the pkg-config binary is found in recipe-sysroot-native of recipe B), but this is also not correct, as recipe B does not really depend on pkgconfig and shouldn't even know about it.
Cheers,
Aleksandar
[1]
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Quoted 7 lines · Aleksandar Nikolic via lists.yoctoproject.org
I have recipe A that builds a cmake project which, among other dependencies, also has "
find_package(pkgconfig)", so, I inherited the pkgconfig class in the recipe. This cmake project is used by other projects since it builds a .so, thus I am also exporting the AConfig.cmake file, which contains the "find_package(pkgconfig)" call. This works well, the project is built and the pkg-config binary is in recipe-sysroot-native (as expected).Recipe B builds another cmake project, which depends on the cmake project A. Thus, I added recipe A to recipe B's DEPENDS. As expected, this nicely copies everything needed from recipe A (the .so file, the headers, the AConfig.cmake and ATargets.cmake, etc.). However, (expectedly?) it does not copy the pkg-config binary along with it, thus building recipe B fails, because the "
find_package(pkgconfig)" call from the AConfig.cmake file fails.Is the above usage of PkgConfig correct? I understand the pkg-config binary from recipe A's recipe-sysroot-native should not be copied to recipe B's recipe-sysroot-native, but still don't understand how this all is supposed to work. Shouldn't all dependencies from recipe A also be available for recipe B?
It goes without saying, when I inherit the pkgconfig class in recipe B, everything works as expected (because the pkg-config binary is found in recipe-sysroot-native of recipe B), but this is also not correct, as recipe B does not really depend on pkgconfig and shouldn't even know about it.
Build time dependencies on executables aren't transitive like that. If A needs executable X during its own build, this does not mean that B (which requires A) would need that same executable.
You either need to split .cmake files to have one for own build of A (with pkg-config call), and one for consumers of A (without pkg-config call), or write a bbclass for consumers that contains both DEPENDS on A and inherit pkgconfig.
Alex
Quoted 33 lines · Alexander Kanavin
Quoted 22 lines · Aleksandar Nikolic via lists.yoctoproject.org
I have recipe A that builds a cmake project which, among other dependencies, also has "
find_package(pkgconfig)", so, I inherited the pkgconfig class in the recipe. This cmake project is used by other projects since it builds a .so, thus I am also exporting the AConfig.cmake file, which contains the "find_package(pkgconfig)" call. This works well, the project is built and the pkg-config binary is in recipe-sysroot-native (as expected).Recipe B builds another cmake project, which depends on the cmake project A. Thus, I added recipe A to recipe B's DEPENDS. As expected, this nicely copies everything needed from recipe A (the .so file, the headers, the AConfig.cmake and ATargets.cmake, etc.). However, (expectedly?) it does not copy the pkg-config binary along with it, thus building recipe B fails, because the "
find_package(pkgconfig)" call from the AConfig.cmake file fails.Is the above usage of PkgConfig correct? I understand the pkg-config binary from recipe A's recipe-sysroot-native should not be copied to recipe B's recipe-sysroot-native, but still don't understand how this all is supposed to work. Shouldn't all dependencies from recipe A also be available for recipe B?
Quoted 5 lines
It goes without saying, when I inherit the pkgconfig class in recipe B, everything works as expected (because the pkg-config binary is found in recipe-sysroot-native of recipe B), but this is also not correct, as recipe B does not really depend on pkgconfig and shouldn't even know about it.
Quoted 3 lines
Build time dependencies on executables aren't transitive like that. If A needs executable X during its own build, this does not mean that B (which requires A) would need that same executable.
I was thinking this, thanks for clearing it up! And yes, this does make sense!
Quoted 5 lines
You either need to split .cmake files to have one for own build of A (with pkg-config call), and one for consumers of A (without pkg-config call), or write a bbclass for consumers that contains both DEPENDS on A and inherit pkgconfig.
Hm, I have a question regarding this idea (please ignore it if it goes out of scope for Yocto).
The A cmake project calls find_package(PkgConfig) because it uses the command pkg_check_modules(). AFAIK this command just looks for modules, so I need this in every cmake project which depends on A, basically meaning inheriting pkconfig.bbclass is the only solution here.
Aleksandar
Quoted 2 lines
Alex
Quoted 1 line · Aleksandar Nikolic via Lists.Yoctoproject.Org
The A cmake project calls
find_package(PkgConfig)because it uses the commandpkg_check_modules(). AFAIK this command just looks for modules, so I need this in every cmake project which depends on A, basically meaning inheriting pkconfig.bbclass is the only solution here.
But what is it actually checking for? Is it something that only A would need? If so, then why consumers of A are forced to use the same file which contains checks for things they don't actually use?
Alex
Quoted 4 lines · Alexander Kanavin
But what is it actually checking for? Is it something that only A would need? If so, then why consumers of A are forced to use the same file which contains checks for things they don't actually use?
It is checking for gstreamer libraries. Here's a bit more context, it can very well be though, that we are using find_package(...) wrongly when it comes to Yocto.
Recipe / Project A
Note that the below code snippet is as-is and that I have issues with this because the Targets.cmake file eventually contains host paths, meaning when the recipe is not built from scratch but pulled from the sstate-cache for example, the build fails because the Targets.cmake file contains paths to recipe-sysroot, which in the second case do not exist. But this is another issue, I don't want to bother you with it. Anyway, the code snippet:
find_package(PkgConfig)pkg_check_modules(GST REQUIRED gstreamer-1.0>=1.4) target_include_directories(A PUBLIC ${GST_INCLUDE_DIRS}) target_compile_options(A PUBLIC ${GST_CFLAGS}) target_link_libraries(A PUBLIC ${GST_LIBRARIES})
Additionally (and I believe this is _the_ issue), our every CMake project writes and exports an additional cmake file, called Deps.cmake, which (1) contains all the dependencies (find_package(...) calls) and (2) is through the Config.cmake file included by the consumer projects. This means that consumers also call find_package(PkgConfig) through this Config.cmake file, which, if pkgconfig is not inherited, fails (as in this case).
While writing this, it occurred to me whether we really need to export the Deps.cmake file and especially find_package(PkgConfig) line. So I just performed two tests: (1) I removed the find_package(PkgConfig) line from our Deps.cmake file and (2) I completely removed the export of the Deps.cmake file. The result: the Yocto build works in both cases, so I am wondering why we even export the Deps.cmake file through Config.cmake... Maybe because we also build on Windows/Ubuntu and export our packages with Conan, I'll double check with my colleagues next week.
Aleksandar
Quoted 2 lines
Alex
Quoted 11 lines · Aleksandar Nikolic
While writing this, it occurred to me whether we really need to export the Deps.cmake file and especially
find_package(PkgConfig)line. So I just performed two tests: (1) I removed thefind_package(PkgConfig)line from our Deps.cmake file and (2) I completely removed the export of the Deps.cmake file. The result: the Yocto build works in both cases, so I am wondering why we even export the Deps.cmake file through Config.cmake... Maybe because we also build on Windows/Ubuntu and export our packages with Conan, I'll double check with my colleagues next week.
I stand corrected. If I completely remove the export of the Deps.cmake file, the build fails because of transient calls in cmake Macros/Function. For example project A calls macroB() defined in project B, while macroB() further calls macroC() defined in project C. So if BConfig.cmake (which is included by A) does not contain find_package(C) (which it would if exporting Deps.cmake which contains that call), building A fails, because macroC() is not defined, as no one calls find_package(C)-
Quoted 9 lines
Aleksandar
Quoted 1 line
Alex
Quoted 1 line · Aleksandar Nikolic via lists.yoctoproject.org
It goes without saying, when I inherit the pkgconfig class in recipe B, everything works as expected (because the pkg-config binary is found in recipe-sysroot-native of recipe B), but this is also not correct, as recipe B does not really depend on pkgconfig and shouldn't even know about it.
But it does: it’s calling cmake macros that use pkgconfig. Inheriting the class is the right thing to do here.
Ross
Quoted 4 lines · Ross Burton
On 11 Oct 2024, at 06:31, Aleksandar Nikolic via lists.yoctoproject.org <[email protected]> wrote:
Quoted 8 lines
Quoted 5 lines
It goes without saying, when I inherit the pkgconfig class in recipe B, everything works as expected (because the pkg-config binary is found in recipe-sysroot-native of recipe B), but this is also not correct, as recipe B does not really depend on pkgconfig and shouldn't even know about it.
But it does: it’s calling cmake macros that use pkgconfig. Inheriting the class is the right thing to do here.
I misspelled a bit, I was going to say "recipe B does not directly depend on pkgconfig, but rather through recipe A". What I meant by it was: I see recipe A as a blackbox which is supposed to bring all its dependencies with it and it does, except binaries (why they are not here has already been cleared up by Alex). I was just thinking "If I didn't know what recipe A depends on, but only that my recipe B depends on A, I would never inherit pkgconfig as recipe B does not know about this dependency". But then again, I fully understand why dependencies on executables aren't transitive in Yocto.
Aleksandar
Quoted 2 lines
Ross