conan-io / conan

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

[bug] Cross compiling to bare metal targets does not work with CMakeToolchain #11041

Open serghov opened 2 years ago

serghov commented 2 years ago

Conan has os == 'Arduino' type for bare metal compilation, however when generating a project with CMakeToolchain generator and a bare metal compiler cmake fails on compiler check stage.

-- Check for working CXX compiler: /usr/local/bin/arm-none-eabi-g++
-- broken

Here is the profile I am trying to write for bare metal compilation

include(default)
[settings]
arch=armv6
os=Arduino
os.board=none
compiler=gcc
compiler.version=11.2
compiler.libcxx=libstdc++11
build_type=Release
[conf]
tools.build:cxxflags=[]
tools.build:cflags+=[]
[env]
CC=/usr/local/bin/arm-none-eabi-gcc
CXX=/usr/local/bin/arm-none-eabi-g++
CMAKE_SYSTEM_PROCESSOR=arm

The solution would be for conan to add set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) to conan_toolchain.cmake while generating.

The whole 'Arduino' system as far as I understand is very underdeveloped in conan, however this fix would make cross compiling for embedded targets much easier.

czoido commented 2 years ago

Hi @serghov, Thanks for the suggestion, we will check if that case is worth adding to the CMakeToolchain generator. Anyway, you could use the tools.cmake.cmaketoolchain:toolchain_file=<filepath> configuration to use your own toolchain and set that variable in CMake. Please, check the Conan documentation for more detailed information.

memsharded commented 2 years ago

I think that for Conan 2.0, Arduino shouldn't be a first level "os", but a subsetting of "baremetal"

dkoerner-festo commented 1 month ago

I think that for Conan 2.0, Arduino shouldn't be a first level "os", but a subsetting of "baremetal"

@memsharded Why? We use RTOSs like ThreadX and my first approach would be to define it as "os" and not as a second level of "baremetal". What are the advantages when using the second level of "baremetal"?

memsharded commented 1 month ago

Well, that is irrelevant now, Conan 2 was released Feb 2023, and it didn't move Arduino to be a nested subsetting of os.

The thing with baremetal is that for example it will map automatically to a "baremetal": "Generic" in CMake toolchains (CMAKE_SYSTEM_NAME), while others won't.

This ticket would need an update for latest Conan 2. There are nowadays some new features, like the possibility to inject arbitrary CMake variables into CMakeToolchain, that could be used for this issue.