打包的构建环境作为配置文件的build_requires,而是使用系统编译器

问题描述

我将尝试首先描述我的设置:

  • 柯南1.29.2
  • cmake/3.18.2官方软件包
  • 具有 gcc自定义package_info软件包,包括其在PATH中的bin目录,并设置CCCXX env变量
    def package(self):
        autotools = AutoToolsBuildEnvironment(self)
        autotools.make(target='install-strip')
    
    def package_info(self):
        bin_folder = os.path.join(self.package_folder,'bin')
    
        self.env_info.path.append(bin_folder)
        self.env_info.CXX = os.path.join(bin_folder,'g++')
        self.env_info.CC = os.path.join(bin_folder,'gcc')
    
  • linux-x86_64代表Linux 64位环境的柯南配置文件,如下所示:
    [settings]
    os=Linux
    os_build=Linux
    arch=x86_64
    arch_build=x86_64
    
  • linux-x86_64-Debug代表Linux 64位Release环境的柯南配置文件,如下所示:
    include(linux-x86_64)
    
    [settings]
    build_type=Debug
    
  • gcc-10.1.0柯南配置文件使用我的gcc软件包构建软件包:
    [settings]
    compiler=gcc
    compiler.version=10.1
    compiler.libcxx=libstdc++11
    
    [build_requires]
    gcc/10.1.0
    
  • cmake-3.18.2柯南配置文件以使用官方cmake软件包构建软件包:
    [build_requires]
    cmake/3.18.2
    
  • default与gcc 7的柯南简介

如果我尝试按以下方式构建软件包:

$ conan create . foo/version --build=missing -pr linux-x86_64-Debug -pr cmake-3.18.2 -pr gcc-10.1.0

结果配置为:

Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=10.1
os=Linux
os_build=Linux
[options]
[build_requires]
*: gcc/10.1.0,cmake/3.18.2
[env]

对我来说合适...

然后柯南开始为gcc 10.1 x86_64配置构建cmake软件包:

cmake/3.18.2: WARN: Build folder is dirty,removing it: /home/manuel/.conan/data/cmake/3.18.2/_/_/build/46c0026dddc0e0537a797652343e8e1e9d0e39e7
cmake/3.18.2: copying sources to build folder
cmake/3.18.2: Building your package in /home/manuel/.conan/data/cmake/3.18.2/_/_/build/46c0026dddc0e0537a797652343e8e1e9d0e39e7
cmake/3.18.2: Generator cmake created conanbuildinfo.cmake
cmake/3.18.2: Calling build()

但是随后构建失败,因为cmake软件包cmake config 正在使用系统编译器

-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: called by CMake conan helper
-- Conan: called inside local cache
-- Conan: Adjusting output directories
-- Conan: Using cmake global configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Conan: Compiler GCC>=5,checking major version 10.1
-- Conan: Checking correct version: 7.4
CMake Error at ../conanbuildinfo.cmake:510 (message):
  Detected a mismatch for the compiler version between your conan profile
  settings and CMake:

  Compiler version specified in your conan profile: 10.1

  Compiler version detected in CMake: 7.4

  Please check your conan profile settings (conan profile show
  [default|your_profile_name])

  P.S.  You may set CONAN_disABLE_CHECK_COMPILER CMake variable in order to
  disable this check.
Call Stack (most recent call first):
  ../conanbuildinfo.cmake:592 (conan_error_compiler_version)
  ../conanbuildinfo.cmake:695 (check_compiler_version)
  ../conanbuildinfo.cmake:249 (conan_check_compiler)
  CMakeLists.txt:9 (conan_basic_setup)

这看起来与https://github.com/conan-io/conan/issues/1842非常相似,但是该问题来自3年前。

解决方法

柯南之前了解了一些有关 host build 上下文的版本,并且能够管理这些上下文的不同配置。相对于旧的os_buildarch_build设置,这是更可取的,而ConanCenter中的软件包正朝着这项新功能迈进。

在您的方案中,您尝试根据构建要求使用软件包librarygcc来构建cmake。您正在为 host 计算机构建library,并使用软件包gcccmake来提供应在 build 计算机中运行的工具。即使您不是交叉编译,我们也可以同意本机构建只是一个特定的用例,其中 host build 是同一台机器,因此它们使用相同的柯南配置。

回到您的示例。您需要用于 host 平台的配置文件,即您要为其生成library的配置文件。这些是您在问题中列出的所有个人资料。但是,您还需要 build 上下文的配置文件,Conan将使用该配置文件来构建(或检索)gcccmake软件包。例如,您可能希望使用配置文件linux-x86_64-Debug在调试模式下编译library,而在Release中使用gcccmake

通常, build 上下文的配置文件可以是柯南检测到的默认配置文件。

尝试使用此命令代替您的命令(请注意--profile:build=default):

conan create <library/conanfile.py> foo/version --build=missing --profile:host linux-x86_64-Debug --profile:host cmake-3.18.2 --profile:host gcc-10.1.0 --profile:build=default 

现在,柯南将使用新功能并将软件包分配给相应的上下文:

  • library及其所有依赖项将分配给 host 上下文,并将使用所有--profile:host配置文件中的信息:您的Debug版本和Conan将添加{{1 }}和cmake作为构建要求。
  • gccgcc(在此命令中是构建必需的)将被分配到 build 上下文,并将使用来自{{1}的信息}。如果柯南需要构建这些软件包,它将使用该配置文件中的设置,而不是 host 配置文件中的设置。

通过此设置,您可以一次运行即可在交叉构建场景中构建所有软件包 host 上下文中的软件包将使用您的构建要求{{1 }}进行构建,而 build 上下文中的软件包将使用cmake中定义的工具。

是的,在这种情况下,除非您在--profile:build中声明gcc,否则 build 上下文中的软件包将使用系统中的编译器。 >