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

[question] How do you use conan.tools.cmake.CMake with conanbuildinfo.cmake? #2359

Closed
jkleve opened this issue Jan 14, 2022 · 4 comments
Closed

Comments

@jkleve
Copy link

jkleve commented Jan 14, 2022

I set up my cmake project to include conanbuildinfo.cmake and do the basic setup. There's a lot of useful stuff in there so I'd like to keep using it. I switched from conans.CMake to conan.tools.cmake.CMake and now when I try to create the package I get:

ERROR: my-example/0.1: Error in build() method, line 90
        cmake = CMake(self)
        ConanException: Usage of toolchain is only supported with 'cmake_find_package' or 'cmake_find_package_multi' generators

So my question is why is the cmake generator forbidden with conan.tools.cmake.CMake?

See cmake.py:13

def _validate_recipe(conanfile):
    forbidden_generators = ["cmake", "cmake_multi"]
    if any(it in conanfile.generators for it in forbidden_generators):
        raise ConanException("Usage of toolchain is only supported with 'cmake_find_package'"
                             " or 'cmake_find_package_multi' generators")
@memsharded
Copy link
Member

Hi @jkleve

They are completely different integrations. The conan.tools.cmake import CMake works together with CMakeDeps and CMakeToolchain, and implements a fully transparent integration that does not use a conanbuildinfo.cmake file at all. The new CMake for example assumes that CMakeToolchain created the conan_toolchain.cmake file (or at least a file telling the toolchain). The new conan.tools.cmake is intended to fully replace the legacy integrations, and it is the only one that will remain in 2.0, all the others have already been removed.

@jkleve
Copy link
Author

jkleve commented Jan 14, 2022

That was my incline. I think I've read quite a bit of the documentation and this wasn't clear to me. We should mark the old CMake build helper as going away in 2.0 and/or mention this is not to be used with the newer CMake method. The second point is covered by the ConanException but I don't believe the documentation covers it.

@memsharded memsharded transferred this issue from conan-io/conan Jan 14, 2022
@memsharded
Copy link
Member

Moving this to the "docs" repo.

We should mark the old CMake build helper as going away in 2.0 and/or mention this is not to be used with the newer CMake method

This is not easy to do in production code, because that is the declared "stable" integration, so we cannot pollute it with warnings or anything, because users will complain. So it needs to be a docs thing (which is also in a bad place at the moment, we know, because it is not easy to swap the old by new without breaking somethings, because for example all recipes in ConanCenter still uses the old integrations)

@jkleve
Copy link
Author

jkleve commented Jan 21, 2022

We can go ahead and close this if you'd like. It's documented in code.

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

No branches or pull requests

2 participants