CMakeFindBinUtils.cmake 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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(CMAKE_LINKER)
  19. # we only get here if CMAKE_LINKER was specified using -D or a pre-made CMakeCache.txt
  20. # (e.g. via ctest) or set in CMAKE_TOOLCHAIN_FILE
  21. # find the linker in the PATH if necessary
  22. get_filename_component(_CMAKE_USER_LINKER_PATH "${CMAKE_LINKER}" PATH)
  23. if(NOT _CMAKE_USER_LINKER_PATH)
  24. find_program(CMAKE_LINKER_WITH_PATH NAMES ${CMAKE_LINKER} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  25. if(CMAKE_LINKER_WITH_PATH)
  26. set(CMAKE_LINKER ${CMAKE_LINKER_WITH_PATH})
  27. get_property(_CMAKE_LINKER_CACHED CACHE CMAKE_LINKER PROPERTY TYPE)
  28. if(_CMAKE_LINKER_CACHED)
  29. set(CMAKE_LINKER "${CMAKE_LINKER}" CACHE STRING "Default Linker" FORCE)
  30. endif()
  31. unset(_CMAKE_LINKER_CACHED)
  32. endif()
  33. unset(CMAKE_LINKER_WITH_PATH CACHE)
  34. endif()
  35. endif()
  36. # if it's the MS C/CXX compiler, search for link
  37. if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC"
  38. OR "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xMSVC"
  39. OR (CMAKE_HOST_WIN32 AND "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xPGI")
  40. OR (CMAKE_GENERATOR MATCHES "Visual Studio"
  41. AND NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android"))
  42. find_program(CMAKE_LINKER NAMES link HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  43. mark_as_advanced(CMAKE_LINKER)
  44. # in all other cases search for ar, ranlib, etc.
  45. else()
  46. if(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN)
  47. set(_CMAKE_TOOLCHAIN_LOCATION ${_CMAKE_TOOLCHAIN_LOCATION} ${CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN}/bin)
  48. endif()
  49. if(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
  50. set(_CMAKE_TOOLCHAIN_LOCATION ${_CMAKE_TOOLCHAIN_LOCATION} ${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}/bin)
  51. endif()
  52. find_program(CMAKE_AR NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ar${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  53. find_program(CMAKE_RANLIB NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ranlib HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  54. if(NOT CMAKE_RANLIB)
  55. set(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib")
  56. endif()
  57. find_program(CMAKE_STRIP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}strip${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  58. find_program(CMAKE_LINKER NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ld HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  59. find_program(CMAKE_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}nm HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  60. find_program(CMAKE_OBJDUMP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objdump HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  61. find_program(CMAKE_OBJCOPY NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objcopy HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  62. mark_as_advanced(CMAKE_AR CMAKE_RANLIB CMAKE_STRIP CMAKE_LINKER CMAKE_NM CMAKE_OBJDUMP CMAKE_OBJCOPY)
  63. endif()
  64. if(CMAKE_PLATFORM_HAS_INSTALLNAME)
  65. find_program(CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  66. if(NOT CMAKE_INSTALL_NAME_TOOL)
  67. message(FATAL_ERROR "Could not find install_name_tool, please check your installation.")
  68. endif()
  69. mark_as_advanced(CMAKE_INSTALL_NAME_TOOL)
  70. endif()