mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
RPi: add clang & clang-check support
This commit is contained in:
parent
ae00abe468
commit
a8d3b15d73
@ -228,6 +228,11 @@ find_package(PythonInterp REQUIRED)
|
||||
#
|
||||
enable_testing()
|
||||
|
||||
#=============================================================================
|
||||
# generate compile command database
|
||||
#
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
#=============================================================================
|
||||
# check required toolchain variables
|
||||
#
|
||||
|
||||
18
Tools/clang-check.sh
Executable file
18
Tools/clang-check.sh
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
COMPILE_DB=$(/bin/pwd)/build_posix_rpi_cross;
|
||||
BIN=${RPI_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf-raspbian/bin
|
||||
|
||||
CXX_INC=$(cd ${RPI_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/include/c++/*; pwd)
|
||||
|
||||
EXTRA_ARG1=-I${CXX_INC}
|
||||
EXTRA_ARG2=-I${CXX_INC}/arm-linux-gnueabihf
|
||||
EXTRA_ARG3=-I${CXX_INC}/backward
|
||||
|
||||
grep file ${COMPILE_DB}/compile_commands.json |
|
||||
awk '{ print $2; }' |
|
||||
sed 's/\"//g' |
|
||||
while read FILE; do
|
||||
(cd $(dirname ${FILE});
|
||||
${BIN}/clang-check -analyze -p ${COMPILE_DB} --extra-arg=${EXTRA_ARG1} --extra-arg=${EXTRA_ARG2} --extra-arg=${EXTRA_ARG3} $(basename ${FILE})
|
||||
);
|
||||
done
|
||||
@ -1,6 +1,11 @@
|
||||
include(configs/posix_rpi_common)
|
||||
|
||||
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchains/Toolchain-arm-linux-gnueabihf-raspbian.cmake)
|
||||
if("$ENV{RPI_USE_CLANG}" STREQUAL "1")
|
||||
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchains/Toolchain-arm-linux-clang-gnueabihf-raspbian.cmake)
|
||||
else()
|
||||
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchains/Toolchain-arm-linux-gnueabihf-raspbian.cmake)
|
||||
endif()
|
||||
|
||||
|
||||
set(CMAKE_PROGRAM_PATH
|
||||
"${RPI_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf-raspbian/bin"
|
||||
|
||||
@ -223,8 +223,19 @@ if ("${BOARD}" STREQUAL "eagle" OR "${BOARD}" STREQUAL "excelsior")
|
||||
-Wl,-rpath-link,${HEXAGON_ARM_SYSROOT}/lib/arm-linux-gnueabihf
|
||||
--sysroot=${HEXAGON_ARM_SYSROOT}
|
||||
)
|
||||
else()
|
||||
elseif ("${BOARD}" STREQUAL "rpi" AND "$ENV{RPI_USE_CLANG}" STREQUAL "1")
|
||||
|
||||
# Add the toolchain specific flags
|
||||
set(clang_added_flags
|
||||
-m32
|
||||
--target=arm-linux-gnueabihf
|
||||
-ccc-gcc-name arm-linux-gnueabihf
|
||||
--sysroot=${RPI_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/libc/)
|
||||
|
||||
set(added_c_flags ${POSIX_CMAKE_C_FLAGS} ${clang_added_flags})
|
||||
set(added_cxx_flags ${POSIX_CMAKE_CXX_FLAGS} ${clang_added_flags})
|
||||
set(added_exe_linker_flags ${POSIX_CMAKE_EXE_LINKER_FLAGS} ${clang_added_flags})
|
||||
else()
|
||||
# Add the toolchain specific flags
|
||||
set(added_cflags ${POSIX_CMAKE_C_FLAGS})
|
||||
set(added_cxx_flags ${POSIX_CMAKE_CXX_FLAGS})
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
include(CMakeForceCompiler)
|
||||
|
||||
if ($ENV{RPI_TOOLCHAIN_DIR} STREQUAL "")
|
||||
message(FATAL_ERROR "RPI_TOOLCHAIN_DIR not set")
|
||||
else()
|
||||
set(RPI_TOOLCHAIN_DIR $ENV{RPI_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 ${RPI_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf-raspbian/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 ${RPI_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf-raspbian/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 ${RPI_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf-raspbian/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()
|
||||
|
||||
add_definitions(
|
||||
-D __RPI
|
||||
)
|
||||
|
||||
# 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)
|
||||
Loading…
x
Reference in New Issue
Block a user