Skip to contentSkip to conversation

Run generated executable in cmake recipe #cmake #kirkstone #make #native #yocto

DISCUSSION Darek Konopka 3 participants 3 messages Oct 19, 2023 – Oct 20, 2023

lore
Share & tools
lore
#0 lore raw

Hello all,

So I have a cmake project that uses an executable generated from a cmake subproject. My architecture is as such

├── ProjectA
├── projecta_1.0.bb ( http://projecta_1.0.bb/ )
├── files
├── ProjectA
├── CMakeLists.txt
├──  ProjectB
├── CMakeLists.txt

My recipe is a standard recipe that inherits pkgconfig cmake
The issue that occurs is that when manually building ProjectA natively it builds as expected, but when building it with yocto, during the do_compile for ProjectA, it says it is missing the executable generated by ProjectB located in /usr/bin/ProjBEXE (this executable is needed in order to compile ProjectA).

What did work is creating a projectb-native recipe that runs cmake-native, and then have projecta depend on it, but I was wondering, is there a way to have projecta_1.0.bb ( http://projecta_1.0.bb/ ) build the executable and use it within its own cmake? Perhaps making projectB a package to have projectA use it?
NOTE: I am using yocto kirkstone

#1 lore raw

Hi Darek

Making the recipe compiling for cross and native and adding a DEPENDS from cross to native seems to be the cleanest and most Yocto-ish way to me.

Alternatively this patch would allow to run cross compiled executables with Qemu in the cmake project
https://git.yoctoproject.org/poky-contrib/commit/?h=adrianf/devtool-ide&id=6c63df973d9530ecabc9480f8ba2aba3ff93952f.
But that's not the most common approach.

It's also possible to hack a cmake script which allows to pass a native tool-chain file for B. But this approach needs some hacks because cmake is designed to work with one tool-chain file only. I did that for a special use case, but I'm not aware of a public example.

Regards,
Adrian

Darek Konopka <[email protected]> schrieb am Do., 19. Okt. 2023, 17:21:

Quoted 42 lines

Hello all,

So I have a cmake project that uses an executable generated from a cmake subproject.
My architecture is as such

    ├── ProjectA
          ├── projecta_1.0.bb
          ├── files
               ├── ProjectA
                     ├── CMakeLists.txt
                     ├──  ProjectB
                         ├── CMakeLists.txt

My recipe is a standard recipe that inherits pkgconfig cmake The issue that occurs is that when manually building ProjectA natively it builds as expected, but when building it with yocto, during the do_compile for ProjectA, it says it is missing the executable generated by ProjectB located in /usr/bin/ProjBEXE (this executable is needed in order to compile ProjectA).

What did work is creating a projectb-native recipe that runs cmake-native, and then have projecta depend on it, but I was wondering, is there a way to have projecta_1.0.bb build the executable and use it within its own cmake? Perhaps making projectB a package to have projectA use it?
NOTE: I am using yocto kirkstone

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#61419):
https://lists.yoctoproject.org/g/yocto/message/61419
Mute This Topic: https://lists.yoctoproject.org/mt/102062177/4454582
Mute #native:https://lists.yoctoproject.org/g/yocto/mutehashtag/native Mute #yocto:https://lists.yoctoproject.org/g/yocto/mutehashtag/yocto Mute #cmake:https://lists.yoctoproject.org/g/yocto/mutehashtag/cmake Mute #kirkstone:
https://lists.yoctoproject.org/g/yocto/mutehashtag/kirkstone
Mute #make:https://lists.yoctoproject.org/g/yocto/mutehashtag/make Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#2 lore raw
Quoted 1 line · Adrian Freihofer via lists.yoctoproject.org

Making the recipe compiling for cross and native and adding a DEPENDS from cross to native seems to be the cleanest and most Yocto-ish way to me.

Agreed, there’s plenty of prior art in oe-core that does this.

Quoted 1 line

Alternatively this patch would allow to run cross compiled executables with Qemu in the cmake project https://git.yoctoproject.org/poky-contrib/commit/?h=adrianf/devtool-ide&id=6c63df973d9530ecabc9480f8ba2aba3ff93952f. But that's not the most common approach.

The downside of this is that in a situation where qemu-user doesn’t work, you can’t build the recipe. So I’d still recommend a native recipe in this case, because as Adrian said CMake just does not support the ability to build a single binary with the native tools for use in the build.

This is one of many reasons why I dislike CMake: it’s actively hostile for cross compiling. The toolchain support looks good at first, but the ability to easily say “build this binary with the host compiler so I can run it during the build” is important and absolutely missing in CMake.

Ross