c++ - 带有 cmake-conan 的柯南缺少 conanbuild.conf
问题描述
我想用柯南打包一个 CMake 项目。为此,我使用以下内容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"
CMakeLists.txt
这是我的主文件旁边。CMake 项目的构建没有问题,并且还有一个正确的install
目标,可以正确安装所有内容:bin,lib,include,share
. 在 CMake 中,我使用conan-cmake模块,基本上是这样的。
当我跑
conan create -s build_type=Release . demo/testing
我收到以下奇怪的错误:
...
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.
这里有什么问题,我该如何解决?我找不到与此相关的任何内容?
解决方案
我遇到了同样的问题,最后发现了问题:
你CMake
正在导入的是一个正在使用的CMakeToolchain
,它们都是conan.tools.cmake
模块的一部分。cmake_find_package
[ref]的用法中描述的那个是conans
模块中的那个
所以更换:
from conans import ConanFile, tools
from conan.tools.cmake import CMake, CMakeToolchain
经过
from conans import ConanFile, tools, CMake
from conan.tools.cmake import CMakeToolchain
应该解决你的问题
推荐阅读
- git - 在变基出错后删除其他人在我的分支上的提交
- .net - 将 Ninject 与 Azure 移动应用后端一起使用
- jquery - 全容器视频丢弃响应式代码
- amazon-web-services - [亚马逊](500150) 错误设置/关闭连接:连接超时
- python - 尝试发送电子邮件附件时出错
- javascript - 处理对象数组时如何构造 GraphQL 突变
- python - 为什么 python 在 for 循环中击败 c++?
- java - 字节数组到带流的 int 数组
- arrays - 将浮点列表转换为字节数组并返回 Python
- nginx - 如何防止NGINX代理转发给自己