将选项传递给cmake以便将来选择交叉编译(CROSS_COMPILE)

cnd*_*cnd 4 makefile cmake cross-compiling

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++)
Run Code Online (Sandbox Code Playgroud)

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

make CROSS_COMPILE=~/projects/buildroot/output/host/usr/bin/arm-linux-
Run Code Online (Sandbox Code Playgroud)

如果我没有路径CROSS_COMPILE来制作(而不是cmake)它必须使用系统默认值,所以cmake必须将此选项路径为makefile.我该怎么做?

Tho*_*oni 9

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环境变量,标头和库位置等的所有定义.