riscv.toolchain.cmake 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. cmake_minimum_required(VERSION 3.5)
  2. if(COMMAND toolchain_save_config)
  3. return() # prevent recursive call
  4. endif()
  5. set(CMAKE_SYSTEM_NAME Linux)
  6. set(CMAKE_SYSTEM_VERSION 1)
  7. include("${CMAKE_CURRENT_LIST_DIR}/gnu.toolchain.cmake")
  8. MESSAGE(STATUS "Debug: CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
  9. if(NOT "x${GCC_COMPILER_VERSION}" STREQUAL "x")
  10. set(__GCC_VER_SUFFIX "-${GCC_COMPILER_VERSION}")
  11. endif()
  12. if(NOT DEFINED CMAKE_C_COMPILER)
  13. MESSAGE("Looking for compler.. ${GNU_MACHINE}-gcc${__GCC_VER_SUFFIX}")
  14. find_program(CMAKE_C_COMPILER NAMES ${GNU_MACHINE}-gcc${__GCC_VER_SUFFIX})
  15. else()
  16. #message(WARNING "CMAKE_C_COMPILER=${CMAKE_C_COMPILER} is defined")
  17. endif()
  18. if(NOT DEFINED CMAKE_CXX_COMPILER)
  19. find_program(CMAKE_CXX_COMPILER NAMES ${GNU_MACHINE}-g++${__GCC_VER_SUFFIX})
  20. else()
  21. #message(WARNING "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} is defined")
  22. endif()
  23. if(NOT DEFINED CMAKE_LINKER)
  24. find_program(CMAKE_LINKER NAMES ${GNU_MACHINE}-ld${__GCC_VER_SUFFIX} ${GNU_MACHINE}-ld)
  25. else()
  26. #message(WARNING "CMAKE_LINKER=${CMAKE_LINKER} is defined")
  27. endif()
  28. if(NOT DEFINED CMAKE_AR)
  29. find_program(CMAKE_AR NAMES ${GNU_MACHINE}-ar${__GCC_VER_SUFFIX} ${GNU_MACHINE}-ar)
  30. else()
  31. #message(WARNING "CMAKE_AR=${CMAKE_AR} is defined")
  32. endif()
  33. if(NOT DEFINED RISCV_LINUX_SYSROOT AND DEFINED GNU_MACHINE)
  34. set(RISCV_LINUX_SYSROOT /usr/${GNU_MACHINE})
  35. endif()
  36. if(NOT DEFINED CMAKE_CXX_FLAGS)
  37. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")
  38. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")
  39. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,nocopyreloc")
  40. set(RISCV_LINKER_FLAGS "-Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
  41. set(CMAKE_SHARED_LINKER_FLAGS "${RISCV_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
  42. set(CMAKE_MODULE_LINKER_FLAGS "${RISCV_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")
  43. set(CMAKE_EXE_LINKER_FLAGS "${RISCV_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
  44. else()
  45. message(STATUS "User provided flags are used instead of defaults")
  46. endif()
  47. set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${RISCV_LINUX_SYSROOT})
  48. set(TOOLCHAIN_CONFIG_VARS ${TOOLCHAIN_CONFIG_VARS}
  49. RISCV_LINUX_SYSROOT
  50. )
  51. toolchain_save_config()