Add RISC-V to cmake linux (#6375)

* Add support for RISC-V compile to cmake

* No need to pass -march for gcc in riscv

* -march=native is not supported in Risc-V clang

* fix comment and remove unnecessary newline

* Remove incorrect values while checking CMAKE_SYSTEM_PROCESSOR

* Support 32bit RISCV as well

I dont think this will be ever be needed, but i dont like that compilation will fail due to incorrect compiler flags if you try.
This commit is contained in:
Shivansps authored and GitHub committed 2024-10-28 17:27:39 +09:00
1 parent 80625fd307
commit 2eb2af6f76
5 files changed
+44 -7

No files matched your search

+12
View File
@@ -19,3 +19,15 @@ else()
set(IS_ARM64 TRUE)
endif()
endif()
set(IS_RISCV FALSE)
if (NOT "${CMAKE_GENERATOR_PLATFORM}" STREQUAL "") # needed to cover Visual Studio generator
if(CMAKE_GENERATOR_PLATFORM MATCHES "^(riscv64|RISCV64|riscv32|RISCV32)")
set(IS_RISCV TRUE)
endif()
else()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv64|RISCV64|riscv32|RISCV32)")
set(IS_RISCV TRUE)
endif()
endif()
+1
View File
@@ -10,6 +10,7 @@
#cmakedefine01 IS_64BIT
#cmakedefine01 IS_ARM64
#cmakedefine01 IS_RISCV
#cmakedefine01 SCP_HAVE_STRCASECMP
#cmakedefine01 SCP_HAVE_STRNCASECMP
+11 -3
View File
@@ -9,9 +9,17 @@ option(CLANG_ENABLE_ADDRESS_SANITIZER "Enable -fsanitize=address" OFF)
option(CLANG_USE_LIBCXX "Use libc++" OFF)
# These are the default values
set(C_BASE_FLAGS "-march=native -pipe")
set(CXX_BASE_FLAGS "-march=native -pipe")
# Clang does not support -march=native for RISC-V
if(IS_RISCV)
# You do not need to pass a -march, passing nothing will make clang to choose itself.
# If you want a specific set of instructions like vectors, set -march in CFLAGS and CXXFLAGS env variables
set(C_BASE_FLAGS "-pipe")
set(CXX_BASE_FLAGS "-pipe")
else()
# These are the default values
set(C_BASE_FLAGS "-march=native -pipe")
set(CXX_BASE_FLAGS "-march=native -pipe")
endif()
# For C and C++, the values can be overwritten independently
if(DEFINED ENV{CXXFLAGS})
+13 -3
View File
@@ -11,9 +11,19 @@ option(GCC_ENABLE_SANITIZE_UNDEFINED "Enable -fsanitize=undefined" OFF)
option(GCC_USE_GOLD "Use the gold linker instead of the standard linker" OFF)
option(GCC_GENERATE_GDB_INDEX "Adds linker option to generate the gdb index for debug builds" OFF)
# These are the default values
set(C_BASE_FLAGS "-march=native -pipe")
set(CXX_BASE_FLAGS "-march=native -pipe")
# GCC does not support -march=native in RISC-V
if(IS_RISCV)
# You do not need to pass a -march, passing nothing will make gcc to choose itself.
# If you want a specific set of instructions like vectors, set -march in CFLAGS and CXXFLAGS env variables
# Example for vectors: -march=rv64gcv
# https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Options.html
set(C_BASE_FLAGS "-pipe")
set(CXX_BASE_FLAGS "-pipe")
else()
# These are the default values
set(C_BASE_FLAGS "-march=native -pipe")
set(CXX_BASE_FLAGS "-march=native -pipe")
endif()
# For C and C++, the values can be overwritten independently
if(DEFINED ENV{CFLAGS})
+7 -1
View File
@@ -35,7 +35,13 @@ ELSE()
SET(FSO_BINARY_SUFFIX "${FSO_VERSION_MAJOR}_${FSO_VERSION_MINOR}_${FSO_VERSION_BUILD}_${FSO_VERSION_REVISION_STR}")
ENDIF()
IF(IS_ARM64)
IF(IS_RISCV)
IF(IS_64BIT)
SET(FSO_BINARY_SUFFIX "${FSO_BINARY_SUFFIX}_riscv64")
ELSE()
SET(FSO_BINARY_SUFFIX "${FSO_BINARY_SUFFIX}_riscv32")
ENDIF()
ELSEIF(IS_ARM64)
SET(FSO_BINARY_SUFFIX "${FSO_BINARY_SUFFIX}_arm64")
ELSEIF(IS_64BIT)
# This is a 64-bit builds