adds first version of cmake

This commit is contained in:
Hongyu Liu 2024-12-17 12:32:21 +01:00
parent 5eac63d773
commit 32b9cc78b4
6 changed files with 132 additions and 46 deletions

10
CMakeLists.txt Normal file
View File

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.12)
project(bsp C)
add_subdirectory(libwrap)
message(STATUS " liu here")
message(STATUS " SUPPORTED_BOARDS= ${SUPPORTED_BOARDS}")
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE
include/
env/${BOARD}
env/)

39
env/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,39 @@
project(bsp_env)
message(STATUS " here in bsp_env")
# Enable ASM language
enable_language(ASM)
set(LIB_SOURCES
entry.S
start.S
)
# Set ASM compile options
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI}")
add_library(asm_obj OBJECT ${LIB_SOURCES})
add_subdirectory(${BOARD})
# Include the ISS board configuration
set(ISS_SOURCE_DIR "${CMAKE_SOURCE_DIR}/bare-metal-bsp/env/iss")
set(ISS_BINARY_DIR "${CMAKE_BINARY_DIR}/iss_build")
add_subdirectory(${ISS_SOURCE_DIR} ${ISS_BINARY_DIR})
# Export variables for hello-world to use
set(ENV_OBJECTS
$<TARGET_OBJECTS:env_entry>
$<TARGET_OBJECTS:env_start>
PARENT_SCOPE
)
# Export board library
set(BOARD_LIB board_iss PARENT_SCOPE)

2
env/common-gcc.mk vendored
View File

@ -16,6 +16,7 @@ BOARD?=iss
ASM_SRCS += $(ENV_DIR)/start.S $(ENV_DIR)/entry.S ASM_SRCS += $(ENV_DIR)/start.S $(ENV_DIR)/entry.S
C_SRCS += $(PLATFORM_DIR)/init.c C_SRCS += $(PLATFORM_DIR)/init.c
C_SRCS += $(PLATFORM_DIR)/write.c
LINKER_SCRIPT ?= $(PLATFORM_DIR)/$(LINK_TARGET).lds LINKER_SCRIPT ?= $(PLATFORM_DIR)/$(LINK_TARGET).lds
@ -23,6 +24,7 @@ INCLUDES += -I$(BSP_BASE)/include
INCLUDES += -I$(BSP_BASE)/drivers/ INCLUDES += -I$(BSP_BASE)/drivers/
INCLUDES += -I$(ENV_DIR) INCLUDES += -I$(ENV_DIR)
INCLUDES += -I$(PLATFORM_DIR) INCLUDES += -I$(PLATFORM_DIR)
INCLUDES += -I$(BSP_BASE)/libwrap/sys/
LDFLAGS += -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) LDFLAGS += -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI)
LDFLAGS += -L$(ENV_DIR) LDFLAGS += -L$(ENV_DIR)

26
env/iss/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,26 @@
# Create library for ISS board support
add_library(board_iss STATIC
init.c
write.c
)
# Include directories
target_include_directories(board_iss PUBLIC
${BSP_BASE}/include
${BSP_BASE}/env
${CMAKE_CURRENT_SOURCE_DIR}
)
# Set compile options
target_compile_options(board_iss PRIVATE
-march=${RISCV_ARCH}_zicsr_zifencei
-mabi=${RISCV_ABI}
-mcmodel=medany
-ffunction-sections
-fdata-sections
)
# Add compile definitions
target_compile_definitions(board_iss PRIVATE
BOARD_${BOARD}
)

View File

