first version of working cmake

This commit is contained in:
Hongyu Liu 2024-12-20 14:33:57 +01:00
parent 90c45d7c3c
commit fddf608418
3 changed files with 42 additions and 30 deletions

View File

@ -52,7 +52,7 @@ if(NOT DEFINED BOARD)
endif() endif()
if(NOT DEFINED ISA) if(NOT DEFINED ISA)
set(ISA imc CACHE STRING "Target ISA") set(ISA rv32imc CACHE STRING "Target ISA")
endif() endif()
if(NOT DEFINED RISCV_ABI) if(NOT DEFINED RISCV_ABI)
@ -69,7 +69,7 @@ if(NOT BOARD IN_LIST SUPPORTED_BOARDS)
endif() endif()
if(NOT ISA IN_LIST SUPPORTED_ISAS) if(NOT ISA IN_LIST SUPPORTED_ISAS)
message(FATAL_ERROR "Invalid ISA specified. Supported ISAs: ${SUPPORTED_ISAS}") message(FATAL_ERROR "Invalid ISA specified(${ISA}). Supported ISAs: ${SUPPORTED_ISAS}")
endif() endif()
if(NOT RISCV_ABI IN_LIST SUPPORTED_ABIS) if(NOT RISCV_ABI IN_LIST SUPPORTED_ABIS)
@ -91,8 +91,10 @@ set(BSP_BASE "${CMAKE_CURRENT_SOURCE_DIR}/bare-metal-bsp")
add_compile_definitions(BOARD_${BOARD}) add_compile_definitions(BOARD_${BOARD})
# RISC-V specific compiler flags # RISC-V specific compiler flags
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI} -mcmodel=medany")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -g -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI} -mcmodel=medany")
#set(CMAKE_ASM_COMPILER riscv64-unknown-elf-as)
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -O2 -g -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI} -mcmodel=medany")
# Optional: Enable semihosting support # Optional: Enable semihosting support
option(SEMIHOSTING "Enable semihosting support" OFF) option(SEMIHOSTING "Enable semihosting support" OFF)
@ -101,18 +103,18 @@ if(SEMIHOSTING)
endif() endif()
#create interface library for propagating compile options #create interface library for propagating compile options
add_library(global_compile_options INTERFACE) #add_library(global_compile_options INTERFACE)
# Compile options # Compile options
target_compile_options(global_compile_options INTERFACE #target_compile_options(global_compile_options INTERFACE
-march=${RISCV_ARCH}_zicsr_zifencei # -march=${RISCV_ARCH}_zicsr_zifencei
-mabi=${RISCV_ABI} # -mabi=${RISCV_ABI}
-mcmodel=medany # -mcmodel=medany
-O2 # -O2
-g # -g
# -ffunction-sections # -ffunction-sections
# -fdata-sections # -fdata-sections
) #)

@ -1 +1 @@
Subproject commit 87dc0ec2304adcb94a25b397a357aadae1304867 Subproject commit f419b1a3e6e9e8075d7e937ac5b1e1fb4829a976

View File

@ -6,9 +6,6 @@ if(NOT DEFINED BOARD)
set(BOARD "iss" CACHE STRING "Target board") set(BOARD "iss" CACHE STRING "Target board")
endif() endif()
#set(BSP_BASE "${CMAKE_CURRENT_SOURCE_DIR}/../bare-metal-bsp")
# Source files # Source files
set(SOURCES set(SOURCES
@ -21,19 +18,19 @@ message(STATUS "Using board-specific files from: ${BSP_BASE}/env/${BOARD}")
# Create executable with all objects # Create executable with all objects
add_executable(${PROJECT_NAME} add_executable(${PROJECT_NAME}
${SOURCES} ${SOURCES}
${BSP_OBJECTS}
) )
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".elf")
# Link with board library # Link with board library
target_link_libraries(${PROJECT_NAME} PRIVATE #target_link_libraries(${PROJECT_NAME} PRIVATE
${LIBWRAP_OBJECTS} # libwrap
${ENV_OBJECTS} # ${BOARD}
#$<TARGET_OBJECTS:env_entry> # $<TARGET_OBJECTS:asm_obj>
#$<TARGET_OBJECTS:env_start> # #$<TARGET_OBJECTS:env_start>
) # )
# Include directories # Include directories
target_include_directories(${PROJECT_NAME} PRIVATE target_include_directories(${PROJECT_NAME} PRIVATE
@ -49,14 +46,27 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
BOARD_${BOARD} BOARD_${BOARD}
) )
# link global_compile_options to this target # link global_compile_options to this target ????
target_link_libraries(${PROJECT_NAME} PRIVATE global_compile_options) #target_link_libraries(${PROJECT_NAME} PRIVATE global_compile_options)
get_target_property(WRAP_LIBRARY_PATH libwrap ARCHIVE_OUTPUT_DIRECTORY)
get_target_property(BOARDLIBRARY_PATH ${BOARD} ARCHIVE_OUTPUT_DIRECTORY)
## TODDO ???
set(ASM_OBJ_LIB "${BOARDLIBRARY_PATH}/CMakeFiles/asm_obj.dir")
message(STATUS "in hello_world WRAP_LIBRARY_PATH : ${WRAP_LIBRARY_PATH}, BOARDLIBRARY_PATH : ${BOARDLIBRARY_PATH} ASM_OBJ_LIB: ${ASM_OBJ_LIB} ")
# Set linker options # Set linker options
target_link_options(${PROJECT_NAME} PRIVATE target_link_options(${PROJECT_NAME} PRIVATE
-T${BSP_BASE}/env/${BOARD}/link.ld --verbose
-nostartfiles -L${ASM_OBJ_LIB}
-Wl,--gc-sections -L${WRAP_LIBRARY_PATH}
-L${BOARDLIBRARY_PATH}
${ASM_OBJ_LIB}/start.S.o
${ASM_OBJ_LIB}/entry.S.o
-L/scratch/hongyu/workarea/Firmwares/build/bare-metal-bsp/env/CMakeFiles/asm_obj.dir
-g -Wl,--wrap=printf -march=rv32imc -mabi=ilp32 -L../bare-metal-bsp/env/ -Wl,--wrap=malloc -Wl,--wrap=open -Wl,--wrap=lseek -Wl,--wrap=_lseek -Wl,--wrap=read -Wl,--wrap=_read -Wl,--wrap=write -Wl,--wrap=_write -Wl,--wrap=fstat -Wl,--wrap=_fstat -Wl,--wrap=stat -Wl,--wrap=close -Wl,--wrap=_close -Wl,--wrap=link -Wl,--wrap=unlink -Wl,--wrap=execve -Wl,--wrap=fork -Wl,--wrap=getpid -Wl,--wrap=kill -Wl,--wrap=wait -Wl,--wrap=isatty -Wl,--wrap=times -Wl,--wrap=sbrk -Wl,--wrap=_sbrk -Wl,--wrap=exit -Wl,--wrap=_exit -Wl,--wrap=puts -Wl,--wrap=_puts -Wl,--wrap=printf -Wl,--wrap=sprintf -L. -Wl,--start-group -llibwrap -liss -lc -Wl,--end-group -T /scratch/hongyu/workarea/Firmwares/bare-metal-bsp/env/iss/link.lds -Wl,--no-warn-rwx-segments -Wl,-Map=hello.map -nostartfiles -o hello.elf
) )
# Install target # Install target