FindLLVM.cmake 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # - Find LLVM library
  2. # Find the native LLVM includes and library
  3. # This module defines
  4. # LLVM_INCLUDE_DIRS, where to find LLVM.h, Set when LLVM_INCLUDE_DIR is found.
  5. # LLVM_LIBRARIES, libraries to link against to use LLVM.
  6. # LLVM_ROOT_DIR, The base directory to search for LLVM.
  7. # This can also be an environment variable.
  8. # LLVM_FOUND, If false, do not try to use LLVM.
  9. #
  10. # also defined, but not for general use are
  11. # LLVM_LIBRARY, where to find the LLVM library.
  12. #=============================================================================
  13. # Copyright 2015 Blender Foundation.
  14. #
  15. # Distributed under the OSI-approved BSD License (the "License");
  16. # see accompanying file Copyright.txt for details.
  17. #
  18. # This software is distributed WITHOUT ANY WARRANTY; without even the
  19. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. # See the License for more information.
  21. #=============================================================================
  22. if(LLVM_ROOT_DIR)
  23. if(DEFINED LLVM_VERSION)
  24. find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION} HINTS ${LLVM_ROOT_DIR}/bin NO_CMAKE_PATH)
  25. endif()
  26. if(NOT LLVM_CONFIG)
  27. find_program(LLVM_CONFIG llvm-config HINTS ${LLVM_ROOT_DIR}/bin NO_CMAKE_PATH)
  28. endif()
  29. else()
  30. if(DEFINED LLVM_VERSION)
  31. message(running llvm-config-${LLVM_VERSION})
  32. find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION})
  33. endif()
  34. if(NOT LLVM_CONFIG)
  35. find_program(LLVM_CONFIG llvm-config)
  36. endif()
  37. endif()
  38. if(NOT DEFINED LLVM_VERSION)
  39. execute_process(COMMAND ${LLVM_CONFIG} --version
  40. OUTPUT_VARIABLE LLVM_VERSION
  41. OUTPUT_STRIP_TRAILING_WHITESPACE)
  42. set(LLVM_VERSION ${LLVM_VERSION} CACHE STRING "Version of LLVM to use")
  43. endif()
  44. if(NOT LLVM_ROOT_DIR)
  45. execute_process(COMMAND ${LLVM_CONFIG} --prefix
  46. OUTPUT_VARIABLE LLVM_ROOT_DIR
  47. OUTPUT_STRIP_TRAILING_WHITESPACE)
  48. set(LLVM_ROOT_DIR ${LLVM_ROOT_DIR} CACHE PATH "Path to the LLVM installation")
  49. endif()
  50. if(NOT LLVM_LIBPATH)
  51. execute_process(COMMAND ${LLVM_CONFIG} --libdir
  52. OUTPUT_VARIABLE LLVM_LIBPATH
  53. OUTPUT_STRIP_TRAILING_WHITESPACE)
  54. set(LLVM_LIBPATH ${LLVM_LIBPATH} CACHE PATH "Path to the LLVM library path")
  55. mark_as_advanced(LLVM_LIBPATH)
  56. endif()
  57. if(LLVM_STATIC)
  58. find_library(LLVM_LIBRARY
  59. NAMES LLVMAnalysis # first of a whole bunch of libs to get
  60. PATHS ${LLVM_LIBPATH})
  61. else()
  62. find_library(LLVM_LIBRARY
  63. NAMES
  64. LLVM-${LLVM_VERSION}
  65. LLVMAnalysis # check for the static library as a fall-back
  66. PATHS ${LLVM_LIBPATH})
  67. endif()
  68. if(LLVM_LIBRARY AND LLVM_ROOT_DIR AND LLVM_LIBPATH)
  69. if(LLVM_STATIC)
  70. # if static LLVM libraries were requested, use llvm-config to generate
  71. # the list of what libraries we need, and substitute that in the right
  72. # way for LLVM_LIBRARY.
  73. execute_process(COMMAND ${LLVM_CONFIG} --libfiles
  74. OUTPUT_VARIABLE LLVM_LIBRARY
  75. OUTPUT_STRIP_TRAILING_WHITESPACE)
  76. string(REPLACE " " ";" LLVM_LIBRARY "${LLVM_LIBRARY}")
  77. endif()
  78. endif()
  79. # handle the QUIETLY and REQUIRED arguments and set SDL2_FOUND to TRUE if
  80. # all listed variables are TRUE
  81. INCLUDE(FindPackageHandleStandardArgs)
  82. FIND_PACKAGE_HANDLE_STANDARD_ARGS(LLVM DEFAULT_MSG
  83. LLVM_LIBRARY)
  84. MARK_AS_ADVANCED(
  85. LLVM_LIBRARY
  86. )