first version of working cmake

This commit is contained in:
Hongyu Liu 2024-12-20 14:27:45 +01:00
parent 32b9cc78b4
commit f419b1a3e6
6 changed files with 115 additions and 34 deletions

View File

@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.12)
project(bsp C) project(bsp C)
add_subdirectory(libwrap) add_subdirectory(libwrap)
message(STATUS " liu here") add_subdirectory(env)
message(STATUS " in bsp with ${CMAKE_CXX_FLAGS}")
message(STATUS " SUPPORTED_BOARDS= ${SUPPORTED_BOARDS}") message(STATUS " SUPPORTED_BOARDS= ${SUPPORTED_BOARDS}")
add_library(${PROJECT_NAME} INTERFACE) add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE target_include_directories(${PROJECT_NAME} INTERFACE

79
env/CMakeLists.txt vendored
View File

@ -1,39 +1,64 @@
project(bsp_env) project(env)
message(STATUS " here in bsp_env") message(STATUS " here in bsp/env")
message(STATUS " BOARD: ${BOARD}")
# Enable ASM language # Enable ASM language
enable_language(ASM) enable_language(ASM)
set(LIB_SOURCES set(ASM_SOURCES
entry.S entry.S
start.S start.S
) )
add_library(asm_obj OBJECT ${ASM_SOURCES})
# Set ASM compile options set_target_properties(asm_obj PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bare-metal-bsp/${PROJECT_NAME})
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI}") target_include_directories(asm_obj PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${BSP_BASE}/include
add_library(asm_obj OBJECT ${LIB_SOURCES}) #include/
add_subdirectory(${BOARD}) ${BSP_BASE}/env
${BSP_BASE}/env/${BOARD}
${BSP_BASE}/drivers
)
# 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 # Export variables for hello-world to use
set(ENV_OBJECTS set(ENV_OBJECTS
$<TARGET_OBJECTS:env_entry> $<TARGET_OBJECTS:asm_obj>
$<TARGET_OBJECTS:env_start>
PARENT_SCOPE PARENT_SCOPE
) )
set(BOARD_LIB_NAME ${BOARD})
message(STATUS " BOARD_LIB_NAME: ${BOARD_LIB_NAME}")
set(BOARD_LIB_SRC
${BOARD}/init.c
${BOARD}/write.c
)
add_library(${BOARD_LIB_NAME} STATIC ${BOARD_LIB_SRC})
set_target_properties(${BOARD_LIB_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bare-metal-bsp/${PROJECT_NAME})
# Set ASM compile options
#set(CMAKE_ASM_COMPILER riscv64-unknown-elf-as)
#set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI}")
#add_subdirectory(${BOARD})
target_include_directories(${BOARD_LIB_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${BSP_BASE}/include
${BSP_BASE}/libwrap/sys
${BSP_BASE}/env
${BSP_BASE}/env/${BOARD}
${BSP_BASE}/drivers
)
# 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 board library # Export board library
set(BOARD_LIB board_iss PARENT_SCOPE) #set(BOARD_LIB board_iss PARENT_SCOPE)

View File

@ -1,3 +1,7 @@
#cmake_minimum_required(VERSION 3.12)
project(iss)
message(STATUS " here in iss")
# Create library for ISS board support # Create library for ISS board support
add_library(board_iss STATIC add_library(board_iss STATIC
init.c init.c

38
env/iss/write.c vendored Normal file
View File

@ -0,0 +1,38 @@
/* See LICENSE of license details. */
#include <errno.h>
#include <stdint.h>
#include <sys/types.h>
#include <unistd.h>
#include "platform.h"
#include "stub.h"
#include "weak_under_alias.h"
#if defined(SEMIHOSTING)
#include "semihosting.h"
#endif
ssize_t __wrap_write(int fd, const void *ptr, size_t len) {
const uint8_t *current = (const uint8_t *)ptr;
#if defined(SEMIHOSTING)
if (isatty(fd)) {
for (size_t jj = 0; jj < len; jj++) {
sh_writec(current[jj]);
}
return len;
} else {
sh_write(current, fd);
return len;
}
// return len;
#endif
if (isatty(fd)) {
for (size_t jj = 0; jj < len; jj++) {
*((uint32_t *)0xFFFF0000) = current[jj];
}
return len;
}
return _stub(EBADF);
}
weak_under_alias(write);

1
env/start.S vendored
View File

@ -1,3 +1,4 @@
#include "encoding.h"
// See LICENSE for license details. // See LICENSE for license details.
.section .init .section .init

View File

@ -1,6 +1,9 @@
#cmake_minimum_required(VERSION 3.12)
project(libwrap) project(libwrap)
message(STATUS " here 2 in libwrap") message(STATUS " here 2 in libwrap")
set(LIBRARY_NAME libwrap)
set(STATIC_LIBRARY_FLAGS "rcs")
# Create object library for libwrap # Create object library for libwrap
set(LIB_SOURCES set(LIB_SOURCES
@ -24,7 +27,7 @@ set(LIB_SOURCES
sys/times.c sys/times.c
sys/unlink.c sys/unlink.c
sys/wait.c sys/wait.c
sys/write.c # sys/write.c
# Standard library # Standard library
stdlib/malloc.c stdlib/malloc.c
# Miscellaneous # Miscellaneous
@ -38,11 +41,20 @@ if(SEMIHOSTING)
endif() endif()
add_library(${PROJECT_NAME} OBJECT ${LIB_SOURCES}) #add_library(${LIBRARY_NAME} OBJECT ${LIB_SOURCES})
add_library(${LIBRARY_NAME} STATIC ${LIB_SOURCES})
set_target_properties(${LIBRARY_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bare-metal-bsp/${PROJECT_NAME})
message(STATUS " CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
# Retrieve the output directory for the library
get_target_property(LIBRARY_PATH ${LIBRARY_NAME} ARCHIVE_OUTPUT_DIRECTORY)
# Print the path to the console (for debugging purposes)
message(STATUS "The library output path is: ${LIBRARY_PATH}")
# Include directories # Include directories
target_include_directories(${PROJECT_NAME} PRIVATE target_include_directories(${LIBRARY_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${BSP_BASE}/include ${BSP_BASE}/include
include/ include/
@ -51,10 +63,10 @@ target_include_directories(${PROJECT_NAME} PRIVATE
${BSP_BASE}/drivers ${BSP_BASE}/drivers
) )
# Compile options
#link global_compile_options to this libraries #link global_compile_options to this libraries
target_link_libraries(${PROJECT_NAME} PRIVATE global_compile_options) #target_link_libraries(${PROJECT_NAME} PRIVATE global_compile_options)
# Compile definitions # Compile definitions
#target_compile_definitions(libwrap_objects PRIVATE #target_compile_definitions(libwrap_objects PRIVATE
@ -62,4 +74,4 @@ target_link_libraries(${PROJECT_NAME} PRIVATE global_compile_options)
#) #)
# Export objects to parent scope # Export objects to parent scope
set(LIBWRAP_OBJECTS $<TARGET_OBJECTS:${PROJECT_NAME}> PARENT_SCOPE) #set(LIBWRAP_OBJECTS $<TARGET_OBJECTS:${PROJECT_NAME}> PARENT_SCOPE)