-
Notifications
You must be signed in to change notification settings - Fork 981
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
[question] How to combine a compiler package with a CMake toolchain file? #7285
Comments
Yes, having 2 profiles is the modern way, was released a few months ago and still experimental, but certainly the way to go. To summarize, to see if I understood correctly:
If I understood correctly, this would be a Summoning @jgsogo to check this.
Yes, the idea would be that the |
Hi! Yours is one of the use-cases we had in mind when designing this new feature, we still need feedback and more examples to polish it before having the final version. So, thanks a lot for sharing with us your thoughts about it. There are more issues about this topic and I'm trying to link them all to #7120. Disclaimer.- Please, realize this is not a final answer, it is something we are working on right now, any of the following alternatives may change or may stop working, or we can recommend in the future a better way to address this scenario. So, please, approach these solutions with caution and do comment and question if you think there is a better way to do it. I would implement your use case as follows (I'm writing just the draft of the recipes, if you need more details about any of them, please ask):
Ok, now let's talk about the toolchain file.
The next challenge is how to use the toolchain file to build the package Old build helper provides a way to inject a custom toolchain by using the compiler.py class Compiler(ConanFile):
...
def package_info(self):
self.env_info.CONAN_CMAKE_TOOLCHAIN_FILE = os.path.join(self.package_folder, "res", "toolchain.cmake") library.py class Library(ConanFile):
name = "library"
settings = "os", "arch", "compiler", "build_type"
requires = "zlib/1.2.11", "boost/1.72.0",...
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build() Other approaches could be to pass information using compiler.py class Compiler(ConanFile):
...
def package_info(self):
self.user_info.TOOLCHAIN = os.path.join(self.package_folder, "res", "toolchain.cmake") library.py class Library(ConanFile):
name = "library"
settings = "os", "arch", "compiler", "build_type"
requires = "zlib/1.2.11", "boost/1.72.0",...
def build(self):
cmake = CMake(self)
cmake.definitions["CMAKE_TOOLCHAIN_FILE"] = self.user_info_build["mycompiler"].TOOLCHAIN
cmake.configure()
cmake.build() Some warnings about the future related to We are not sure if propagating all the environment variables from the build_requires and populating the environment before entering the I'm thinking about activating the environment for each build_requires only while the executable provided by the build requires is running, something like wrapping the executable: cmake
Adding that This change would mean that the approach using the env variable This is just an example. That's all, sorry for the really long answer, but... work in progress 🚧 |
Thank you very much for the detailed replies! @memsharded Your summary is spot on. @jgsogo What you describe is exactly what I was trying to accomplish but I failed at propagating the environment variable to the toolchain file. At least in conan 1.25 the Your idea to use a path relative to the toolchain file provided the missing link 👍. This CMake snippet solved the "propagating the sysroot to the toolchain file" issue for me, thanks! get_filename_component(SYSROOT_PATH "${CMAKE_CURRENT_LIST_DIR}" DIRECTORY) I think the idea of wrapping the executables is very interesting. However making this work properly with CMake toolchain files the way I'm currently using them will be a challenge. Thanks again for the help, I now have a proof of concept. |
Thanks! If you can (and want) to share with us the working POC it would be amazing. Having a look at these examples in the wild helps us a lot when thinking about how to evolve the feature. |
Hi guys,
I'm struggling to make conan work with a compiler that also needs a CMake toolchain file to work. To fully understand the problem I'll quickly go over the setup. There are two systems:
That means we are cross-compiling from windows to linux. We use CMake as the build system. CMake needs a toolchain file for the compiler (there is a chicken-egg problem in cmake when compilation needs a sysroot to succeed, which is the case for us).
We want the conan ecosystem to be independent from outside factors such as installed software, so naturally it makes sense to package the compiler with conan. To model the dependency between compiler and toolchain file, it would also make sense to include the CMake toolchain file in the package or model the dependency differently.
It's worth noting that the toolchain file needs to know the location of the compilers in order to configure
CMAKE_SYSROOT
and all the other paths to the compiler tools (e.g.CMAKE_C_COMPILER
). The sysroot path is currently passed as an environment variable to the toolchain file (if there is a better way, please let me know).From reading the documentation, it looks like the modern way is to use two profiles: win_build and linux_host. One of them should have a
build_requires
dependency on the compiler package. I tried withlinux_host
but that didn't work out.So essentially my question is: How is conan designed to work in that scenario?
build_requires('compiler-package')
in one of the profiles? which one?A slightly different question regarding the new experimental toolchain feature: Are there any plans to make this feature work together with "old-school" CMake toolchain files such that no modifications on the client side are required?
Thanks in advance for your help, you're doing a great job with conan!
The text was updated successfully, but these errors were encountered: