CMakeFindBinUtils.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # search for additional tools required for C/C++ (and other languages ?)
  2. #
  3. # If the internal cmake variable _CMAKE_TOOLCHAIN_PREFIX is set, this is used
  4. # as prefix for the tools (e.g. arm-elf-gcc etc.)
  5. # If the cmake variable _CMAKE_TOOLCHAIN_LOCATION is set, the compiler is
  6. # searched only there. The other tools are at first searched there, then
  7. # also in the default locations.
  8. #
  9. # Sets the following variables:
  10. # CMAKE_AR
  11. # CMAKE_RANLIB
  12. # CMAKE_LINKER
  13. # CMAKE_STRIP
  14. # CMAKE_INSTALL_NAME_TOOL
  15. # on UNIX, cygwin and mingw
  16. #=============================================================================
  17. # Copyright 2007-2009 Kitware, Inc.
  18. #
  19. # Distributed under the OSI-approved BSD License (the "License");
  20. # see accompanying file Copyright.txt for details.
  21. #
  22. # This software is distributed WITHOUT ANY WARRANTY; without even the
  23. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  24. # See the License for more information.
  25. #=============================================================================
  26. # (To distribute this file outside of CMake, substitute the full
  27. # License text for the above reference.)
  28. # if it's the MS C/CXX compiler, search for link
  29. if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC"
  30. OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"
  31. OR "x${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "xMSVC"
  32. OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xMSVC"
  33. OR "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC"
  34. OR (CMAKE_GENERATOR MATCHES "Visual Studio"
  35. AND NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android"))
  36. find_program(CMAKE_LINKER NAMES link HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  37. mark_as_advanced(CMAKE_LINKER)
  38. # in all other cases search for ar, ranlib, etc.
  39. else()
  40. if(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN)
  41. set(_CMAKE_TOOLCHAIN_LOCATION ${_CMAKE_TOOLCHAIN_LOCATION} ${CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN}/bin)
  42. endif()
  43. if(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
  44. set(_CMAKE_TOOLCHAIN_LOCATION ${_CMAKE_TOOLCHAIN_LOCATION} ${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}/bin)
  45. endif()
  46. find_program(CMAKE_AR NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ar${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  47. find_program(CMAKE_RANLIB NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ranlib HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  48. if(NOT CMAKE_RANLIB)
  49. set(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib")
  50. endif()
  51. find_program(CMAKE_STRIP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}strip${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  52. find_program(CMAKE_LINKER NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ld HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  53. find_program(CMAKE_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}nm HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  54. find_program(CMAKE_OBJDUMP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objdump HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  55. find_program(CMAKE_OBJCOPY NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objcopy HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  56. mark_as_advanced(CMAKE_AR CMAKE_RANLIB CMAKE_STRIP CMAKE_LINKER CMAKE_NM CMAKE_OBJDUMP CMAKE_OBJCOPY)
  57. endif()
  58. if(CMAKE_PLATFORM_HAS_INSTALLNAME)
  59. find_program(CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  60. if(NOT CMAKE_INSTALL_NAME_TOOL)
  61. message(FATAL_ERROR "Could not find install_name_tool, please check your installation.")
  62. endif()
  63. mark_as_advanced(CMAKE_INSTALL_NAME_TOOL)
  64. endif()