conan-io / conan

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

[question] Cross compiling SDL #15237

Open codewithpassion opened 9 months ago

codewithpassion commented 9 months ago

What is your question?

I'm trying to cross compile an application in a Yocto SDK environment. I can cross compile executables and dependent conan packages, so the general setup is working.

My Conan version is: 2.0.14

Now, I tried to add sdl/2.26.1 and things are breaking.

here are my profiles:

Profile host:
[settings]
arch=armv8
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=11
os=Linux
[options]
shared=True
[conf]
tools.build:compiler_executables={'c': 'aarch64-oe4t-linux-gcc', 'cpp': 'aarch64-oe4t-linux-g++'}
tools.build:cflags=[' -march=armv8-a+crc -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/sdk/sysroots/armv8a-oe4t-linux', ' -O2 -pipe -g -feliminate-unused-debug-types ']
tools.build:cxxflags=[' -march=armv8-a+crc -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/sdk/sysroots/armv8a-oe4t-linux', ' -O2 -pipe -g -feliminate-unused-debug-types ']
tools.cmake.cmaketoolchain:user_toolchain=['/opt/sdk/sysroots/x86_64-tdsdk-linux/usr/share/cmake/OEToolchainConfig.cmake']
tools.system.package_manager:mode=report
tools.system.package_manager:tool=apt
tools.cmake.cmake_layout:build_folder_vars=['settings.arch']

[buildenv]
CMAKE_C_COMPILER=aarch64-oe4t-linux-gcc
CMAKE_CXX_COMPILER=aarch64-oe4t-linux-g++
HAVE_GCC=1
HAVE_CXX=1

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=11
os=Linux
[conf]
tools.system.package_manager:mode=check
tools.system.package_manager:tool=apt

What happens, I think, is that sdl is creating it's own toolchain file, without respecting neither the user_toolchain nor the built/target architectures. Which causes the generated package references to be wrong. I can conan install the dependencies, like expat, but if I'm trying to install sdl it still want's to compile dependencies like the expat one that I just compiled/installed again as the reference now is different, presumable because the arch is not passed properly.

I'm using this command to install sdl:

conan install \
    --requires sdl/2.26.1 \
    -vtrace \
    --build=missing \
    -s build_type=Release \
    -pr:b default \
    -pr:h armv8 

The error is:

-- Using Conan toolchain: /home/vscode/.conan2/p/b/expat08f17334dc219/b/build/Release/generators/conan_toolchain.cmake
-- Conan toolchain: Setting CMAKE_POSITION_INDEPENDENT_CODE=ON (options.fPIC)
-- Conan toolchain: Setting BUILD_SHARED_LIBS = OFF
-- The C compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /opt/sdk/sysroots/x86_64-tdsdk-linux/usr/bin/aarch64-oe4t-linux/aarch64-oe4t-linux-gcc
-- Check for working C compiler: /opt/sdk/sysroots/x86_64-tdsdk-linux/usr/bin/aarch64-oe4t-linux/aarch64-oe4t-linux-gcc - broken
CMake Error at /opt/sdk/sysroots/x86_64-tdsdk-linux/usr/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "/opt/sdk/sysroots/x86_64-tdsdk-linux/usr/bin/aarch64-oe4t-linux/aarch64-oe4t-linux-gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/vscode/.conan2/p/b/expat08f17334dc219/b/build/Release/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_8674e/fast && /usr/bin/gmake  -f CMakeFiles/cmTC_8674e.dir/build.make CMakeFiles/cmTC_8674e.dir/build
    gmake[1]: Entering directory '/home/vscode/.conan2/p/b/expat08f17334dc219/b/build/Release/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_8674e.dir/testCCompiler.c.o
    /opt/sdk/sysroots/x86_64-tdsdk-linux/usr/bin/aarch64-oe4t-linux/aarch64-oe4t-linux-gcc   -march=armv8-a+crc -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/sdk/sysroots/armv8a-oe4t-linux   -O2 -pipe -g -feliminate-unused-debug-types    -m64  -fPIE -o CMakeFiles/cmTC_8674e.dir/testCCompiler.c.o -c /home/vscode/.conan2/p/b/expat08f17334dc219/b/build/Release/CMakeFiles/CMakeTmp/testCCompiler.c
    aarch64-oe4t-linux-gcc: error: unrecognized command-line option ‘-m64’
    gmake[1]: *** [CMakeFiles/cmTC_8674e.dir/build.make:78: CMakeFiles/cmTC_8674e.dir/testCCompiler.c.o] Error 1
    gmake[1]: Leaving directory '/home/vscode/.conan2/p/b/expat08f17334dc219/b/build/Release/CMakeFiles/CMakeTmp'
    gmake: *** [Makefile:127: cmTC_8674e/fast] Error 2

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:39 (project)

Did anyone come across this?

Thanks Dom

Have you read the CONTRIBUTING guide?

memsharded commented 9 months ago

Hi @codewithpassion

Thanks very much for your question.

As you describe it, it seems this would be mostly a sdl recipe issue than a Conan issue. If Conan can cross-compile and works for other recipes and packages, then it is very likely that there is some limitation in the sdl2 recipe that disallows or difficults the cross-compilation.

This kind of issue is a bit challenging to solve, it requires some mastery in the specifics of the project build, in this case sdl2, which might not be straightforward.

The error is about -m64 flag:

aarch64-oe4t-linux-gcc: error: unrecognized command-line option ‘-m64’

But I am checking and it seems that this flag is not being injected by Conan. So this might be something hardcoded in the sdl CMakeLists scripts

Have you tried latest 2.28.5? That might contain fixes for the architecture

SpaceIm commented 9 months ago

So this might be something hardcoded in the sdl CMakeLists scripts

There is no -m64 hardcoded in any file of sdl 2.26.1 (except in config.guess not used at all in sdl recipe since recipe relies on upstream CMakeLists).

codewithpassion commented 9 months ago

Hi @memsharded AND @SpaceIm Thanks for your answerS. I have tried 2.28.5 with the same result.

I do have a little bit more insight since yesterday. If I run conan first without -pr:b default -pr:h armv8, so it's compiling for the default profile first, the subsequent run works.

In addition, what I forgot to mention yesterday, as this is in a yocto cross compiler environment, I had run an script that sets environment variables. Including CC, CXX, and others.

I think what happens is, when trying to build SDL as for ARM, somehow it's getting first compiled for X86, which fails because CC/CXX is set. The additional flags like -m64 seems to come from the environment.

I'm trying to move the contents from the environment setup file into the profile at the moment.