Firmwares/semihosting_test/CMakeLists.txt

86 lines
2.1 KiB
CMake

CMAKE_MINIMUM_REQUIRED(VERSION 3.13 FATAL_ERROR)
SET(BOARD "iss" CACHE STRING "board to be compiled for")
SET(RISCV_ARCH "rv32imc" CACHE STRING "arch")
SET(RISCV_ABI "ilp32" CACHE STRING "abi")
EXECUTE_PROCESS(
COMMAND which riscv64-unknown-elf-gcc
OUTPUT_VARIABLE COMPILER
OUTPUT_STRIP_TRAILING_WHITESPACE)
GET_FILENAME_COMPONENT(TOOL_DIR ${COMPILER} DIRECTORY)
SET(TRIPLET "riscv64-unknown-elf")
SET(CMAKE_C_COMPILER ${TOOL_DIR}/${TRIPLET}-gcc)
SET(CMAKE_CXX_COMPILER ${TOOL_DIR}/${TRIPLET}-g++)
SET(CMAKE_ASM_COMPILER ${TOOL_DIR}/${TRIPLET}-gcc)
SET(CMAKE_LINKER ${TOOL_DIR}/${TRIPLET}-ld)
SET(CMAKE_OBJCOPY ${TOOL_DIR}/${TRIPLET}-objcopy)
SET(CMAKE_AR ${TOOL_DIR}/${TRIPLET}-ar)
PROJECT(semihosting_test)
SET(BSP_BASE "../bare-metal-bsp")
SET(ENV_DIR ${BSP_BASE}/env)
SET(PLATFORM_DIR ${ENV_DIR}/${BOARD})
SET(SEMIHOSTING TRUE)
INCLUDE(${BSP_BASE}/libwrap/CMakeLists.txt)
INCLUDE_DIRECTORIES(
${BSP_BASE}/include
${BSP_BASE}/drivers
${BSP_BASE}/libwrap/semihosting
${ENV_DIR}
${PLATFORM_DIR})
# Source files
SET(ASM_SRCS
${ENV_DIR}/entry.S
${ENV_DIR}/start.S
)
SET(C_SRCS
${PLATFORM_DIR}/init.c
test.c
)
SET_SOURCE_FILES_PROPERTIES(${ASM_SRCS} PROPERTIES LANGUAGE C)
# Compiler Flags
SET(COMMON_FLAGS "")
# GCC Version Check
EXECUTE_PROCESS(
COMMAND ${CMAKE_C_COMPILER} --version
OUTPUT_VARIABLE GCC_VERSION
)
IF(GCC_VERSION MATCHES "9.2")
LIST(APPEND COMMON_FLAGS "-march=${RISCV_ARCH}")
ELSE()
LIST(APPEND COMMON_FLAGS "-march=${RISCV_ARCH}_zicsr_zifencei")
ENDIF()
LIST(APPEND COMMON_FLAGS "-mabi=${RISCV_ABI}" "-mcmodel=medany" "-DBOARD_${BOARD}")
# Compiler Options
ADD_COMPILE_OPTIONS("${COMMON_FLAGS}")
ADD_EXECUTABLE(${PROJECT_NAME} ${ASM_SRCS} ${C_SRCS} ${SRC_FILES})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC ${LIBWRAP_TGC_LDFLAGS} LIBWRAP_TGC)
# Linker Flags
TARGET_LINK_LIBRARIES(${PROJECT_NAME}
PUBLIC
-march=${RISCV_ARCH} -mabi=${RISCV_ABI}
-T/scratch/gabriel/repos/Firmwares/bare-metal-bsp/env/iss/link.lds
-Wl,-Map=${PROJECT_NAME}.map
-nostartfiles
-L${ENV_DIR}
)