How to combine conan_toolchain.cmake and yocto OEToolchainConfig.cmake?

347 Views Asked by At

I have a c++ project that I am cross compiling using a yocto sdk. I'm starting to use conan 2.0 as a package manager to fetch third party libraries for my c++ project.

I created a conanfile.txt at the root of my project, using the cmake generators:

[generators]
CMakeDeps
CMakeToolchain

I also created a host and build profiles:

  • conan_profile_cross_build
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=12
os=Linux
  • conan_profile_cross_host
[settings]
arch=armv8
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=12
os=Linux

To use it I run conan install and output the results into the build folder that will be used by cmake afterwards.

conan install /src --profile:build=conan_profile_cross_build "
            f"--profile:host=conan_profile_cross_host "
            f" --build=missing --output-folder=build 

The issue

To allow cmake to find the dependencies, you must call cmake with a toolchain file: cmake -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake

However when building with yocto sdk, you source the environment file: source environment-setup-armv8a-enchanted_tools-linux, and it creates a cmake alias that already sets a CMAKE_TOOLCHAIN_FILE to OEToolchainConfig.cmake which is somewhere inside the sdk.

cmake only allows one toolchain file so I can't use both of them.

I've seen in the conan documentation that you should edit OEToolchainConfig.cmake which I did but it doesn't solve the problem that I can only choose one toolchain file.

Question

How can I still use the sdk and allow cmake to find the conan provided packages ? Maybe there is something to do in the host conan profile ? Or is this workflow not a good idea and I should install the dependencies in yocto sdk directly ? I am also compiling this project on native ubuntu linux desktop and here conan works great. The idea is to easily test new dependencies before going through the hoops of integrating them into yocto and regenerating a whole sdk.

1

There are 1 best solutions below

0
Loki On

Conan allows to include a second toolchain via a configuration option. I added this in the host profile:

[conf]
tools.cmake.cmaketoolchain:user_toolchain="/home/yoctouser/sdk/sysroots/x86_64-etelsdk-linux/usr/share/cmake/OEToolchainConfig.cmake"]

I didn't need to edit the OEToolchainConfig.cmake file actually.