'Conan with cmake-conan missing conanbuild.conf
I am want to package a CMake project with conan.
For that I use the following conanfile.py:
import os
from conans import ConanFile, tools
from conan.tools.cmake import CMake, CMakeToolchain
from conans.tools import Version
class BaseLibrary(ConanFile):
name = "base-library"
version = "1.0.0"
description = """This is a test project with a library base::io
and base::math and an executable cli."""
license = "MIT"
generators = "cmake_find_package_multi", "cmake_find_package",
default_options = {"fmt:shared": True}
build_policy = "missing" # if this package is build by default if missing.
settings = "os", "compiler", "build_type", "arch"
exports_sources = "*"
_cmake = None
def requirements(self):
if Version(self.version) >= "1.0.0":
self.requires("fmt/8.0.1")
def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure(source_folder=".")
return self._cmake
def build(self):
cmake = self._configure_cmake()
cmake.build()
cmake.install()
def package(self):
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))
def package_info(self):
self.cpp_info.names["cmake_find_package"] = "base"
self.cpp_info.names["cmake_find_package_multi"] = "base"
self.cpp_info.names["pkg_config"] = "base"
which is next to my main CMakeLists.txt file. The CMake project builds without problems and also has a proper install target which installs everything properly: bin,lib,include,share. In CMake I use the conan-cmake module with basically something like this.
When I run
conan create -s build_type=Release . demo/testing
I get the following weird error:
...
Requirements
base-library/1.0.0@demo/testing from local cache - Cache
fmt/8.0.1 from 'conancenter' - Cache
Packages
base-library/1.0.0@demo/testing:4f2b14d304ab8e4391d162a6eb44110cc27a3faa - Build
fmt/8.0.1:d4e9c4f02b4f03edf5a640dcd22779727d782e79 - Cache
Installing (downloading, building) binaries...
fmt/8.0.1: Already installed!
base-library/1.0.0@demo/testing: WARN: Build folder is dirty, removing it: /home/developer/.conan/data/base-library/1.0.0/demo/testing/build/4f2b14d304ab8e4391d162a6eb44110cc27a3faa
base-library/1.0.0@demo/testing: Configuring sources in /home/developer/.conan/data/base-library/1.0.0/demo/testing/source
base-library/1.0.0@demo/testing: Copying sources to build folder
base-library/1.0.0@demo/testing: Building your package in /home/developer/.conan/data/base-library/1.0.0/demo/testing/build/4f2b14d304ab8e4391d162a6eb44110cc27a3faa
base-library/1.0.0@demo/testing: Generator cmake_find_package created Findfmt.cmake
base-library/1.0.0@demo/testing: Generator cmake_find_package_multi created fmt-config-version.cmake
base-library/1.0.0@demo/testing: Generator cmake_find_package_multi created fmt-config.cmake
base-library/1.0.0@demo/testing: Generator cmake_find_package_multi created fmtTargets.cmake
base-library/1.0.0@demo/testing: Generator cmake_find_package_multi created fmtTarget-release.cmake
base-library/1.0.0@demo/testing: Aggregating env generators
base-library/1.0.0@demo/testing: Calling build()
base-library/1.0.0@demo/testing:
base-library/1.0.0@demo/testing: ERROR: Package '4f2b14d304ab8e4391d162a6eb44110cc27a3faa' build failed
base-library/1.0.0@demo/testing: WARN: Build folder /home/developer/.conan/data/base-library/1.0.0/demo/testing/build/4f2b14d304ab8e4391d162a6eb44110cc27a3faa
ERROR: base-library/1.0.0@demo/testing: Error in build() method, line 74
cmake = self._configure_cmake()
while calling '_configure_cmake', line 65
self._cmake = CMake(self)
ConanException: The file /home/developer/.conan/data/base-library/1.0.0/demo/testing/build/4f2b14d304ab8e4391d162a6eb44110cc27a3faa/conanbuild.conf does not exist. Please, make sure that it was not generated in another folder.
What is the problem here and how can I resolve this? I could not find anything related to this?
Solution 1:[1]
from conans import ConanFile, CMake
...
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
...
Solution 2:[2]
I had the same problem and finally found the issue:
The CMake you are importing is the one working with the CMakeToolchain which are both part of the conan.tools.cmake module.
The one that is described in the usage of cmake_find_package[ref] is the one in conans module
So replacing:
from conans import ConanFile, tools
from conan.tools.cmake import CMake, CMakeToolchain
by
from conans import ConanFile, tools, CMake
from conan.tools.cmake import CMakeToolchain
should fix your problem
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tan Su |
| Solution 2 | Sylvaus |