@ -1,55 +1,65 @@
project(libwrap)
IF(NOT DEFINED _MK_LIBWRAP) message(STATUS " here 2 in libwrap")
SET(_MK_LIBWRAP TRUE) # Create object library for libwrap
set(LIB_SOURCES
sys/_exit.c
sys/close.c
sys/execve.c
sys/fork.c
sys/fstat.c
sys/getpid.c
sys/isatty.c
sys/kill.c
sys/link.c
sys/lseek.c
sys/open.c
sys/openat.c
sys/printf.c
sys/puts.c
sys/read.c
sys/sbrk.c
sys/stat.c
sys/times.c
sys/unlink.c
sys/wait.c
sys/write.c
# Standard library
stdlib/malloc.c
# Miscellaneous
misc/write_hex.c
)
SET(LIBWRAP_DIR ${CMAKE_CURRENT_LIST_DIR}) if(SEMIHOSTING)
list(APPEND LIB_SOURCES
semihosting/semihosting.c
semihosting/trap.c )
endif()
SET(LIBWRAP_SRCS add_library(${PROJECT_NAME} OBJECT ${LIB_SOURCES})
${LIBWRAP_DIR}/stdlib/malloc.c
${LIBWRAP_DIR}/sys/open.c
${LIBWRAP_DIR}/sys/lseek.c
${LIBWRAP_DIR}/sys/read.c
${LIBWRAP_DIR}/sys/write.c
${LIBWRAP_DIR}/sys/fstat.c
${LIBWRAP_DIR}/sys/stat.c
${LIBWRAP_DIR}/sys/close.c
${LIBWRAP_DIR}/sys/link.c
${LIBWRAP_DIR}/sys/unlink.c
${LIBWRAP_DIR}/sys/execve.c
${LIBWRAP_DIR}/sys/fork.c
${LIBWRAP_DIR}/sys/getpid.c
${LIBWRAP_DIR}/sys/kill.c
${LIBWRAP_DIR}/sys/wait.c
${LIBWRAP_DIR}/sys/isatty.c
${LIBWRAP_DIR}/sys/times.c
${LIBWRAP_DIR}/sys/sbrk.c
${LIBWRAP_DIR}/sys/_exit.c
${LIBWRAP_DIR}/misc/write_hex.c
${LIBWRAP_DIR}/sys/printf.c
${LIBWRAP_DIR}/sys/puts.c
)
IF(${SEMIHOSTING})
SET(LIBWRAP_SRCS ${LIBWRAP_SRCS} ${LIBWRAP_DIR}/semihosting/semihosting.c ${LIBWRAP_DIR}/semihosting/trap.c)
ENDIF()
SET(LIBWRAP_SYMS malloc free open lseek read write fstat stat close link unlink execve fork getpid jukk wait isatty times sbrk _exit printf puts)
# Includes # Include directories
INCLUDE_DIRECTORIES( target_include_directories(${PROJECT_NAME} PRIVATE
${LIBWRAP_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${LIBWRAP_DIR}/../include ${BSP_BASE}/include
${LIBWRAP_DIR}/../drivers include/
${LIBWRAP_DIR}/../env ${BSP_BASE}/env
${LIBWRAP_DIR}/../env/iss ${BSP_BASE}/env/${BOARD}
${BSP_BASE}/drivers
) )
ADD_LIBRARY(LIBWRAP_TGC STATIC ${LIBWRAP_SRCS}) # Compile options
TARGET_COMPILE_OPTIONS(LIBWRAP_TGC PRIVATE -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI} "-DBOARD_${BOARD}")
FOREACH(SYM ${LIBWRAP_SYMS}) #link global_compile_options to this libraries
LIST(APPEND WRAP_LDFLAGS "-Wl,--wrap=${SYM}") target_link_libraries(${PROJECT_NAME} PRIVATE global_compile_options)
ENDFOREACH()
SET(LIBWRAP_TGC_LDFLAGS ${WRAP_LDFLAGS} "-Wl,--start-group" "-Wl,--end-group" "-L. -lLIBWRAP_TGC") # Compile definitions
#target_compile_definitions(libwrap_objects PRIVATE
# BOARD_${BOARD}
#)
ENDIF(NOT DEFINED _MK_LIBWRAP) # Export objects to parent scope
set(LIBWRAP_OBJECTS $<TARGET_OBJECTS:${PROJECT_NAME}> PARENT_SCOPE)

View File

@ -9,7 +9,6 @@ LIBWRAP_SRCS := \
sys/open.c \ sys/open.c \
sys/lseek.c \ sys/lseek.c \
sys/read.c \ sys/read.c \
sys/write.c \
sys/fstat.c \ sys/fstat.c \
sys/stat.c \ sys/stat.c \
sys/close.c \ sys/close.c \