conan - 打包构建环境为profile的build_requires,使用系统编译器代替
问题描述
我将首先尝试描述我的设置:
- 柯南 1.29.2
- 官方
cmake/3.18.2
包 - 包含其 bin 目录并设置和env 变量的自定义
gcc
包:package_info
PATH
CC
CXX
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 位发布环境的柯南配置文件如下: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]
在我看来是正确的...
然后柯南开始cmake
为 gcc 10.1 x86_64 配置构建包:
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 年前。
解决方案
柯南在一些版本之前了解了主机和构建上下文,并且能够为这些上下文管理不同的配置。这比旧的更受欢迎,os_build
并且arch_build
ConanCenter 中的设置和软件包正在朝着这个新功能发展。
在您的场景中,您正在尝试构建一个library
使用包gcc
并cmake
作为构建要求。您正在为主library
机构建并使用包并提供应在构建机器中运行的工具。即使您没有进行交叉编译,我们也可以同意原生构建只是一个特定的用例,其中主机和构建是同一台机器,因此它们使用相同的柯南配置。gcc
cmake
回到你的例子。您需要主机平台的配置文件,即您要为其生成的配置文件library
。这些是您在问题中列出的所有配置文件。但是您还需要构建上下文的配置文件,柯南将使用该配置文件来构建(或检索)gcc
和cmake
包。例如,您可能希望使用配置文件在调试模式下linux-x86_64-Debug
编译您的文件,同时在 Release 中使用和。library
gcc
cmake
通常,构建上下文的配置文件可以是柯南检测到的默认配置文件。
试试这个命令而不是你的(注意--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
并且它的所有依赖项都将分配给主机上下文,并将使用来自所有--profile:host
配置文件的信息:您的 Debug 构建和 Conan 将添加cmake
和gcc
作为构建要求。gcc
和cmake
,因为它们是此命令中的构建要求,将被分配给构建上下文并使用来自--profile:build
. 如果柯南需要构建这些包,它将使用该配置文件中的设置,而不是主机配置文件的设置。
使用此设置,您可以在一次运行中构建交叉构建场景中的所有包:主机上下文中的包将使用您的 build-requiresgcc
进行构建,而构建上下文中的包将使用--profile:build
.
是的,在这种情况下,构建上下文中的包将使用系统中的编译器......除非您[build_requires]
在--profile:build
.
推荐阅读
- laravel - Apache 的多租户虚拟主机设置
- javascript - REST/JSON——响应的字段由浏览器静默递增?
- r - 标记基于参数的记录第一次出现在 r 数据框中
- django - Django网站中的语音集成
- python - 如何使用 python 从谷歌驱动器访问本地文件?
- r - 由于 curl 编译失败,无法在 Fedora 27 的 R v3.4.3 中安装 devtools
- javascript - 使用 Node 处理一个表单的多个提交版本
- azure - 如何让 CosmosDB 模拟器在机器启动/重启时自动启动
- android - 将复选框标题和状态存储为 JSON
- devops - 使用 NOLIO 运行 sql 脚本的最佳方式是什么?