sw:vec_iree: Fix float_to_str function for non-springbok build Create a new cache function to link springbok.cpp to executables without the simprint dependency. Change-Id: I350f9ede4447451da2028efa0710a499e0bfeb7a
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c41392..5128e42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -13,7 +13,7 @@ ) set(BUILD_RV64_LINUX OFF CACHE BOOL "Build RISC-V 64-bit Linux target (default: OFF)") -set(BUILD_INTERNAL_MODELS OFF CACHE BOOL "Build applications from internal models (default: OFF") +set(BUILD_INTERNAL_MODELS OFF CACHE BOOL "Build applications from internal models (default: OFF)") # Use nano spec header and libraries. if(NOT ${BUILD_RV64_LINUX}) @@ -32,7 +32,6 @@ 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)") set(BUILD_WITH_SPRINGBOK ON CACHE BOOL "Build the target with springbok BSP (default: ON)") -add_subdirectory($ENV{ROOTDIR}/sw/vec/springbok springbok) #------------------------------------------------------------------------------- # IREE-specific settings @@ -57,13 +56,23 @@ add_definitions(-DIREE_USER_CONFIG_H="${SPRINGBOK_CONFIG_HEADER}") endif() -# Springbok BSP-related setting +# The project does a cmake hack here -- at the executable linkage stage, we +# append the logging library (and springbok BSP). Any logging library update +# (libspringbok.a or libnative_log.a) only gets rebuilt during executable +# linkage, but not during library compilation. +# +# However, an explicit include path gets added here across all targets so the +# header files can be found during compilation. if(${BUILD_WITH_SPRINGBOK}) + # Springbok BSP-related setting + add_subdirectory($ENV{ROOTDIR}/sw/vec/springbok springbok) include(riscv_springbok) include_directories($ENV{ROOTDIR}/sw/vec/springbok/include) else() - # Add the LOG_X springbok macros with fprintf. - include_directories(native_log_include) + # Add the springbok printout support. + add_subdirectory(native_log) + include(riscv_native_log) + include_directories(native_log) endif() # Build IREE runtime libraries.
diff --git a/cmake/riscv_native_log.cmake b/cmake/riscv_native_log.cmake new file mode 100644 index 0000000..5e6fd1a --- /dev/null +++ b/cmake/riscv_native_log.cmake
@@ -0,0 +1,17 @@ +# A native log support to be compatible with springbok simprint +# +# Connect the logging library with the executables + +if(NOT TARGET native_log) + message(FATAL_ERROR "Please include native_log target 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 native_log) + endif() +endfunction()
diff --git a/native_log/CMakeLists.txt b/native_log/CMakeLists.txt new file mode 100644 index 0000000..0c6cbb8 --- /dev/null +++ b/native_log/CMakeLists.txt
@@ -0,0 +1,23 @@ +add_library(native_log STATIC) + +target_sources(native_log + PRIVATE + springbok.h + "$ENV{ROOTDIR}/sw/vec/springbok/springbok.cpp" +) + +target_include_directories(native_log + PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}" +) + +target_compile_options(native_log + PRIVATE + "-Wall" +) + +set_target_properties( + native_log + PROPERTIES + LINKER_LANGUAGE C +)
diff --git a/native_log_include/springbok.h b/native_log/springbok.h similarity index 79% rename from native_log_include/springbok.h rename to native_log/springbok.h index b6ac85c..6872908 100644 --- a/native_log_include/springbok.h +++ b/native_log/springbok.h
@@ -10,4 +10,12 @@ #define LOG_WARN(msg, args...) fprintf(stdout, "[WARN] " msg "\n", ##args) #define LOG_ERROR(msg, args...) fprintf(stderr, "[ERROR] " msg "\n", ##args) +#ifdef __cplusplus +extern "C" { +#endif +int float_to_str(const int len, char *buffer, const float value); +#ifdef __cplusplus +} +#endif + #endif // SPRINGBOK_H