The pass parameter for cmake for a future cross-compilation option (CROSS_COMPILE)

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++)

here is what i am doing now for cross compiling. I want to add an option to run it like this:

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

and if I do not make the CROSS_COMPILE path to do (not for cmake), it should use the system defaults, so cmake should skip this option in the makefile. How can i do this?

+5
source share
2 answers

Buildroot creates a CMake toolkit for you. Depending on your String, it can be directly in the directory outputor in output/host/usr/share/buildroot. The file has a name toolchainfile.cmake. Then, to create your CMake applications, follow these steps:

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

-, pkg-config, ..

+7

:

SET(CMAKE_C_COMPILER   $(CROSS_COMPILE)gcc)
SET(CMAKE_CXX_COMPILER $(CROSS_COMPILE)g++)

CROSS_COMPILE , -.

, . CROSS_COMPILE CMake, -. , CMake.

:

IF(UNIX)
    SET(CMAKE_C_COMPILER   ${CROSS_COMPILE}gcc)
    SET(CMAKE_CXX_COMPILER ${CROSS_COMPILE}g++)

:

cmake -G "Unix Makefiles" -DCROSS_COMPILE=~/projects/buildroot/output/host/usr/bin/arm-linux-

CMake CROSS_COMPILE .

+2

All Articles