makefile - 将选项传递给 cmake 以供将来交叉编译的选项 (CROSS_COMPILE)

标签 makefile cmake cross-compiling cmakelists-options

IF(UNIX)
    # CROSS COMPILATION! ON/OFF
    #SET(CMAKE_C_COMPILER   /home/username/projects/buildroot/output/host/usr/bin/arm-linux-gcc)
    #SET(CMAKE_CXX_COMPILER /home/username/projects/buildroot/output/host/usr/bin/arm-linux-g++)
    #SET(CMAKE_C_COMPILER   /home/username/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-eabi-gcc)
    #SET(CMAKE_CXX_COMPILER /home/username/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-eabi-g++)

这就是我现在所做的交叉编译。我想添加选项来运行它:

make CROSS_COMPILE=~/projects/buildroot/output/host/usr/bin/arm-linux-

如果我不将 CROSS_COMPILE 路径设置为 make(而不是 cmake),则它必须使用系统默认值,因此 cmake 必须将此选项路径设置为 makefile。我怎样才能做到呢?

最佳答案

Buildroot 为您生成一个 CMake 工具链文件。根据您的 Buildroot,它可能直接位于 output 目录中,或位于 output/host/usr/share/buildroot 中。该文件名为 toolchainfile.cmake。然后要构建您的 CMake 应用程序,请执行以下操作:

cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/buildroot/output/host/usr/share/buildroot/toolchainfile.cmake

该文件包含交叉编译器路径、pkg-config 环境变量、头文件和库位置等的所有定义。

关于makefile - 将选项传递给 cmake 以供将来交叉编译的选项 (CROSS_COMPILE),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10549924/

相关文章:

cmake - 如何使用 CMake 为某个目标创建 C#define?

c++ - CMake target_link_options LINKER 语法

rust 在 x86_64 机器上编译 x86 库

windows - 无法使用 Windows 的 OpenSSL 支持交叉编译 cURL

android - 使用 Android 独立工具链为 ARM 构建 SDL

linux - 如何定制运行Linux/C程序?

c - 在 Windows 操作系统中使用 C 运行 GTK 库的任何方式?

c++ - CMake 对 main 的 undefined reference

makefile,多个输入的规则

c++ - make中隐含规则的问题