Conan: Error when calling CMake(self) in method package

Created on 14 Oct 2019  路  3Comments  路  Source: conan-io/conan

On version 1.19.1 of conan, when using the following example (from https://docs.conan.io/en/latest/howtos/cmake_install.html)

def _configure_cmake(self):
    cmake = CMake(self)
    cmake.definitions["SOME_DEFINITION"] = True
    cmake.configure()
    return cmake

def build(self):
    cmake = self._configure_cmake()
    cmake.build()

def package(self):
    cmake = self._configure_cmake()
    cmake.install()

def package_info(self):
    self.cpp_info.libs = ["libname"]

I have an error when trying to build.

Error in package() method, line 69
        cmake = CMake(self)
        AttributeError: 'NoneType' object has no attribute 'replace'

A user (tomskside) from the conan slack suggested it may come from install_folder = self._conanfile.install_folder.replace("\\", "/") which is not available.

Note: The error is non-blocking.

  • [x] I've read the CONTRIBUTING guide.
  • [x] I've specified the Conan version, operating system version and any tool that can be relevant.
  • [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.
low low queue bug

All 3 comments

I cannot reproduce the issue. Could you provide more verbose output/recipe or even better a zip with something I can reproduce?

Hello, here's a zip with an example.
It contains the conanfile.py, the conanfile.txt and the profile file.
You can build it via the build_fmt.sh
example_fmt.zip

It is kind of a bug but the usage of the example is a bit weird. You can reproduce the issue only with the conanfile.py doing conan export-pkg . fmt/5.3.0@test/stable -f.
If you run first a conan install . it will generate the conaninfo.txt, graph_info.json etc, then when you run a conan export-pkg it will find a valid install folder. You can also declare one with the -if argument if you want a clean directory.

The fix might be to protect the following usage of the install_folder at the cmake_flags.py checking if the folder is not none first.

``` if "cmake_find_package" in self._conanfile.generators:
definitions["CMAKE_MODULE_PATH"] = install_folder

    if "cmake_find_package_multi" in self._conanfile.generators:
        # The cmake_find_package_multi only works with targets and generates XXXConfig.cmake
        # that require the prefix path and the module path
        definitions["CMAKE_PREFIX_PATH"] = install_folder
        definitions["CMAKE_MODULE_PATH"] = install_folder

```

Was this page helpful?
0 / 5 - 0 ratings