mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2026-10-28 18:07:12 +08:00
- Use -fno-tree-vectorize and -fno-tree-slp-vectorize instead of Clang-only -fno-vectorize and -fno-slp-vectorize in CMakeLists.txt, riscv-clang.cmake, BUILD.gn, and BUILD.bazel for GCC and Clang compatibility. - Split row_rvv.cc and scale_rvv.cc into a dedicated libyuv_rvv target in BUILD.gn and define LIBYUV_RVV so callers in row.h and scale_row.h can dispatch to RVV kernels when built without global -march=rv64gcv. - Guard the x86 AVX512-BF16 vdpphps inline assembly probe in util/cpuid.c with __i386__ / __x86_64__. - Replace new/delete and new[]/delete[] with calloc/malloc/free in source/mjpeg_decoder.cc and util/yuvconvert.cc to avoid C++ standard library dependencies, and link libm for yuvconstants and libyuv_unittest in CMakeLists.txt. Test: cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ .. Bug: None Change-Id: I701c0625f2730e864806556213a5e013c931e2d6 Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8464751 Reviewed-by: richard winterton <rrwinterton@gmail.com> Commit-Queue: Frank Barchard <fbarchard@google.com>
57 lines
2.3 KiB
CMake
57 lines
2.3 KiB
CMake
set(CMAKE_CROSSCOMPILING TRUE)
|
|
set(CMAKE_SYSTEM_NAME "Linux")
|
|
set(CMAKE_SYSTEM_PROCESSOR "riscv64")
|
|
|
|
option(USE_RVV "Enable riscv vector or not." ON)
|
|
option(USE_AUTO_VECTORIZER "Enable riscv auto vectorizer or not." OFF)
|
|
|
|
# Avoid to use system path for cross-compile
|
|
set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE)
|
|
|
|
set(TOOLCHAIN_PATH "" CACHE STRING "The toolcahin path.")
|
|
if(NOT TOOLCHAIN_PATH)
|
|
set(TOOLCHAIN_PATH ${CMAKE_SOURCE_DIR}/build-toolchain-qemu/riscv-clang)
|
|
endif()
|
|
|
|
set(TOOLCHAIN_PREFIX "riscv64-unknown-linux-gnu-" CACHE STRING "The toolcahin prefix.")
|
|
|
|
# toolchain setting
|
|
set(CMAKE_C_COMPILER "${TOOLCHAIN_PATH}/bin/${TOOLCHAIN_PREFIX}clang")
|
|
set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PATH}/bin/${TOOLCHAIN_PREFIX}clang++")
|
|
|
|
# CMake will just use the host-side tools for the following tools, so we setup them here.
|
|
set(CMAKE_C_COMPILER_AR "${TOOLCHAIN_PATH}/bin/llvm-ar")
|
|
set(CMAKE_CXX_COMPILER_AR "${TOOLCHAIN_PATH}/bin/llvm-ar")
|
|
set(CMAKE_C_COMPILER_RANLIB "${TOOLCHAIN_PATH}/bin/llvm-ranlib")
|
|
set(CMAKE_CXX_COMPILER_RANLIB "${TOOLCHAIN_PATH}/bin/llvm-ranlib")
|
|
set(CMAKE_OBJDUMP "${TOOLCHAIN_PATH}/bin/llvm-objdump")
|
|
set(CMAKE_OBJCOPY "${TOOLCHAIN_PATH}/bin/llvm-objcopy")
|
|
|
|
# compile options
|
|
set(RISCV_COMPILER_FLAGS "" CACHE STRING "Compile flags")
|
|
# if user provides RISCV_COMPILER_FLAGS, appeding compile flags is avoided.
|
|
if(RISCV_COMPILER_FLAGS STREQUAL "")
|
|
message(STATUS "USE_RVV: ${USE_RVV}")
|
|
message(STATUS "USE_AUTO_VECTORIZER: ${USE_AUTO_VECTORIZER}")
|
|
if(USE_RVV)
|
|
list(APPEND RISCV_COMPILER_FLAGS "-march=rv64gcv")
|
|
if(NOT USE_AUTO_VECTORIZER)
|
|
# Disable auto-vectorizer
|
|
add_compile_options(-fno-tree-vectorize -fno-tree-slp-vectorize)
|
|
endif()
|
|
else()
|
|
list(APPEND RISCV_COMPILER_FLAGS "-march=rv64gc")
|
|
endif()
|
|
endif()
|
|
add_compile_options("-Wuninitialized")
|
|
message(STATUS "RISCV_COMPILER_FLAGS: ${RISCV_COMPILER_FLAGS}")
|
|
|
|
set(CMAKE_C_FLAGS "${RISCV_COMPILER_FLAGS} ${CMAKE_C_FLAGS}")
|
|
set(CMAKE_CXX_FLAGS "${RISCV_COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}")
|
|
|
|
set(RISCV_LINKER_FLAGS "-lstdc++ -lpthread -lm -ldl")
|
|
set(RISCV_LINKER_FLAGS_EXE)
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${RISCV_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
|
|
set(CMAKE_MODULE_LINKER_FLAGS "${RISCV_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")
|
|
set(CMAKE_EXE_LINKER_FLAGS "${RISCV_LINKER_FLAGS} ${RISCV_LINKER_FLAGS_EXE} ${CMAKE_EXE_LINKER_FLAGS}")
|