IREE: use some clever CMake hacks to avoid linker flags Create riscv_springbok.cmake file.This overrides the `add_executable` function to add an explicit link against the springbok intrinsic library. Doing so wires the dependencies through CMake and avoids the need for passing along flags for executables from the build system and scheduling them sequentially. The file can also be used to connect springbok BSP with other projects. Change-Id: I8830580464f17db12d4d0de0bec48bcb29c8ec47
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b7e783..ad2c355 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -9,10 +9,16 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(BUILD_RV64_LINUX OFF CACHE BOOL "Build RISC-V 64-bit Linux target (default: OFF)") + +#------------------------------------------------------------------------------- +# Springbok-specific settings +#------------------------------------------------------------------------------- set(ITCM_LENGTH "256K" CACHE STRING "ITCM (I-mem) Length (default: 256K)") add_link_options("LINKER:--defsym=__itcm_length__=${ITCM_LENGTH}") set(STACK_SIZE "10K" CACHE STRING "Stack size (default: 10K)") add_link_options("LINKER:--defsym=__stack_size__=${STACK_SIZE}") +set(SPRINGBOK_LINKER_SCRIPT "$ENV{ROOTDIR}/sw/vec/springbok/matcha.ld" CACHE PATH "Springbok linker script path (default: matcha.ld)") +add_subdirectory($ENV{ROOTDIR}/sw/vec/springbok springbok) #------------------------------------------------------------------------------- # IREE-specific settings @@ -37,6 +43,8 @@ add_definitions(-DIREE_USER_CONFIG_H="${SPRINGBOK_CONFIG_HEADER}") endif() +include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/riscv_springbok.cmake) + # Build IREE runtime libraries. add_subdirectory($ENV{ROOTDIR}/toolchain/iree iree) @@ -44,8 +52,5 @@ # functions properly in this project. include($ENV{ROOTDIR}/toolchain/iree/build_tools/cmake/iree_copts.cmake) -# Include springbok log functions. -include_directories(BEFORE SYSTEM "$ENV{ROOTDIR}/sw/vec/springbok/include") - # Add the included directory here. add_subdirectory(samples)
diff --git a/cmake/riscv_springbok.cmake b/cmake/riscv_springbok.cmake new file mode 100644 index 0000000..11eef4d --- /dev/null +++ b/cmake/riscv_springbok.cmake
@@ -0,0 +1,21 @@ +# A cmake cache to connect springbok BSP with the executables + +if(NOT TARGET springbok) + message(FATAL_ERROR "Please include springbok target first") +endif() + +if(NOT DEFINED SPRINGBOK_LINKER_SCRIPT) + message(FATAL_ERROR "Please specifiy SPRINGBOK_LINKER_SCRIPT path first") +endif() + +function(add_executable executable) + cmake_parse_arguments(AE "ALIAS;IMPORTED" "" "" ${ARGN}) + if(AE_ALIAS OR AE_IMPORTED) + _add_executable(${executable} ${ARGN}) + else() + _add_executable(${executable} ${ARGN}) + target_link_libraries(${executable} PRIVATE springbok) + target_link_options(${executable} PRIVATE "-T${SPRINGBOK_LINKER_SCRIPT}") + target_link_options(${executable} PRIVATE "-nostartfiles") + endif() +endfunction()