arm.toolchain.cmake 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. if(COMMAND toolchain_save_config)
  2. return() # prevent recursive call
  3. endif()
  4. set(CMAKE_SYSTEM_NAME Linux)
  5. set(CMAKE_SYSTEM_VERSION 1)
  6. if(NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
  7. set(CMAKE_SYSTEM_PROCESSOR arm)
  8. else()
  9. #message("CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
  10. endif()
  11. include("${CMAKE_CURRENT_LIST_DIR}/gnu.toolchain.cmake")
  12. if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm AND NOT ARM_IGNORE_FP)
  13. set(FLOAT_ABI_SUFFIX "")
  14. if(NOT SOFTFP)
  15. set(FLOAT_ABI_SUFFIX "hf")
  16. endif()
  17. endif()
  18. if(NOT "x${GCC_COMPILER_VERSION}" STREQUAL "x")
  19. set(__GCC_VER_SUFFIX "-${GCC_COMPILER_VERSION}")
  20. endif()
  21. if(NOT DEFINED CMAKE_C_COMPILER)
  22. find_program(CMAKE_C_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-gcc${__GCC_VER_SUFFIX})
  23. else()
  24. #message(WARNING "CMAKE_C_COMPILER=${CMAKE_C_COMPILER} is defined")
  25. endif()
  26. if(NOT DEFINED CMAKE_CXX_COMPILER)
  27. find_program(CMAKE_CXX_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-g++${__GCC_VER_SUFFIX})
  28. else()
  29. #message(WARNING "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} is defined")
  30. endif()
  31. if(NOT DEFINED CMAKE_LINKER)
  32. find_program(CMAKE_LINKER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld)
  33. else()
  34. #message(WARNING "CMAKE_LINKER=${CMAKE_LINKER} is defined")
  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. else()
  39. #message(WARNING "CMAKE_AR=${CMAKE_AR} is defined")
  40. endif()
  41. if(NOT DEFINED ARM_LINUX_SYSROOT AND DEFINED GNU_MACHINE)
  42. set(ARM_LINUX_SYSROOT /usr/${GNU_MACHINE}${FLOAT_ABI_SUFFIX})
  43. endif()
  44. if(NOT DEFINED CMAKE_CXX_FLAGS)
  45. set(CMAKE_CXX_FLAGS "" CACHE INTERNAL "")
  46. set(CMAKE_C_FLAGS "" CACHE INTERNAL "")
  47. set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")
  48. set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")
  49. set(CMAKE_EXE_LINKER_FLAGS "" CACHE INTERNAL "")
  50. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")
  51. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")
  52. if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
  53. set(CMAKE_CXX_FLAGS "-mthumb ${CMAKE_CXX_FLAGS}")
  54. set(CMAKE_C_FLAGS "-mthumb ${CMAKE_C_FLAGS}")
  55. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,nocopyreloc")
  56. endif()
  57. if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
  58. set(ARM_LINKER_FLAGS "-Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
  59. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
  60. set(ARM_LINKER_FLAGS "-Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
  61. endif()
  62. set(CMAKE_SHARED_LINKER_FLAGS "${ARM_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
  63. set(CMAKE_MODULE_LINKER_FLAGS "${ARM_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")
  64. set(CMAKE_EXE_LINKER_FLAGS "${ARM_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
  65. else()
  66. #message(WARNING "CMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}' is defined")
  67. endif()
  68. if(USE_NEON)
  69. message(WARNING "You use obsolete variable USE_NEON to enable NEON instruction set. Use -DENABLE_NEON=ON instead." )
  70. set(ENABLE_NEON TRUE)
  71. elseif(USE_VFPV3)
  72. message(WARNING "You use obsolete variable USE_VFPV3 to enable VFPV3 instruction set. Use -DENABLE_VFPV3=ON instead." )
  73. set(ENABLE_VFPV3 TRUE)
  74. endif()
  75. set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${ARM_LINUX_SYSROOT})
  76. if(EXISTS ${CUDA_TOOLKIT_ROOT_DIR})
  77. set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CUDA_TOOLKIT_ROOT_DIR})
  78. endif()
  79. set(TOOLCHAIN_CONFIG_VARS ${TOOLCHAIN_CONFIG_VARS}
  80. ARM_LINUX_SYSROOT
  81. ENABLE_NEON
  82. ENABLE_VFPV3
  83. CUDA_TOOLKIT_ROOT_DIR
  84. )
  85. toolchain_save_config()