conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.13k stars 968 forks source link

[question] Cross compiling embedded with gcc-arm-none-eabi #10053

Open Ju1He1 opened 2 years ago

Ju1He1 commented 2 years ago

Hey, I'd like to use conan to cross compile some 3rd parties for an embedded target with gcc-arm-none-eabi compiler (GCC 10 is used)

I've found this info https://github.com/conan-io/conan/issues/675 bit it looks a little bit outdated to me

What os_target and arch_target should i use for embedded builds. target on embedded is usually "none" but this is not in the list

I tried

  set(settings 
     #host
    "os_build=Windows"
    "arch_build=x86_64"
    #Target
    "os_target=None"
    "arch_target=None")

 conan_cmake_install(
    PATH_OR_REFERENCE
    .
    BUILD
    missing
    REMOTE
    conan-center
    SETTINGS
    ${settings})

However it looks like "None" is not a valid arch_target value The settings.yml currently contains only these (cross) compiling values


# Only for cross building, 'os_build/arch_build' is the system that runs Conan
os_build: [Windows, WindowsStore, Linux, Macos, FreeBSD, SunOS, AIX]
arch_build: [x86, x86_64, ppc32be, ppc32, ppc64le, ppc64, armv5el, armv5hf, armv6, armv7, armv7hf, armv7s, armv7k, armv8, armv8_32, armv8.3, sparc, sparcv9, mips, mips64, avr, s390, s390x, sh4le, e2k-v2, e2k-v3, e2k-v4, e2k-v5, e2k-v6, e2k-v7]

# Only for building cross compilation tools, 'os_target/arch_target' is the system for
# which the tools generate code
os_target: [Windows, Linux, Macos, Android, iOS, watchOS, tvOS, FreeBSD, SunOS, AIX, Arduino, Neutrino]
arch_target: [x86, x86_64, ppc32be, ppc32, ppc64le, ppc64, armv5el, armv5hf, armv6, armv7, armv7hf, armv7s, armv7k, armv8, armv8_32, armv8.3, sparc, sparcv9, mips, mips64, avr, s390, s390x, asm.js, wasm, sh4le, e2k-v2, e2k-v3, e2k-v4, e2k-v5, e2k-v6, e2k-v7, xtensalx6, xtensalx106]

Is it currently possible to cross compile with gcc arm none eabi using conan, or do I have to manually apply the fix posted here https://github.com/conan-io/conan/issues/675#issuecomment-262303771

Thx for you answer :)

Edit: I did take a look at https://docs.conan.io/en/1.6/systems_cross_building/cross_building.html , especially the Windows to Raspberry PI (Linux/ARM) section but cortex M MCUs don't have arch=armv7

memsharded commented 2 years ago

Hi @Ju1He1

It seems you are using quite old information. (For example using the docs for Conan 1.6, while we are at Conan 1.42, the former is like 3 years old now).

The cross-build model has also been updated. The modern approach doesn't use os_build in the profile, but instead uses 2 profiles, the "build" profile and the "host" profile. You could see a short demo in this video (https://youtu.be/VzUJQw89U7o?t=3188),

It would also be good to try things without the cmake-conan integration first, because it is possible that that integration is not very well ready to do cross-building.

Ju1He1 commented 2 years ago

Hey thx for this interesting video :) I will go with the 2 separate profiles for cross compiling.

However I still got some questions

If this all is not possible, can I tell conan just to do an export and no build. I can live with compiling the 3rd parties on each project rebuild.

Thx for your fast answers :)

Ju1He1 commented 2 years ago

@memsharded I tried the extra profile for cross building as you suggested. This worked. I'm currently working with

target_host=arm-none-eabi
standalone_toolchain=C:/toolchains/arm-none-eabi-gcc-10.2.1
cc_compiler=gcc
cxx_compiler=g++

[settings]
os=Linux
arch=armv6
compiler=gcc
compiler.version=10
compiler.libcxx=libstdc++11
build_type=Release

[env]
CONAN_CMAKE_FIND_ROOT_PATH=$standalone_toolchain/$target_host
PATH=[$standalone_toolchain/bin]
CHOST=$target_host
AR=$target_host-ar
AS=$target_host-as
RANLIB=$target_host-ranlib
LD=$target_host-ld
STRIP=$target_host-strip
CC=$target_host-$cc_compiler
CXX=$target_host-$cxx_compiler
CXXFLAGS="-I $standalone_toolchain/$target_host/include -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 --specs=nosys.spec"

However as you can see there are many hardcoded path inside this profile. However since some of these paths (like the Compiler version) are project depended, I'd like to access the project specific settings configured in CMake.

So is it possible to get the toolchain path from a CMake Variable or an environment variable?