Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/toolchain cmake cross #9115

Merged
merged 9 commits into from Jun 21, 2021

Conversation

memsharded
Copy link
Member

@memsharded memsharded commented Jun 16, 2021

Changelog: Feature: Initial cross-build support in CMakeToolchain with definition of CMAKE_SYSTEM_NAME, CMAKE_SYSTEM_PROCESSOR and CMAKE_SYSTEM_VERSION, deduced from self.settings_build (only using the 2 profiles) and from new [conf] items.
Docs: conan-io/docs#2140

Close #9072

@memsharded memsharded added this to the 1.38 milestone Jun 16, 2021
@memsharded memsharded requested a review from czoido June 17, 2021 07:55
Copy link
Contributor

@lasote lasote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

  • Missing docs
  • I'm wondering if we should add moreconf entries for the rest of the typical stuff that CMake uses in a toolchain file. How would be the alternative for the user without modifying the recipe ( toolchain blocks ) ?
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_SYSROOT /home/devel/rasp-pi-rootfs)
set(CMAKE_STAGING_PREFIX /home/devel/stage)

set(tools /home/devel/gcc-4.7-linaro-rpi-gnueabihf)
set(CMAKE_C_COMPILER ${tools}/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/arm-linux-gnueabihf-g++)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

conan/tools/cmake/toolchain.py Outdated Show resolved Hide resolved
Co-authored-by: Luis Martinez de Bartolome Izquierdo <lasote@gmail.com>
@memsharded
Copy link
Member Author

memsharded commented Jun 18, 2021

I'm wondering if we should add moreconf entries for the rest of the typical stuff that CMake uses in a toolchain file. How would be the alternative for the user without modifying the recipe ( toolchain blocks ) ?

It is possible to directly inject a complete toolchain, with "tools.cmake.cmaketoolchain:user_toolchain" conf, in the UserToolchain block. Is this what you want?

Regarding the CMAKE_FIND_ROOT_PATH_MODE_LIBRARY variables, yes, maybe we should add some of those lines directly in the toolchain?

@KerstinKeller
Copy link

I just saw this PR, and I wanted to give some feedback. We're currently using some dirty hacks to induce the correct Toolchain files for cross builds.
Basically every profile which is a cross compilation profile, sets an environment variable

[env]
TOOLCHAIN_FILE=/common/toolchain-files/arm64_toolchainfile.cmake

But this toolchain file is usually present in the docker images which run the build, back then we didn't find a better solution.

Also it's nice that Conan will now offer to generate these toolchains (or induce variables in the generic toolchain), however from my experience, (real life) cmake toolchain files for cross compilation go beyond just setting sysroot and the compilers, so it might be hard for Conan to generate them correctly.

If profiles could reference existing CMake toolchain files (e.g. don't know where they could be stored, ideally with/next to the profile), and if these existing toolchains would be induced to the one that Conan generates, or (if the user doesn't use the toolchain generator, if Conan could provide a path to the specified toolchain in the profile), that would be extremly useful and beneficial.

@memsharded
Copy link
Member Author

Hi @KerstinKeller

If I understood correctly, I think that this is already available in 1.37 in the [conf] of your profile:

  • tools.cmake.cmaketoolchain:user_toolchain in your profile will include(xxx) that information from the conan_toolchain.cmake
  • tools.cmake.cmaketoolchain:toolchain_file will completely replace the conan_toolchain.cmake by the user provided one.

Does this help? Is this the feature that you want?
Maybe one UX issue is the definition of paths, that would be absolute or something, something we need to check.

@KerstinKeller
Copy link

@memsharded
Ah perfect 👍 , I seem never to be able to keep up with all the new features available 🙈

about the paths of the toolchain files, they are usually tightly coupled to proflex, e.g. one toolchain file per profile, so it would be cool to have it there. Alternative could be a build_requires package, that contains the toolchain, but then I have no clue how to reference that from the profile...

@memsharded
Copy link
Member Author

Alternative could be a build_requires package, that contains the toolchain, but then I have no clue how to reference that from the profile...

We also introduced the possibility for build_requires to pass [conf] items to their consumers, so if the toolchain is inside a package that is build_required it could define that config and point it to its own file: https://docs.conan.io/en/latest/reference/config_files/global_conf.html#configuration-from-build-requires

@KerstinKeller
Copy link

Oh that's very good to know and very handy! Thanks for the info!

@memsharded
Copy link
Member Author

Oh that's very good to know and very handy! Thanks for the info!

:)

Keep in mind that it is experimental, we are doing a ton of work in this, and this is expected to evolve. Feedback very welcome of course!

franramirez688 and others added 3 commits June 21, 2021 10:54
* Added --conf argument as new possible argument for conan create, install, export_dpkg, etc

* Fixed bad positional argument

* Added TODOs and conf merge

* Added several tests for conf cli option

* Simplified integration test

* Added more tests

* Added more complete integration test
Copy link
Contributor

@lasote lasote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget the docs and explain that tools.cmake.cmaketoolchain:user_toolchain invalidates the cross build block

@memsharded memsharded merged commit 80f344c into conan-io:develop Jun 21, 2021
@memsharded memsharded deleted the feature/toolchain_cmake_cross branch June 21, 2021 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] Cross-compilation model in CMakeToolchain
5 participants