Open markspacehub opened 1 month ago
What I am doing is to create a toolchain for the target system, not very differently from android-ndk or mingw-builds.
After you have the toolchain than you can create the profile you need. In the profile you can also define the sysroot and other environment variables that are needed for the build.
Hi @elvisdukaj, thanks for your reply! In those exampled you linked, I cannot see any profile or toolchain files and I am unable to work out how exactly they are adding the sysroot. I only need the sysroot when I am cross-building, but the build machine is also a valid target and would like to get its dependencies from conan in the usual way.
Am I able to simply add sysroot to the end of my profile? :
[settings]
arch=armv8
build_type=Release
compiler=gcc
compiler.cppstd=14
compiler.libcxx=libstdc++
compiler.version=7.5
os=Linux
[buildenv]
CC=/home/user/projects/linux/buildroot/output/host/bin/aarch64-linux-gnu-gcc
CXX=/home/user/projects/linux/buildroot/output/host/bin/aarch64-linux-gnu-g++
LD=/home/user/projects/linux/buildroot/output/host/bin/aarch64-linux-gnu-ld
sysroot=/path/to/my/sysroot
or do I need to be more specific, I am using CMake, can I set specific CMAKE_SYSROOT variables here?
This can be done in different ways, if you take as an example the android ndk package_info
you can see https://github.com/conan-io/conan-center-index/blob/master/recipes/android-ndk/all/conanfile.py#L287 that the sysroot is defined. Here it is like conan 1 was doing it: https://github.com/conan-io/conan-center-index/blob/master/recipes/android-ndk/all/conanfile.py#L346
One important thing to note that CMakeToolchain
will automatically add the android toolchain file.
CMakeToolchain automatically adds the standard Android toolchain file that ships with the NDK
That means that ideally you will create your own cmake tool chain file like and specify the toolchain environment.
Most probably you will need your custom one.
Ok, that all makes sense. I have my own cmake toolchain file that I was using before I began to integrate conan. I was hoping that I could set this up in the conan profile that I use in the conan install command, but I can add it in the conanfile.py instead!
Here you can find even more information: https://docs.conan.io/2/reference/tools/cmake/cmaketoolchain.html#using-a-custom-toolchain-file
Hi @markspacehub
Thanks for the question, and sorry for the delay in replying to this thread 😓
You can use any custom CMake toolchain through your profile for sure:
# your settings, etc.
[conf]
tools.cmake.cmaketoolchain:user_toolchain+=["/path/to/your/toolchain.cmake"]
# Do you want to inject a sysroot? This will set the CMAKE_SYSROOT in the conan_toolchain.cmake
tools.build:sysroot="/path/to/your/sysroot"
Talking about creating a toolchain as a Conan package, here you can find more information.
Do not hesitate to ask any other doubts.
Ah perfect - that was the last piece I was looking for @franramirez688. Thanks
I have one more question regarding this @franramirez688. When I am cross building with a sysroot, I want the libraries in sysroot to be used, and not pulled from conan center. But if they dont exist in sysroot, or no sysroot was provided then I do want them pulled from conan center.
For example: glog library Sysroot contains glog.so.0.5.0 Latest conan center is glog.so.0.7.1
Local building, or cross building without a sysroot or without glog in the sysroot wants to use the latest version from conan center. However if the library is present in sysroot then I want to use the version present in sysroot.
Is this possible? Arch, os etc from the profile can conditionally self.require("glog/0.7.1"), but if the same arch, os etc is used but without the sysroot then glog will be missing. Is there a way to check if the library is present in the sysroot first?
Maybe it has to be an option for the package? (IsGlogInSysroot)
What is your question?
I am trying to integrate Conan into my team's work. So far I have successfully made Conan packages of our libraries and can get everything to work building locally for my Ubuntu Linux machine (using the local Conan cache). We originally used CMake as the build tool, with CMake presets and toolchain files setting CMAKE_FIND_ROOT_PATH and the compiler etc. The target platform is an embedded system (which we cross-compile for) and the chip manufacturers have provided a linux bundle which we build with buildroot. Inside the bundle are many libraries inside a sysroot folder. I would like Conan to look for libaries inside this first, and if they dont exist then to look on my build machine's local conan cache and finally on Conan Center (further down the line I want to host our libraries in an artifact repository, but that isnt needed now).
I know I need to create a Conan Profile for cross compiling, but how do I tell Conan to use the libraries in the linux bundle if they exist, otherwise to find them itself? Should I be putting this whole massive linux bundle as a Conan package? Should I attach my existing toolchain onto the one generated by Conan? (This would add my CMAKE_FIND_ROOT_PATH and set CMAKE_FIND_ROOT_PATH_MODE_LIBRARY etc to NEVER) Any help or advice would be appreciated!
Have you read the CONTRIBUTING guide?