告诉conan使用我安装的cmake而不是从头开始编译

问题描述 投票:0回答:1

对于我的项目,我使用 conan 版本 2.5.0,我也在 NixOS 上工作。设置完所有内容并尝试安装项目的依赖项后,我发现 conan 可以编译并尝试使用 CMake 作为一个依赖项:

➜ conan install conanfile.txt --build=missing
======== Installing packages ========

-------- Downloading 14 packages --------
cmake/3.30.5: Retrieving package 63fead0844576fc02943e16909f08fcdddd6f44b from remote 'conancenter'
cmake/3.30.5: Downloading 44.0MB conan_package.tgz
cmake/3.30.5: Decompressing 44.0MB conan_package.tgz
cmake/3.30.5: Package installed 63fead0844576fc02943e16909f08fcdddd6f44b
cmake/3.30.5: Downloaded package revision e7bca794d221e787672baaed17ddbc3f

# ...

cmake/3.30.5: Appending PATH environment variable: /home/jorge/.conan2/p/cmake472b88369c9bf/p/bin
cmake/3.30.5: Appending PATH environment variable: /home/jorge/.conan2/p/cmake472b88369c9bf/p/bin

# ...

-------- Installing package joltphysics/3.0.1 (21 of 32) --------
joltphysics/3.0.1: Building from source
joltphysics/3.0.1: Package joltphysics/3.0.1:3f7fd406790cc7bc8b3903b7793684e958c409a3
joltphysics/3.0.1: Copying sources to build folder
joltphysics/3.0.1: Building your package in /home/jorge/.conan2/p/b/joltpc788376fa4e1a/b
joltphysics/3.0.1: Calling generate()
joltphysics/3.0.1: Generators folder: /home/jorge/.conan2/p/b/joltpc788376fa4e1a/b/build/Release/generators
joltphysics/3.0.1: CMakeToolchain generated: conan_toolchain.cmake
joltphysics/3.0.1: CMakeToolchain generated: /home/jorge/.conan2/p/b/joltpc788376fa4e1a/b/build/Release/generators/CMakePresets.json
joltphysics/3.0.1: Generating aggregated env files
joltphysics/3.0.1: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
joltphysics/3.0.1: Calling build()
joltphysics/3.0.1: Apply patch (conan): Fix CMakeLists: no warnings as errors, allow shared, add install target, and add profile & debug_renderer options
joltphysics/3.0.1: Running CMake.configure()
joltphysics/3.0.1: RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/home/jorge/.conan2/p/b/joltpc788376fa4e1a/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/home/jorge/.conan2/p/b/joltpc788376fa4e1a/b/src/Build"
Could not start dynamically linked executable: cmake
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld

joltphysics/3.0.1: ERROR:
Package '3f7fd406790cc7bc8b3903b7793684e958c409a3' build failed
joltphysics/3.0.1: WARN: Build folder /home/jorge/.conan2/p/b/joltpc788376fa4e1a/b/build/Release
ERROR: joltphysics/3.0.1: Error in build() method, line 141
    cmake.configure(build_script_folder=os.path.join(self.source_folder, "Build"))
    ConanException: Error 127 while executing

这是 NixOS 上的一大禁忌。

如何防止柯南这样做?我安装了 CMake 3.29.2。

这是我当前的柯南简介:

➜  conan profile show
Host profile:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=13
os=Linux

Build profile:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=13
os=Linux

这是我项目的

conanfile.txt

[requires]
eastl/3.21.12
joltphysics/3.0.1
diligent-core/api.252009

[generators]
CMakeDeps
cmake conan nixos
1个回答
0
投票

Conan 2.x 对定制有很大的支持,包括您使用的 CMake。如果您不配置它,柯南将使用您系统中安装的默认配置。为了自定义您的 cmake 可执行文件,您必须将配置添加到您的配置文件中,或传递到您的命令行:

# default profile
...
[conf]
tools.cmake:cmake_program=/custom/path/to/cmake_executable
conan install conanfile.txt -c:a tools.cmake:cmake_program=/custom/path/to/cmake_executable

您只需要其中之一,而不是两者都需要。我建议添加到您的个人资料中,这样您就不需要每次运行命令时都进行配置。

您可以查看文档中支持的配置的完整列表:

https://docs.conan.io/2/reference/config_files/global_conf.html

或者,只需运行

conan config list
,您的终端上就会有相同的列表。


我建议将 CMakeToolchain 添加到您的 conanfile.txt 中,这样 Conan 将生成一个 CMake 工具链文件,将您的配置文件与 CMake 配置相匹配。例如,CMake 默认使用 Debug 作为构建类型,但 Conan 使用 Release,这种不匹配可能会导致配置错误和构建错误。你看一下官方教程为例,如何使用柯南生成的工具链文件

© www.soinside.com 2019 - 2024. All rights reserved.