【问题标题】:CMake Generator is not passed to Conan when Cross Compiling交叉编译时未将 CMake 生成器传递给柯南
【发布时间】:2021-12-30 05:07:17
【问题描述】:

我正在尝试使用 Conan 和 GCC arm none eabi 和 Ninja Generator 来设置嵌入式 CMake 项目。

我已经设法设置了 Windows (Ninja) 和 Linux (WSL2) 版本。 现在我开始构建嵌入式目标。

从一个 cmake 预设 USE_SPDLOG 设置为“1.8.5”,

现在我的柯南工作流程符合https://github.com/conan-io/cmake-conan 中的建议

include(${CMAKE_BINARY_DIR}/conan.cmake)

 if(USE_SPDLOG)
    set(SPDLOG_PACKAGE "spdlog/${USE_SPDLOG}")
    set(SPDLOG_ADDITIONAL_OPTIONS "spdlog:header_only=True")
  endif()

 conan_cmake_configure(
    REQUIRES
    ${SPDLOG_PACKAGE}
    OPTIONS
    ${SPDLOG_ADDITIONAL_OPTIONS}
    GENERATORS cmake_find_package)

  conan_cmake_autodetect(settings)

 conan_cmake_install(
    PATH_OR_REFERENCE
    .
    BUILD
    missing
    REMOTE
    conan-center
    SETTINGS
    ${OS_SETTING}
    ${OS_VERSION_SETTING}
    ${ARCH_SETTING}
    ${settings})

 list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})

  if(USE_SPDLOG)
    conan_find_package(spdlog)
  endif()

现在 Cmake 可以正确检测到我的交叉编译器(GCC 10.2,arm none eabi)

 [CMake] -- The C compiler identification is GNU 10.2.1
1> [CMake] -- The CXX compiler identification is GNU 10.2.1
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Check for working C compiler: C:/xxxx/toolchains/arm-none-eabi-gcc-10.2.1/bin/arm-none-eabi-gcc.exe - skipped
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- Detecting CXX compiler ABI info
1> [CMake] -- Detecting CXX compiler ABI info - done
1> [CMake] -- Check for working CXX compiler: C:/xxxx/toolchains/arm-none-eabi-gcc-10.2.1/bin/arm-none-eabi-g++.exe - skipped
1> [CMake] -- Detecting CXX compile features
1> [CMake] -- Detecting CXX compile features - done
1> [CMake] -- The ASM compiler identification is GNU
1> [CMake] -- Found assembler: C:/xxxx/toolchains/arm-none-eabi-gcc-10.2.1/bin/arm-none-eabi-gcc.exe

所以在我的项目 gcc + ninja seam 中工作。

不过柯南开头是

[CMake] -- Downloading conan.cmake from https://github.com/conan-io/cmake-conan
1> [CMake] -- Conan: checking conan executable
1> [CMake] -- Conan: Found program C:/Users/xxx/AppData/Local/Programs/Python/Python39/Scripts/conan.exe
1> [CMake] -- Conan: Version found Conan version 1.42.1
1> [CMake] -- Conan executing: C:/Users/xxxx/AppData/Local/Programs/Python/Python39/Scripts/conan.exe install . --remote conan-center --build missing --settings build_type=Debug --settings compiler=gcc --settings compiler.version=10 --settings compiler.libcxx=libstdc++11
1> [CMake] Configuration:
1> [CMake] [settings]
1> [CMake] arch=x86_64
1> [CMake] arch_build=x86_64
1> [CMake] build_type=Debug
1> [CMake] compiler=gcc
1> [CMake] compiler.libcxx=libstdc++11
1> [CMake] compiler.version=10
1> [CMake] os=Windows
1> [CMake] os_build=Windows
1> [CMake] [options]
1> [CMake] [build_requires]
1> [CMake] [env]
1> [CMake] 

=>我相信柯南实际上并没有交叉编译

来自柯南文档 https://docs.conan.io/en/1.6/systems_cross_building/cross_building.html

我尝试添加

os_build=none
arch_build=arm
os=Windows
arch=x86_64
compiler=Visual Studio

到选项

但这会导致

ERROR: Invalid setting 'none
1> [CMake]     arch_build=arm
1> [CMake]     os=Windows
1> [CMake]     arch=x86_64
1> [CMake]     compiler=Visual Studio' is not a valid 'settings.os_build' value.

那么如何让嵌入式交叉编译工作?你有什么想法吗?

【问题讨论】:

  • 根据文档,您似乎把事情搞混了:arch_build 用于构建系统,即系统,arch 用于主机系统(出于某种原因,这里似乎是类似于目标系统;不熟悉柯南,所以没有一些研究我无法区分)。因此,由于您正在为 Linux arm 进行编译,它可能应该是 arch_build=x86_64 os_build=Windows os=Linuxarch=arm 在链接站点中的 Windows 到 Raspberry 及以下部分应列出示例;您可能想要/需要指定一个 arm 版本(ARM 架构参考)...

标签: c++ cmake


【解决方案1】:

如果我得到了正确的文档,如果你想在这个平台上交叉编译,你必须将主机操作系统定义为 windows。

来自文档:

Build platform: The platform on which the compilation tools are executed

【讨论】:

  • 嘿,谢谢,我将设置重新排列为 set(settings #host "os_build=Windows" "arch_build=x86_64" #Target "os=none" "arch_target=arm" "compiler=gcc") 现在我得到了。 “错误:无效设置 'arm' 不是有效的 'settings.arch_target' 值。可能的值为 ['x86', 'x86_64', 'ppc32be', 'ppc32', 'ppc64le', 'ppc64', 'armv5el' ,'armv5hf','armv6','armv7','armv7hf','armv7s','armv7k','armv8','armv8_32','armv8.3','sparc','sparcv9','mips' 、'mips64'、'avr'、's390'、's390x'、'asm.js'、'wasm'、'sh4le'、'e2k-v2'、'e2k-v3'、'e2k-v4'、' e2k-v5']
  • 我猜柯南不支持 arm-none?
猜你喜欢
  • 2021-11-14
  • 2012-05-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多