CMakeFindBinUtils.cmake 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC"
  30. OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC"
  31. OR "${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "MSVC"
  32. OR "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC"
  33. OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC"
  34. OR "${CMAKE_GENERATOR}" MATCHES "Visual Studio")
  35. find_program(CMAKE_LINKER NAMES link HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  36. mark_as_advanced(CMAKE_LINKER)
  37. # in all other cases search for ar, ranlib, etc.
  38. else()
  39. if(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN)
  40. set(_CMAKE_TOOLCHAIN_LOCATION ${_CMAKE_TOOLCHAIN_LOCATION} ${CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN}/bin)
  41. endif()
  42. if(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
  43. set(_CMAKE_TOOLCHAIN_LOCATION ${_CMAKE_TOOLCHAIN_LOCATION} ${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}/bin)
  44. endif()
  45. find_program(CMAKE_AR NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ar${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  46. find_program(CMAKE_RANLIB NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ranlib HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  47. if(NOT CMAKE_RANLIB)
  48. set(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib")
  49. endif()
  50. find_program(CMAKE_STRIP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}strip${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  51. find_program(CMAKE_LINKER NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ld HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  52. find_program(CMAKE_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}nm HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  53. find_program(CMAKE_OBJDUMP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objdump HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  54. find_program(CMAKE_OBJCOPY NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objcopy HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
  55. mark_as_advanced(CMAKE_AR CMAKE_RANLIB CMAKE_STRIP CMAKE_LINKER CMAKE_NM CMAKE_OBJDUMP CMAKE_OBJCOPY)
  56. endif()
  57. # on Apple there really should be install_name_tool
  58. if(APPLE)
  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()