Merge branch 'master' into blender2.8
[blender.git] / build_files / cmake / Modules / FindLLVM.cmake
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 #=============================================================================
14 # Copyright 2015 Blender Foundation.
15 #
16 # Distributed under the OSI-approved BSD License (the "License");
17 # see accompanying file Copyright.txt for details.
18 #
19 # This software is distributed WITHOUT ANY WARRANTY; without even the
20 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 # See the License for more information.
22 #=============================================================================
23
24 if(LLVM_ROOT_DIR)
25         if(DEFINED LLVM_VERSION)
26                 find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION} HINTS ${LLVM_ROOT_DIR}/bin NO_CMAKE_PATH)
27         endif()
28         if(NOT LLVM_CONFIG)
29                 find_program(LLVM_CONFIG llvm-config HINTS ${LLVM_ROOT_DIR}/bin NO_CMAKE_PATH)
30         endif()
31 else()
32         if(DEFINED LLVM_VERSION)
33         message(running llvm-config-${LLVM_VERSION})
34                 find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION})
35         endif()
36         if(NOT LLVM_CONFIG)
37                 find_program(LLVM_CONFIG llvm-config)
38         endif()
39 endif()
40
41 if(NOT DEFINED LLVM_VERSION)
42         execute_process(COMMAND ${LLVM_CONFIG} --version
43                                         OUTPUT_VARIABLE LLVM_VERSION
44                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
45         set(LLVM_VERSION ${LLVM_VERSION} CACHE STRING "Version of LLVM to use")
46 endif()
47 if(NOT LLVM_ROOT_DIR)
48         execute_process(COMMAND ${LLVM_CONFIG} --prefix
49                                         OUTPUT_VARIABLE LLVM_ROOT_DIR
50                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
51         set(LLVM_ROOT_DIR ${LLVM_ROOT_DIR} CACHE PATH "Path to the LLVM installation")
52 endif()
53 if(NOT LLVM_LIBPATH)
54         execute_process(COMMAND ${LLVM_CONFIG} --libdir
55                                         OUTPUT_VARIABLE LLVM_LIBPATH
56                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
57         set(LLVM_LIBPATH ${LLVM_LIBPATH} CACHE PATH "Path to the LLVM library path")
58         mark_as_advanced(LLVM_LIBPATH)
59 endif()
60
61 if(LLVM_STATIC)
62         find_library(LLVM_LIBRARY
63                      NAMES LLVMAnalysis # first of a whole bunch of libs to get
64                      PATHS ${LLVM_LIBPATH})
65 else()
66         find_library(LLVM_LIBRARY
67                      NAMES
68                        LLVM-${LLVM_VERSION}
69                        LLVMAnalysis  # check for the static library as a fall-back
70                      PATHS ${LLVM_LIBPATH})
71 endif()
72
73
74 if(LLVM_LIBRARY AND LLVM_ROOT_DIR AND LLVM_LIBPATH)
75         if(LLVM_STATIC)
76                 # if static LLVM libraries were requested, use llvm-config to generate
77                 # the list of what libraries we need, and substitute that in the right
78                 # way for LLVM_LIBRARY.
79                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
80                                 OUTPUT_VARIABLE LLVM_LIBRARY
81                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
82                 string(REPLACE " " ";" LLVM_LIBRARY "${LLVM_LIBRARY}")
83         endif()
84 endif()
85
86
87 # handle the QUIETLY and REQUIRED arguments and set SDL2_FOUND to TRUE if
88 # all listed variables are TRUE
89 INCLUDE(FindPackageHandleStandardArgs)
90 FIND_PACKAGE_HANDLE_STANDARD_ARGS(LLVM DEFAULT_MSG
91     LLVM_LIBRARY)
92
93 MARK_AS_ADVANCED(
94   LLVM_LIBRARY
95 )