raspberrypi.toolchain.cmake 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #
  2. # Copyright (c) 2008-2014 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. cmake_minimum_required (VERSION 2.6.3)
  23. if (CMAKE_TOOLCHAIN_FILE)
  24. # Reference toolchain variable to suppress "unused variable" warning
  25. endif ()
  26. # this one is important
  27. set (CMAKE_SYSTEM_NAME Linux)
  28. #this one not so much
  29. set (CMAKE_SYSTEM_VERSION 1)
  30. # specify the cross compiler
  31. file (TO_CMAKE_PATH "$ENV{RASPI_TOOL}" RASPI_TOOL)
  32. set (CMAKE_C_COMPILER ${RASPI_TOOL}/arm-linux-gnueabihf-gcc CACHE PATH "C compiler")
  33. set (CMAKE_CXX_COMPILER ${RASPI_TOOL}/arm-linux-gnueabihf-c++ CACHE PATH "C++ compiler")
  34. set (CMAKE_ASM_COMPILER ${RASPI_TOOL}/arm-linux-gnueabihf-gcc CACHE PATH "assembler")
  35. set (CMAKE_STRIP ${RASPI_TOOL}/arm-linux-gnueabihf-strip CACHE PATH "strip")
  36. set (CMAKE_AR ${RASPI_TOOL}/arm-linux-gnueabihf-ar CACHE PATH "archive")
  37. set (CMAKE_LINKER ${RASPI_TOOL}/arm-linux-gnueabihf-ld CACHE PATH "linker")
  38. set (CMAKE_NM ${RASPI_TOOL}/arm-linux-gnueabihf-nm CACHE PATH "nm")
  39. set (CMAKE_OBJCOPY ${RASPI_TOOL}/arm-linux-gnueabihf-objcopy CACHE PATH "objcopy")
  40. set (CMAKE_OBJDUMP ${RASPI_TOOL}/arm-linux-gnueabihf-objdump CACHE PATH "objdump")
  41. set (CMAKE_RANLIB ${RASPI_TOOL}/arm-linux-gnueabihf-ranlib CACHE PATH "ranlib")
  42. if (NOT CMAKE_CXX_COMPILER)
  43. message (FATAL_ERROR "Could not find Raspberry Pi cross compilation tool. "
  44. "Use RASPI_TOOL environment variable to specify the location of the toolchain. "
  45. "Use RASPI_ROOT environment variable to specify the location of system root.")
  46. endif ()
  47. # specify the system root
  48. if (NOT BCM_VC_INCLUDE_DIRS)
  49. # Keep invalidating the cache until we found the BCM library and its include directory which hopefully also mean we have found the correct SYSROOT
  50. unset (RASPI_SYSROOT CACHE)
  51. unset (CMAKE_INSTALL_PREFIX CACHE)
  52. endif ()
  53. file (TO_CMAKE_PATH "$ENV{RASPI_ROOT}" RASPI_ROOT)
  54. if (NOT RASPI_ROOT)
  55. set (RASPI_ROOT ${RASPI_TOOL}/../arm-linux-gnueabihf/libc)
  56. endif ()
  57. set (RASPI_SYSROOT ${RASPI_ROOT} CACHE PATH "Path to Raspberry Pi SYSROOT")
  58. set (CMAKE_FIND_ROOT_PATH ${RASPI_SYSROOT})
  59. # only search programs, libraries, and headers in the target directories
  60. set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
  61. set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  62. set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  63. # setup install destination prefix path
  64. set (CMAKE_INSTALL_PREFIX "${RASPI_SYSROOT}/usr/local" CACHE PATH "Install path prefix, prepended onto install directories.")