0

I am using Conan version 1.27.1 and trying to generate a toolchain from the existing setting in options in my profile file. The following example, which is provided in the Conan document (https://docs.conan.io/en/latest/creating_packages/toolchains/cmake.html), fails with an error. It seems the method write_toolchain_file() does not exist. I tried write_toolchain(), which works, but it does not generate a toolchain cmake file.

I will greatly appreciate any help on this; so that I can generate a toolchain cmake file from my existing conan profile.

Code:

from conans import ConanFile, CMake, CMakeToolchain

class App(ConanFile):
    settings = "os", "arch", "compiler", "build_type"
    requires = "hello/0.1"
    generators = "cmake_find_package_multi"
    options = {"shared": [True, False], "fPIC": [True, False]}
    default_options = {"shared": False, "fPIC": True}

    def toolchain(self):
        tc = CMakeToolchain(self)
        tc.write_toolchain_files()

Error on running above code:

ERROR: conanfile.py: Error in toolchain() method, line 18
        tc.write_toolchain_file()
        AttributeError: 'CMakeToolchain' object has no attribute 'write_toolchain_files'
user982042
  • 329
  • 3
  • 7

1 Answers1

0

The documentation you are reading is latest, that correspond to Conan 1.28 docs.

If you are using an older Conan version, make sure to select the corresponding documentation version, in your case Conan 1.27 docs

As can be seen, there was a change in the toolchain interface from Conan 1.27 to Conan 1.28. This is a breaking change, but it is allowed as this feature is very new (introduced in Conan 1.26) and marked as experimental.

The reason this change was introduced was to allow any user to create their own files directly in the toolchain() method, without requiring to return an object with the delegated responsibility of creating the necessary files.

drodri
  • 5,157
  • 15
  • 21