【问题标题】:Conan with cmake-conan missing conanbuild.conf带有 cmake-conan 的柯南缺少 conanbuild.conf
【发布时间】:2021-09-06 13:29:15
【问题描述】:

我想用柯南打包一个 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 模块,基本上是 like this

当我跑步时

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.

这里有什么问题,我该如何解决?我找不到与此相关的任何内容?

【问题讨论】:

标签: c++ cmake conan


【解决方案1】:
from conans import ConanFile, CMake
...

def build(self):
    cmake = CMake(self)
    cmake.configure()
    cmake.build()
...

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,终于找到了问题:
    您正在导入的CMake 是与CMakeToolchain 一起工作的conan.tools.cmake 模块,它们都是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
    

    应该解决你的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      • 2023-03-11
      • 1970-01-01
      • 2021-11-14
      • 2021-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多