ARM Toolchain: search compiler in PATH

Add CMake target for strip since these changes break adb_upload_to_bebop.

GCC users should add the cross compiler bin path to PATH (location of arm-linux-gnueabihf-g++).
Clang user should do the following:
* set CMAKE_CXX_COMPILER to clang++ by providing -DCMAKE_CXX_COMPILER=clang++ to cmake
* get GCC cross compiler - needed because Clang does not ship a CRT
* create a symlink for clang and clang++ in GCC cross compiler bin dir.
* add GCC bin dir to PATH

Signed-off-by: Nicolae Rosia <nicolae.rosia@gmail.com>
This commit is contained in:
Nicolae Rosia
2017-06-13 08:16:37 +02:00
committed by Lorenz Meier
parent 8f9ca9b45e
commit a6acb2e68e
7 changed files with 49 additions and 166 deletions
@@ -1,65 +0,0 @@
include(CMakeForceCompiler)
if ($ENV{PX4_TOOLCHAIN_DIR} STREQUAL "")
message(FATAL_ERROR "PX4_TOOLCHAIN_DIR not set")
else()
set(PX4_TOOLCHAIN_DIR $ENV{PX4_TOOLCHAIN_DIR})
endif()
# this one is important
set(CMAKE_SYSTEM_NAME Generic)
#this one not so much
set(CMAKE_SYSTEM_VERSION 1)
# specify the cross compiler
# requires a symbolic link typically from /usr/bin/clang
find_program(C_COMPILER clang
PATHS ${PX4_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf/bin
NO_DEFAULT_PATH
)
if(NOT C_COMPILER)
message(FATAL_ERROR "could not find C compiler")
endif()
cmake_force_c_compiler(${C_COMPILER} Clang)
find_program(CXX_COMPILER clang++
PATHS ${PX4_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf/bin
NO_DEFAULT_PATH
)
if(NOT CXX_COMPILER)
message(FATAL_ERROR "could not find C++ compiler")
endif()
cmake_force_cxx_compiler(${CXX_COMPILER} Clang)
# compiler tools
foreach(tool objcopy nm ld)
string(TOUPPER ${tool} TOOL)
find_program(${TOOL} arm-linux-gnueabihf-${tool}
PATHS ${PX4_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf/bin
NO_DEFAULT_PATH
)
if(NOT ${TOOL})
message(FATAL_ERROR "could not find arm-linux-gnueabihf-${tool}")
endif()
endforeach()
# os tools
foreach(tool echo grep rm mkdir nm cp touch make unzip)
string(TOUPPER ${tool} TOOL)
find_program(${TOOL} ${tool})
if(NOT ${TOOL})
message(FATAL_ERROR "could not find ${TOOL}")
endif()
endforeach()
# where is the target environment
set(CMAKE_FIND_ROOT_PATH get_file_component(${C_COMPILER} PATH))
# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
@@ -1,65 +1,13 @@
# defines:
#
# NM
# OBJCOPY
# LD
# CXX_COMPILER
# C_COMPILER
# CMAKE_SYSTEM_NAME
# CMAKE_SYSTEM_VERSION
# LINKER_FLAGS
# CMAKE_EXE_LINKER_FLAGS
# CMAKE_FIND_ROOT_PATH
# CMAKE_FIND_ROOT_PATH_MODE_PROGRAM
# CMAKE_FIND_ROOT_PATH_MODE_LIBRARY
# CMAKE_FIND_ROOT_PATH_MODE_INCLUDE
# More on cross-compilation: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html
include(CMakeForceCompiler)
if ("$ENV{PX4_TOOLCHAIN_DIR}" STREQUAL "")
message(FATAL_ERROR "PX4_TOOLCHAIN_DIR not set")
else()
set(PX4_TOOLCHAIN_DIR $ENV{PX4_TOOLCHAIN_DIR})
endif()
# this one is important
set(CMAKE_SYSTEM_NAME Generic)
#this one not so much
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSTEM_VERSION 1)
# specify the cross compiler
find_program(C_COMPILER arm-linux-gnueabihf-gcc
PATHS ${PX4_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf/bin
NO_DEFAULT_PATH
)
if(NOT C_COMPILER)
message(FATAL_ERROR "could not find arm-linux-gnueabihf-gcc compiler")
endif()
cmake_force_c_compiler(${C_COMPILER} GNU)
find_program(CXX_COMPILER arm-linux-gnueabihf-g++
PATHS ${PX4_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf/bin
NO_DEFAULT_PATH
)
if(NOT CXX_COMPILER)
message(FATAL_ERROR "could not find arm-linux-gnueabihf-g++ compiler")
endif()
cmake_force_cxx_compiler(${CXX_COMPILER} GNU)
# compiler tools
foreach(tool objcopy nm ld)
string(TOUPPER ${tool} TOOL)
find_program(${TOOL} arm-linux-gnueabihf-${tool}
PATHS ${PX4_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf/bin
NO_DEFAULT_PATH
)
if(NOT ${TOOL})
message(FATAL_ERROR "could not find arm-linux-gnueabihf-${tool}")
endif()
endforeach()
IF (NOT CMAKE_C_COMPILER OR NOT CMAKE_CXX_COMPILER)
SET(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
ENDIF()
# os tools
foreach(tool echo grep rm mkdir nm cp touch make unzip)
@@ -70,16 +18,11 @@ foreach(tool echo grep rm mkdir nm cp touch make unzip)
endif()
endforeach()
set(LINKER_FLAGS "-Wl,-gc-sections")
set(CMAKE_EXE_LINKER_FLAGS ${LINKER_FLAGS})
set(CMAKE_C_FLAGS ${C_FLAGS})
set(CMAKE_CXX_LINKER_FLAGS ${C_FLAGS})
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-gc-sections")
#set(CMAKE_C_FLAGS ${C_FLAGS})
#set(CMAKE_CXX_LINKER_FLAGS ${C_FLAGS})
# where is the target environment
set(CMAKE_FIND_ROOT_PATH get_file_component(${C_COMPILER} PATH))
# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)