CMakeFindBinUtils.cmake 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. # search for additional tools required for C/C++ (and other languages ?)
  4. #
  5. # If the internal cmake variable _CMAKE_TOOLCHAIN_PREFIX is set, this is used
  6. # as prefix for the tools (e.g. arm-elf-gcc etc.)
  7. # If the cmake variable _CMAKE_TOOLCHAIN_LOCATION is set, the compiler is
  8. # searched only there. The other tools are at first searched there, then
  9. # also in the default locations.
  10. #
  11. # Sets the following variables:
  12. # CMAKE_AR
  13. # CMAKE_RANLIB
  14. # CMAKE_LINKER
  15. # CMAKE_STRIP
  16. # CMAKE_INSTALL_NAME_TOOL
  17. # on UNIX, cygwin and mingw
  18. # if it's the MS C/CXX compiler, search for link
  19. if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC"
  20. OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"
  21. OR "x${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "xMSVC"
  22. OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xMSVC"
  23. OR "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC"
  24. OR (CMAKE_GENERATOR MATCHES "Visual Studio"
  25. AND NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android"))
  26. find_program(CMAKE_LINKER NAMES link HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  27. mark_as_advanced(CMAKE_LINKER)
  28. # in all other cases search for ar, ranlib, etc.
  29. else()
  30. if(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN)
  31. set(_CMAKE_TOOLCHAIN_LOCATION ${_CMAKE_TOOLCHAIN_LOCATION} ${CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN}/bin)
  32. endif()
  33. if(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
  34. set(_CMAKE_TOOLCHAIN_LOCATION ${_CMAKE_TOOLCHAIN_LOCATION} ${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}/bin)
  35. endif()
  36. find_program(CMAKE_AR NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ar${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  37. find_program(CMAKE_RANLIB NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ranlib HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  38. if(NOT CMAKE_RANLIB)
  39. set(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib")
  40. endif()
  41. find_program(CMAKE_STRIP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}strip${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  42. find_program(CMAKE_LINKER NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ld HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  43. find_program(CMAKE_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}nm HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  44. find_program(CMAKE_OBJDUMP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objdump HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  45. find_program(CMAKE_OBJCOPY NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objcopy HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  46. mark_as_advanced(CMAKE_AR CMAKE_RANLIB CMAKE_STRIP CMAKE_LINKER CMAKE_NM CMAKE_OBJDUMP CMAKE_OBJCOPY)
  47. endif()
  48. if(CMAKE_PLATFORM_HAS_INSTALLNAME)
  49. find_program(CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  50. if(NOT CMAKE_INSTALL_NAME_TOOL)
  51. message(FATAL_ERROR "Could not find install_name_tool, please check your installation.")
  52. endif()
  53. mark_as_advanced(CMAKE_INSTALL_NAME_TOOL)
  54. endif()