adds toolchain file
This commit is contained in:
parent
32ff23709f
commit
2c063fe9a4
60
cmake/rv32imc.cmake
Normal file
60
cmake/rv32imc.cmake
Normal file
@ -0,0 +1,60 @@
|
||||
# Look for GCC in path
|
||||
# https://xpack.github.io/riscv-none-embed-gcc/
|
||||
FIND_FILE( RISCV_XPACK_GCC_COMPILER_EXE "riscv-none-embed-gcc.exe" PATHS ENV INCLUDE)
|
||||
FIND_FILE( RISCV_XPACK_GCC_COMPILER "riscv-none-embed-gcc" PATHS ENV INCLUDE)
|
||||
# New versions of xpack
|
||||
FIND_FILE( RISCV_XPACK_NEW_GCC_COMPILER_EXE "riscv-none-elf-gcc.exe" PATHS ENV INCLUDE)
|
||||
FIND_FILE( RISCV_XPACK_NEW_GCC_COMPILER "riscv-none-elf-gcc" PATHS ENV INCLUDE)
|
||||
# Look for RISC-V github GCC
|
||||
# https://github.com/riscv/riscv-gnu-toolchain
|
||||
FIND_FILE( RISCV_XPACK_GCC_COMPILER_EXT "riscv64-unknown-elf-gcc.exe" PATHS ENV INCLUDE)
|
||||
FIND_FILE( RISCV_XPACK_GCC_COMPILER "riscv64-unknown-elf-gcc" PATHS ENV INCLUDE)
|
||||
|
||||
# Select which is found
|
||||
if (EXISTS ${RISCV_XPACK_NEW_GCC_COMPILER})
|
||||
set( RISCV_GCC_COMPILER ${RISCV_XPACK_NEW_GCC_COMPILER})
|
||||
elseif (EXISTS ${RISCV_XPACK_GCC_NEW_COMPILER_EXE})
|
||||
set( RISCV_GCC_COMPILER ${RISCV_XPACK_NEW_GCC_COMPILER_EXE})
|
||||
elseif (EXISTS ${RISCV_XPACK_GCC_COMPILER})
|
||||
set( RISCV_GCC_COMPILER ${RISCV_XPACK_GCC_COMPILER})
|
||||
elseif (EXISTS ${RISCV_XPACK_GCC_COMPILER_EXE})
|
||||
set( RISCV_GCC_COMPILER ${RISCV_XPACK_GCC_COMPILER_EXE})
|
||||
elseif (EXISTS ${RISCV_GITHUB_GCC_COMPILER})
|
||||
set( RISCV_GCC_COMPILER ${RISCV_GITHUB_GCC_COMPILER})
|
||||
elseif (EXISTS ${RISCV_GITHUB_GCC_COMPILER_EXE})
|
||||
set( RISCV_GCC_COMPILER ${RISCV_GITHUB_GCC_COMPILER_EXE})
|
||||
else()
|
||||
message(FATAL_ERROR "RISC-V GCC not found. ${RISCV_GITHUB_GCC_COMPILER} ${RISCV_XPACK_GCC_COMPILER} ${RISCV_GITHUB_GCC_COMPILER_EXE} ${RISCV_XPACK_GCC_COMPILER_EXE}")
|
||||
endif()
|
||||
|
||||
get_filename_component(RISCV_TOOLCHAIN_BIN_PATH ${RISCV_GCC_COMPILER} DIRECTORY)
|
||||
get_filename_component(RISCV_TOOLCHAIN_BIN_GCC ${RISCV_GCC_COMPILER} NAME_WE)
|
||||
get_filename_component(RISCV_TOOLCHAIN_BIN_EXT ${RISCV_GCC_COMPILER} EXT)
|
||||
|
||||
STRING(REGEX REPLACE "\-gcc" "-" CROSS_COMPILE ${RISCV_TOOLCHAIN_BIN_GCC})
|
||||
|
||||
# The Generic system name is used for embedded targets (targets without OS)
|
||||
set(CMAKE_SYSTEM_NAME Generic )
|
||||
set(CMAKE_EXECUTABLE_SUFFIX_C ".elf")
|
||||
set(RISCV_ARCH rv32imc_zicsr )
|
||||
set(RISCV_ABI ilp32)
|
||||
|
||||
|
||||
set(CMAKE_ASM_COMPILER {CROSS_COMPILE}gcc )
|
||||
set(CMAKE_AR ${CROSS_COMPILE}ar)
|
||||
set(CMAKE_ASM_COMPILER ${CROSS_COMPILE}gcc)
|
||||
set(CMAKE_C_COMPILER ${CROSS_COMPILE}gcc)
|
||||
set(CMAKE_CXX_COMPILER ${CROSS_COMPILE}g++)
|
||||
|
||||
set( CMAKE_OBJCOPY ${RISCV_TOOLCHAIN_BIN_PATH}/${CROSS_COMPILE}objcopy
|
||||
CACHE FILEPATH "The toolchain objcopy command " FORCE )
|
||||
|
||||
set( CMAKE_OBJDUMP ${RISCV_TOOLCHAIN_BIN_PATH}/${CROSS_COMPILE}objdump
|
||||
CACHE FILEPATH "The toolchain objdump command " FORCE )
|
||||
|
||||
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g" )
|
||||
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=${RISCV_ARCH} -mabi=${RISCV_ABI}" )
|
||||
|
||||
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" )
|
||||
set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" )
|
||||
set( CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" )
|
Loading…
x
Reference in New Issue
Block a user