mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
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:
parent
8f9ca9b45e
commit
a6acb2e68e
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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/)
|
||||
FIND_PROGRAM(CXX_COMPILER_PATH ${CMAKE_CXX_COMPILER})
|
||||
|
||||
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})
|
||||
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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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…
x
Reference in New Issue
Block a user