CMakeFindBinUtils.cmake 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC"
  20. OR "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xMSVC"
  21. OR (CMAKE_HOST_WIN32 AND "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xPGI")
  22. OR (CMAKE_GENERATOR MATCHES "Visual Studio"
  23. AND NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android"))
  24. find_program(CMAKE_LINKER NAMES link HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  25. mark_as_advanced(CMAKE_LINKER)
  26. # in all other cases search for ar, ranlib, etc.
  27. else()
  28. if(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN)
  29. set(_CMAKE_TOOLCHAIN_LOCATION ${_CMAKE_TOOLCHAIN_LOCATION} ${CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN}/bin)
  30. endif()
  31. if(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
  32. set(_CMAKE_TOOLCHAIN_LOCATION ${_CMAKE_TOOLCHAIN_LOCATION} ${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}/bin)
  33. endif()
  34. find_program(CMAKE_AR NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ar${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  35. find_program(CMAKE_RANLIB NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ranlib HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  36. if(NOT CMAKE_RANLIB)
  37. set(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib")
  38. endif()
  39. find_program(CMAKE_STRIP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}strip${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  40. find_program(CMAKE_LINKER NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ld HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  41. find_program(CMAKE_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}nm HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  42. find_program(CMAKE_OBJDUMP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objdump HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  43. find_program(CMAKE_OBJCOPY NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objcopy HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  44. mark_as_advanced(CMAKE_AR CMAKE_RANLIB CMAKE_STRIP CMAKE_LINKER CMAKE_NM CMAKE_OBJDUMP CMAKE_OBJCOPY)
  45. endif()
  46. if(CMAKE_PLATFORM_HAS_INSTALLNAME)
  47. find_program(CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  48. if(NOT CMAKE_INSTALL_NAME_TOOL)
  49. message(FATAL_ERROR "Could not find install_name_tool, please check your installation.")
  50. endif()
  51. mark_as_advanced(CMAKE_INSTALL_NAME_TOOL)
  52. endif()