Browse Source

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>
sbg
Nicolae Rosia 8 years ago committed by Lorenz Meier
parent
commit
a6acb2e68e
  1. 4
      Tools/adb_upload_to_bebop.sh
  2. 5
      cmake/configs/posix_bebop_default.cmake
  3. 12
      cmake/configs/posix_rpi_cross.cmake
  4. 42
      cmake/posix/px4_impl_posix.cmake
  5. 65
      cmake/toolchains/Toolchain-arm-linux-gnueabihf-clang.cmake
  6. 79
      cmake/toolchains/Toolchain-arm-linux-gnueabihf.cmake
  7. 10
      src/firmware/posix/CMakeLists.txt

4
Tools/adb_upload_to_bebop.sh

@ -42,10 +42,6 @@ if [[ $adb_return == "" ]]; then @@ -42,10 +42,6 @@ if [[ $adb_return == "" ]]; then
restart_px4=true
fi
${PX4_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-strip \
-R .comment -R .gnu.version \
../build_posix_bebop_default/src/firmware/posix/px4
../Tools/adb_upload.sh $@
# restart the process after uploading

5
cmake/configs/posix_bebop_default.cmake

@ -8,11 +8,6 @@ add_definitions( @@ -8,11 +8,6 @@ add_definitions(
-D__DF_BEBOP # Define needed DriverFramework
)
set(CMAKE_PROGRAM_PATH
"${PX4_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf/bin"
${CMAKE_PROGRAM_PATH}
)
set(config_module_list
# examples/px4_simple_app

12
cmake/configs/posix_rpi_cross.cmake

@ -1,13 +1,3 @@ @@ -1,13 +1,3 @@
include(configs/posix_rpi_common)
if("$ENV{RPI_USE_CLANG}" STREQUAL "1")
set(CMAKE_TOOLCHAIN_FILE ${PX4_SOURCE_DIR}/cmake/toolchains/Toolchain-arm-linux-gnueabihf-clang.cmake)
else()
set(CMAKE_TOOLCHAIN_FILE ${PX4_SOURCE_DIR}/cmake/toolchains/Toolchain-arm-linux-gnueabihf.cmake)
endif()
set(CMAKE_PROGRAM_PATH
"${PX4_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf/bin"
${CMAKE_PROGRAM_PATH}
)
SET(CMAKE_TOOLCHAIN_FILE ${PX4_SOURCE_DIR}/cmake/toolchains/Toolchain-arm-linux-gnueabihf.cmake)

42
cmake/posix/px4_impl_posix.cmake

@ -267,22 +267,36 @@ elseif ("${BOARD}" STREQUAL "excelsior") @@ -267,22 +267,36 @@ elseif ("${BOARD}" STREQUAL "excelsior")
--sysroot=${HEXAGON_ARM_SYSROOT}/lib32-apq8096 -mfloat-abi=softfp -mfpu=neon -mthumb-interwork
)
elseif ("${BOARD}" STREQUAL "rpi" AND "$ENV{RPI_USE_CLANG}" STREQUAL "1")
elseif ("${BOARD}" STREQUAL "rpi")
SET(RPI_COMPILE_FLAGS
-mcpu=cortex-a53
-mfpu=neon
-mfloat-abi=hard
)
LIST(APPEND added_c_flags ${RPI_COMPILE_FLAGS})
LIST(APPEND added_cxx_flags ${RPI_COMPILE_FLAGS})
# Add the toolchain specific flags
set(clang_added_flags
-m32
--target=arm-linux-gnueabihf
-ccc-gcc-name arm-linux-gnueabihf
--sysroot=${PX4_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf/arm-linux-gnueabihf/libc/)
set(added_c_flags ${POSIX_CMAKE_C_FLAGS} ${clang_added_flags})
list(APPEND added_cxx_flags ${POSIX_CMAKE_CXX_FLAGS} ${clang_added_flags})
list(APPEND added_exe_linker_flags ${POSIX_CMAKE_EXE_LINKER_FLAGS} ${clang_added_flags})
FIND_PROGRAM(CXX_COMPILER_PATH ${CMAKE_CXX_COMPILER})
GET_FILENAME_COMPONENT(CXX_COMPILER_PATH ${CXX_COMPILER_PATH} DIRECTORY)
GET_FILENAME_COMPONENT(CXX_COMPILER_PATH "${CXX_COMPILER_PATH}/../" ABSOLUTE)
IF ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
set(CLANG_COMPILE_FLAGS
--target=arm-pc-linux-gnueabihf
-ccc-gcc-name arm-linux-gnueabihf-gcc
--sysroot=${CXX_COMPILER_PATH}/arm-linux-gnueabihf/libc
-I${CXX_COMPILER_PATH}/arm-linux-gnueabihf/libc/usr/include/
)
set(added_c_flags ${POSIX_CMAKE_C_FLAGS} ${CLANG_COMPILE_FLAGS})
list(APPEND added_cxx_flags ${POSIX_CMAKE_CXX_FLAGS} ${CLANG_COMPILE_FLAGS})
list(APPEND added_exe_linker_flags ${POSIX_CMAKE_EXE_LINKER_FLAGS} ${CLANG_COMPILE_FLAGS}
-B${CXX_COMPILER_PATH}/arm-linux-gnueabihf/libc/usr/lib
-L${CXX_COMPILER_PATH}/arm-linux-gnueabihf/libc/usr/lib
)
ENDIF()
else()
# Add the toolchain specific flags
set(added_cflags ${POSIX_CMAKE_C_FLAGS})
list(APPEND added_cxx_flags ${POSIX_CMAKE_CXX_FLAGS})
endif()
# output

65
cmake/toolchains/Toolchain-arm-linux-gnueabihf-clang.cmake

@ -1,65 +0,0 @@ @@ -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)

79
cmake/toolchains/Toolchain-arm-linux-gnueabihf.cmake

@ -1,65 +1,13 @@ @@ -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) @@ -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})
# where is the target environment
set(CMAKE_FIND_ROOT_PATH get_file_component(${C_COMPILER} PATH))
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-gc-sections")
#set(CMAKE_C_FLAGS ${C_FLAGS})
#set(CMAKE_CXX_LINKER_FLAGS ${C_FLAGS})
# 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)

10
src/firmware/posix/CMakeLists.txt

@ -140,4 +140,14 @@ install(TARGETS px4 DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -140,4 +140,14 @@ install(TARGETS px4 DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/ROMFS DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/posix-configs DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
FIND_PROGRAM(STRIP_TOOL "arm-linux-gnueabihf-strip")
add_custom_target(strip
DEPENDS px4.stripped
)
add_custom_command(OUTPUT px4.stripped
COMMAND arm-linux-gnueabihf-strip -R .comment -R .gnu.version $<TARGET_FILE:px4>
DEPENDS px4)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :

Loading…
Cancel
Save