ppcat.toolchain.cmake 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. if(COMMAND toolchain_save_config)
  2. return() # prevent recursive call
  3. endif()
  4. option(AT_PATH "Advance Toolchain directory" "")
  5. option(AT_RPATH "Add new directories to runtime search path" "")
  6. option(AT_HOST_LINK "Enable/disable Link against host advance toolchain runtime" OFF)
  7. option(AT_NO_AUTOVEC "Disable/enable Auto Vectorizer optimization" OFF)
  8. set(CMAKE_SYSTEM_NAME Linux)
  9. set(CMAKE_SYSTEM_VERSION 1)
  10. include("${CMAKE_CURRENT_LIST_DIR}/gnu.toolchain.cmake")
  11. if(NOT DEFINED CMAKE_C_COMPILER)
  12. string(REGEX REPLACE "/+$" "" AT_PATH "${AT_PATH}")
  13. if(NOT AT_PATH)
  14. message(FATAL_ERROR "'AT_PATH' option is required. Please set it to Advance Toolchain path to get toolchain works")
  15. endif()
  16. if(NOT EXISTS ${AT_PATH})
  17. message(FATAL_ERROR "'${AT_PATH}' Advance Toolchain path isn't exist")
  18. endif()
  19. set(CMAKE_C_COMPILER "${AT_PATH}/bin/${GNU_MACHINE}-gcc")
  20. if(NOT EXISTS ${CMAKE_C_COMPILER})
  21. message(FATAL_ERROR "GNU C compiler isn't exist on path '${CMAKE_C_COMPILER}'. Please install Advance Toolchain with ${CMAKE_SYSTEM_PROCESSOR} supports")
  22. endif()
  23. endif()
  24. if(NOT DEFINED CMAKE_CXX_COMPILER)
  25. set(CMAKE_CXX_COMPILER "${AT_PATH}/bin/${GNU_MACHINE}-g++")
  26. if(NOT EXISTS ${CMAKE_CXX_COMPILER})
  27. message(FATAL_ERROR "GNU C++ compiler isn't exist. Invalid install of Advance Toolchain")
  28. endif()
  29. endif()
  30. if(NOT DEFINED AT_GCCROOT_PATH)
  31. set(AT_GCCROOT_PATH "${AT_PATH}/${GNU_MACHINE}")
  32. if(NOT EXISTS ${AT_GCCROOT_PATH})
  33. message(FATAL_ERROR "GCC root path '${AT_GCCROOT_PATH}' isn't exist. Invalid install of Advance Toolchain")
  34. endif()
  35. endif()
  36. if(NOT DEFINED AT_SYSROOT_PATH)
  37. if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64")
  38. set(AT_SYSROOT_PATH "${AT_PATH}/ppc")
  39. else()
  40. set(AT_SYSROOT_PATH "${AT_PATH}/${CMAKE_SYSTEM_PROCESSOR}")
  41. endif()
  42. if(NOT EXISTS ${AT_SYSROOT_PATH})
  43. message(FATAL_ERROR "System root path '${AT_SYSROOT_PATH}' isn't exist. Invalid install of Advance Toolchain")
  44. endif()
  45. endif()
  46. if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS)
  47. set(CMAKE_CXX_FLAGS "" CACHE INTERNAL "")
  48. set(CMAKE_C_FLAGS "" CACHE INTERNAL "")
  49. set(CMAKE_EXE_LINKER_FLAGS "" CACHE INTERNAL "")
  50. set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")
  51. set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")
  52. if(AT_RPATH)
  53. string(REPLACE "," ";" RPATH_LIST ${AT_RPATH})
  54. endif()
  55. if(AT_HOST_LINK)
  56. #get 64-bit dynamic linker path
  57. file(STRINGS "${AT_SYSROOT_PATH}/usr/bin/ldd" RTLDLIST LIMIT_COUNT 1 REGEX "^RTLDLIST=[\"*\"]")
  58. string(REGEX REPLACE "RTLDLIST=|\"" "" RTLDLIST "${RTLDLIST}")
  59. string(REPLACE " " ";" RTLDLIST "${RTLDLIST}")
  60. #RTLDLIST must contains 32 and 64 bit paths
  61. list(LENGTH RTLDLIST RTLDLIST_LEN)
  62. if(NOT RTLDLIST_LEN GREATER 1)
  63. message(FATAL_ERROR "Could not fetch dynamic linker path. Invalid install of Advance Toolchain")
  64. endif()
  65. list (GET RTLDLIST 1 LINKER_PATH)
  66. set(CMAKE_EXE_LINKER_FLAGS "-Wl,--dynamic-linker=${AT_SYSROOT_PATH}${LINKER_PATH}")
  67. list(APPEND RPATH_LIST "${AT_GCCROOT_PATH}/lib64/")
  68. list(APPEND RPATH_LIST "${AT_SYSROOT_PATH}/lib64/")
  69. list(APPEND RPATH_LIST "${AT_SYSROOT_PATH}/usr/lib64/")
  70. list(APPEND RPATH_LIST "${PROJECT_BINARY_DIR}/lib/")
  71. endif()
  72. list(LENGTH RPATH_LIST RPATH_LEN)
  73. if(RPATH_LEN GREATER 0)
  74. set(AT_LINKER_FLAGS "${AT_LINKER_FLAGS} -Wl")
  75. foreach(RPATH ${RPATH_LIST})
  76. set(AT_LINKER_FLAGS "${AT_LINKER_FLAGS},-rpath,${RPATH}")
  77. endforeach()
  78. endif()
  79. set(CMAKE_SHARED_LINKER_FLAGS "${AT_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
  80. set(CMAKE_MODULE_LINKER_FLAGS "${AT_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")
  81. set(CMAKE_EXE_LINKER_FLAGS "${AT_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
  82. if(AT_NO_AUTOVEC)
  83. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-tree-vectorize -fno-tree-slp-vectorize")
  84. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-tree-vectorize -fno-tree-slp-vectorize")
  85. endif()
  86. endif()
  87. set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${AT_SYSROOT_PATH} ${AT_GCCROOT_PATH})
  88. set(CMAKE_SYSROOT ${AT_SYSROOT_PATH})
  89. # what about ld.gold?
  90. if(NOT DEFINED CMAKE_LINKER)
  91. find_program(CMAKE_LINKER NAMES ld)
  92. endif()
  93. if(NOT DEFINED CMAKE_AR)
  94. find_program(CMAKE_AR NAMES ar)
  95. endif()
  96. set(TOOLCHAIN_CONFIG_VARS ${TOOLCHAIN_CONFIG_VARS}
  97. CMAKE_SYSROOT
  98. AT_SYSROOT_PATH
  99. AT_GCCROOT_PATH
  100. )
  101. toolchain_save_config()