diff --git a/CMakeLists.txt b/CMakeLists.txt index ec96d591..f1cc01b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,8 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)") set(ARCH "arm") elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^riscv64") set(ARCH "riscv64") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^riscv32") + set(ARCH "riscv32") elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^loongarch64") set(ARCH "loong64") else() @@ -279,6 +281,9 @@ else() elseif(ARCH STREQUAL "riscv64") add_compile_options(-march=rv64gc) add_compile_options(-mabi=lp64d) + elseif(ARCH STREQUAL "riscv32") + add_compile_options(-march=rv32gc) + add_compile_options(-mabi=ilp32d) elseif(ARCH STREQUAL "loong64") add_compile_options(-march=loongarch64) add_compile_options(-mabi=lp64d) diff --git a/cmake/toolchains/riscv32-linux-gnu.cmake b/cmake/toolchains/riscv32-linux-gnu.cmake new file mode 100644 index 00000000..fd5594e5 --- /dev/null +++ b/cmake/toolchains/riscv32-linux-gnu.cmake @@ -0,0 +1,43 @@ +# +# Copyright (C) 2023 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# + +if(UHDR_BUILD_CMAKE_TOOLCHAINS_RISCV32_LINUX_GNU_CMAKE_) + return() +endif() + +set(UHDR_BUILD_CMAKE_TOOLCHAINS_RISCV32_LINUX_GNU_CMAKE_ 1) + +set(CMAKE_SYSTEM_NAME "Linux") +set(CMAKE_SYSTEM_PROCESSOR "riscv32") + +if("${CROSS}" STREQUAL "") + set(CROSS riscv32-linux-gnu-) +endif() + +if(NOT CMAKE_C_COMPILER) + set(CMAKE_C_COMPILER ${CROSS}gcc) +endif() +if(NOT CMAKE_CXX_COMPILER) + set(CMAKE_CXX_COMPILER ${CROSS}g++) +endif() +if(NOT AS_EXECUTABLE) + set(AS_EXECUTABLE ${CROSS}as) +endif() + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) diff --git a/docs/building.md b/docs/building.md index 27e4b374..bb2a3cf4 100644 --- a/docs/building.md +++ b/docs/building.md @@ -271,6 +271,31 @@ This will generate the following files under `build_directory`: **ultrahdr_app** - sample application
**ultrahdr_unit_test** - unit tests
+#### Target - Linux Platform - RISC-V Arch (32 bit) + +Install the prerequisite packages before building: + +```sh +# Download from https://github.com/riscv-collab/riscv-gnu-toolchain/releases +sudo ln -s {your_dir}/riscv/bin/riscv32-unknown-linux-gnu-g++ /usr/bin/riscv32-linux-gnu-g++ +sudo ln -s {your_dir}/riscv/bin/riscv32-unknown-linux-gnu-gcc /usr/bin/riscv32-linux-gnu-gcc +``` + +Compile: + +```sh +cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/riscv32-linux-gnu.cmake -DUHDR_BUILD_DEPS=1 ../ +ninja +``` + +This will generate the following files under `build_directory`: + +**libuhdr.so.{version}** - Shared library for the libuhdr API
+**libuhdr.so** - Symlink to shared library
+**libuhdr.a** - Static link library for the libuhdr API
+**ultrahdr_app** - sample application
+**ultrahdr_unit_test** - unit tests
+ #### Target - Linux Platform - LOONG Arch (64 bit) Install the prerequisite packages before building: