-
Notifications
You must be signed in to change notification settings - Fork 993
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] Using custom cross-compilation toolchains with requirements and CMakeDeps #16376
Comments
Hi @rollebolle Thanks for your question. The def generate(self):
tc = CMakeToolchain(self)
gen_folder = self.generators_folder.replace("\\", "/") # Windows-CMake not happy
tc.variables["MYPATH_GEN"] = gen_folder # IT will be a variable in conan_toolchain.cmake
tc.cache_variables["MYPATH_GEN"] = gen_folder # It will be a cache variables in CMakePresets (and passed in CLI arg)
tc.generate() Does this make sense for your use case? |
Thanks. This does work and I I'll use it. However it means my recipe now has adapations that is only needed in the special case of supplying a toolchain from outside. Ideally I would like the recipe to be agnostic to this detail. As I wrote above, this was not needed with the old generators as the FindXXX files happened to all end up in the build folder. Let me know if I misunderstood. |
Quick question:
Why don't you use the generated |
I tried that but get some nasty conflicts - I think in many advanced cases you want to have complete control of the toolchain file, as in our case. |
I have been thinking a bit about this problem, and honestly I don't know yet what would be the best approach. I think it might be possible to try to find the generated files from your toolchain. This might be done for example by looking for the location of the What would be the best mechanism to communicate the Please let me know if this helps. |
Thanks for taking the time to think about this. Would it make sense for Conan to always append a valid CMAKE_MODULE_PATH to CMakeUserPresets.json, so that even if we use a custom toolchain we can find the dependencies? I don't really know the details around this, but in Conan 2, a dependency on using the generated toolchains to be able to find any requirement packages was introduced. This in combination with the common cross-compile scenario where we want to use a custom toolchain file certainly makes it a bit more complicated to "get it right". |
Yes, this might be something worth exploring.
yes, it is true that the But in any case, I understand the use case, let me discuss with the team, it sounds that to minimize risks we could add those variables when the |
I am exploring the idea in #16455, but it is a draft, I am not very convinced, I might explore other approaches too. |
I have been syncing with the team about #16455 we are still not fully convinced about the approach. We are going to explore the possibility of fully controlling the |
Ok interesting! |
This would be the follow up PR: #16563 Full control over which blocks are enabled or not, with just a conf. That would allow to keep the If you want to give it a try from sources, that would be very useful feedback. |
#16563 has been merged for next 2.5, and it will be the recommended approach for this issue, feedback welcome! |
I tried the feature and it works. Only small unexpected behavior was that the orders of the enabled blocks is not the same as in the "untouched" toolchain file. For example, the user toolchain inclusion came after the find_path block for me |
Thanks for the feedback @rollebolle The feature is intended to respect the order defined by users in |
Sorry - you are right. I accidentally changed the order |
Sorry for opening a discussion here again - and please say if I should move it somewhere else as this issue is resolved. So in short I was a bit fast to celebrate. There are certain cases where the approach even with enable_block is not enough. Consider the following example scenario. We have a cross-compilation SDK. In this SDK we have We add our custom
This means, when looking for packages, the sysroot (our SDK root) will always be prefered. EVEN though the
This does not matter - Conan 2 will always prefer the The reason it worked in Conan 1.X is that the folder where I am not sure how to work around this. FindXXX is kinda deprecated I guess, but the config interface seems to not have considered this scenario. Any feedback is welcome. I have looked through all the CMake variables I can find that controls the find behaviour but cannot find any solution. UPDATE: Editing the generated toolchain from conan so the find_path block also contains the following line seems to fix the issue:
I have no idea what other side effects this could give - but as you do the same thing with |
Thanks @rollebolle. I have troubleshooting this recently (so that we can fix this), and I believe what you are experiencing is the same as "example 3" here: https://github.com/jcar87/conan-crossbuild-with-sysroot?tab=readme-ov-file#example-3-cmake-finds-a-dependency-from-the-sysroot-when-it-should-pick-it-up-from-conan A workaround in this case - is to define
|
Thanks for the reply. In specific cases - yes this could work, when we own the recpie. Consider though when we want to take a package from |
could you print the paths in which CMake is finding the wrong nlohmann-json and fmt? there could variables to define that would work without modifying any recipes |
Sure. We use Yocto (openembedded) and this is the paths in the sysroot it finds:
and similarily for other libs |
Thanks @rollebolle - Perhaps this can be useful: you could add This could be defined in a user toolchain (chain-loaded by the one that Conan generates), or defined as a variable in the |
Maybe, but it kinda breaks my intention. The logic I would want to achieve is the following (and should be pretty common in any cross compilation):
This is an usual usecase for us, as not all packages are managed via Conan. This was how it worked before (even though it may not have been intentional). |
We have been able to work around this issue now, but I think still this is a problem that needs to be solved in some way. To summarize the problem with an example:
|
What is your question?
Updating to conan 2.3.2
I'm building packages via a Yocto based x-compilation toolchain, and the SDK generates this toolchain for us. It is vital to use it as it sets
CMAKE_FIND_ROOT_PATH
among other things, to find packages that are in the SDK and does not come from Conan. Therefore I override the generated toolchain with thetools.cmake.cmaketoolchain:toolchain_file
option.However this poses a problem when we also have
requirements
statements for our Conan requirements. Conan generates the correct<dep>-config.cmake
files for each requirement, but they end up under.../build/Release/generators
. As we are using a custom toolchain, we have no way of knowing this path in beforehand, and therefore we dont know how to set theCMAKE_MODULE_PATH
.If I instead do NOT use the custom toolchain file, but rely on the generated one from Conan with CMakeToolchain, I find the requirement packages as the module path is calculated and added to the toolchain file. But then I get problems for packages in our cross-compilation SDK that we cannot find.
The solution we had in Conan 1.63 was to use the old syntax without toolchain etc, and using
cmake_find_package
. This worked, even with a custom toolchain file, because theFind<dep>.cmake
files ended up in the build folder. Ascmake_find_package
is deprecated, I want to move away from this.What is the best practice here?
Have you read the CONTRIBUTING guide?
The text was updated successfully, but these errors were encountered: