arm-linux.toolchain.cmake 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #
  2. # Copyright (c) 2008-2016 the Urho3D project.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. #
  22. if (DEFINED CMAKE_CROSSCOMPILING)
  23. return ()
  24. endif ()
  25. if (CMAKE_TOOLCHAIN_FILE)
  26. # Reference toolchain variable to suppress "unused variable" warning
  27. mark_as_advanced (CMAKE_TOOLCHAIN_FILE)
  28. endif ()
  29. # this one is important
  30. set (CMAKE_SYSTEM_NAME Linux)
  31. # this one not so much
  32. set (CMAKE_SYSTEM_VERSION 1)
  33. # specify the cross compiler
  34. if (NOT ARM_PREFIX AND DEFINED ENV{ARM_PREFIX})
  35. file (TO_CMAKE_PATH $ENV{ARM_PREFIX} ARM_PREFIX)
  36. endif ()
  37. if (NOT EXISTS ${ARM_PREFIX}-gcc)
  38. message (FATAL_ERROR "Could not find ARM cross compilation tool. "
  39. "Use ARM_PREFIX environment variable or build option to specify the location of the toolchain.")
  40. endif ()
  41. set (COMPILER_PREFIX ${ARM_PREFIX})
  42. if (NOT CMAKE_C_COMPILER AND "$ENV{USE_CCACHE}")
  43. get_filename_component (NAME ${ARM_PREFIX} NAME)
  44. execute_process (COMMAND whereis -b ccache COMMAND grep -o \\S*lib\\S* RESULT_VARIABLE EXIT_CODE OUTPUT_VARIABLE CCACHE_SYMLINK ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  45. if (EXIT_CODE EQUAL 0 AND EXISTS ${CCACHE_SYMLINK}/${NAME}-gcc AND EXISTS ${CCACHE_SYMLINK}/${NAME}-g++)
  46. set (COMPILER_PREFIX ${CCACHE_SYMLINK}/${NAME})
  47. else ()
  48. # Most probably this is a custom compiler toolchain not provided by the distro's own repository
  49. get_filename_component (PATH ${ARM_PREFIX} PATH)
  50. if (NOT $ENV{PATH} MATCHES ${PATH})
  51. message (FATAL_ERROR "The bin directory containing the compiler toolchain (${PATH}) has not been added in the PATH environment variable. "
  52. "This is required to enable ccache support for ARM compiler toolchain.")
  53. endif ()
  54. execute_process (COMMAND which ccache RESULT_VARIABLE EXIT_CODE OUTPUT_VARIABLE CCACHE ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  55. if (EXIT_CODE EQUAL 0)
  56. foreach (suffix gcc g++)
  57. execute_process (COMMAND ${CMAKE_COMMAND} -E create_symlink ${CCACHE} ${CMAKE_BINARY_DIR}/${NAME}-${suffix})
  58. endforeach ()
  59. set (COMPILER_PREFIX ${CMAKE_BINARY_DIR}/${NAME})
  60. else ()
  61. message (WARNING "ccache may not have been installed on this host system. "
  62. "This is required to enable ccache support for ARM compiler toolchain. CMake has been configured to use the actual compiler toolchain instead of ccache. "
  63. "In order to rectify this, the build tree must be regenerated after installing ccache.")
  64. endif ()
  65. endif ()
  66. endif ()
  67. set (CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc CACHE PATH "C compiler")
  68. set (CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++ CACHE PATH "C++ compiler")
  69. set (CMAKE_STRIP ${ARM_PREFIX}-strip CACHE PATH "strip")
  70. set (CMAKE_AR ${ARM_PREFIX}-ar CACHE PATH "archive")
  71. set (CMAKE_LINKER ${ARM_PREFIX}-ld CACHE PATH "linker")
  72. set (CMAKE_NM ${ARM_PREFIX}-nm CACHE PATH "nm")
  73. set (CMAKE_OBJCOPY ${ARM_PREFIX}-objcopy CACHE PATH "objcopy")
  74. set (CMAKE_OBJDUMP ${ARM_PREFIX}-objdump CACHE PATH "objdump")
  75. set (CMAKE_RANLIB ${ARM_PREFIX}-ranlib CACHE PATH "ranlib")
  76. # specify the system root
  77. if (NOT ARM_SYSROOT)
  78. if (DEFINED ENV{ARM_SYSROOT})
  79. file (TO_CMAKE_PATH $ENV{ARM_SYSROOT} ARM_SYSROOT)
  80. endif ()
  81. if (NOT EXISTS ${ARM_SYSROOT})
  82. message (FATAL_ERROR "Could not find ARM system root. "
  83. "Use ARM_SYSROOT environment variable or build option to specify the location of system root.")
  84. endif ()
  85. set (ARM_PREFIX ${ARM_PREFIX} CACHE STRING "Prefix path to ARM cross-compiler tools (ARM on Linux cross-compiling build only)" FORCE)
  86. set (ARM_SYSROOT ${ARM_SYSROOT} CACHE PATH "Path to ARM system root (ARM on Linux cross-compiling build only)" FORCE)
  87. endif ()
  88. set (CMAKE_FIND_ROOT_PATH ${ARM_SYSROOT})
  89. # cache flags (use the same trick found in android.toolchain.cmake)
  90. set (CMAKE_C_FLAGS "" CACHE STRING "C compiler flags")
  91. set (CMAKE_CXX_FLAGS "" CACHE STRING "C++ compiler flags")
  92. # finish flags
  93. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${ARM_SYSROOT}")
  94. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${ARM_SYSROOT}")
  95. # only search libraries, and headers in the target directories
  96. set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  97. set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  98. set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  99. set (ARM 1)