mips.toolchain.cmake 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # ----------------------------------------------------------------------------------------------
  2. # MIPS ToolChanin can be downloaded from https://www.mips.com/develop/tools/codescape-mips-sdk/ .
  3. # Toolchains with 'mti' in the name (and install directory) are for MIPS R2-R5 instruction sets.
  4. # Toolchains with 'img' in the name are for MIPS R6 instruction sets.
  5. # It is recommended to use cmake-gui application for build scripts configuration and generation:
  6. # 1. Run cmake-gui
  7. # 2. Specify toolchain file for cross-compiling, mips32r5el-gnu.toolchian.cmake or mips64r6el-gnu.toolchain.cmake
  8. # can be selected.
  9. # 3. Configure and Generate makefiles.
  10. # 4. make -j4 & make install
  11. # ----------------------------------------------------------------------------------------------
  12. if(COMMAND toolchain_save_config)
  13. return() # prevent recursive call
  14. endif()
  15. set(CMAKE_SYSTEM_NAME Linux)
  16. set(CMAKE_SYSTEM_VERSION 1)
  17. if(NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
  18. set(CMAKE_SYSTEM_PROCESSOR mips)
  19. endif()
  20. include("${CMAKE_CURRENT_LIST_DIR}/gnu.toolchain.cmake")
  21. if(CMAKE_SYSTEM_PROCESSOR STREQUAL mips AND NOT MIPS_IGNORE_FP)
  22. set(FLOAT_ABI_SUFFIX "")
  23. endif()
  24. if(NOT "x${GCC_COMPILER_VERSION}" STREQUAL "x")
  25. set(__GCC_VER_SUFFIX "-${GCC_COMPILER_VERSION}")
  26. endif()
  27. if(NOT DEFINED CMAKE_C_COMPILER)
  28. find_program(CMAKE_C_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-gcc${__GCC_VER_SUFFIX})
  29. endif()
  30. if(NOT DEFINED CMAKE_CXX_COMPILER)
  31. find_program(CMAKE_CXX_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-g++${__GCC_VER_SUFFIX})
  32. endif()
  33. if(NOT DEFINED CMAKE_LINKER)
  34. find_program(CMAKE_LINKER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld)
  35. endif()
  36. if(NOT DEFINED CMAKE_AR)
  37. find_program(CMAKE_AR NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar)
  38. endif()
  39. if(NOT DEFINED MIPS_LINUX_SYSROOT AND DEFINED GNU_MACHINE)
  40. set(MIPS_LINUX_SYSROOT /usr/bin)
  41. endif()
  42. if(NOT DEFINED CMAKE_CXX_FLAGS)
  43. if(CMAKE_SYSTEM_PROCESSOR MATCHES "mips32r5el")
  44. set(CMAKE_C_FLAGS "-march=mips32r5 -EL -mmsa -mhard-float -mfp64 -mnan=2008 -mabs=2008 -O3 -ffp-contract=off -mtune=p5600" CACHE INTERNAL "")
  45. set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")
  46. set(CMAKE_CXX_FLAGS "-march=mips32r5 -EL -mmsa -mhard-float -mfp64 -mnan=2008 -mabs=2008 -O3 -ffp-contract=off -mtune=p5600" CACHE INTERNAL "")
  47. set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")
  48. set(CMAKE_EXE_LINKER_FLAGS "-lpthread -lrt -ldl -latomic" CACHE INTERNAL "Added for mips cross build error")
  49. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")
  50. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")
  51. elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "mips64r6el")
  52. set(CMAKE_C_FLAGS "-O3 -march=i6500 -EL -mmsa -mabi=64 -mhard-float -mfp64 -mnan=2008" CACHE INTERNAL "")
  53. set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")
  54. set(CMAKE_CXX_FLAGS "-O3 -march=i6500 -EL -mmsa -mabi=64 -mhard-float -mfp64 -mnan=2008" CACHE INTERNAL "")
  55. set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")
  56. set(CMAKE_EXE_LINKER_FLAGS "-lpthread -lrt -ldl" CACHE INTERNAL "Added for mips cross build error")
  57. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")
  58. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")
  59. endif()
  60. set(CMAKE_SHARED_LINKER_FLAGS "${MIPS_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
  61. set(CMAKE_MODULE_LINKER_FLAGS "${MIPS_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")
  62. set(CMAKE_EXE_LINKER_FLAGS "${MIPS_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
  63. endif()
  64. set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${MIPS_LINUX_SYSROOT})
  65. set(TOOLCHAIN_CONFIG_VARS ${TOOLCHAIN_CONFIG_VARS}
  66. MIPS_LINUX_SYSROOT
  67. )
  68. toolchain_save_config()