[cmake] move FindLLVM to its own file
authorMartijn Berger <mberger@denc.com>
Wed, 6 May 2015 10:35:41 +0000 (12:35 +0200)
committerMartijn Berger <mberger@denc.com>
Wed, 6 May 2015 10:35:48 +0000 (12:35 +0200)
CMakeLists.txt
build_files/cmake/Modules/FindLLVM.cmake [new file with mode: 0644]

index ea1ca3d37b2d35b1a123837425ee0a795afe8b61..ae2c67b59bfbff1ff97bda1c49771ca23a78c6b9 100644 (file)
@@ -1059,70 +1059,13 @@ if(UNIX AND NOT APPLE)
                endif()
        endif()
 
-       # XXX Maybe most of this section should go into an llvm module?
        if(WITH_LLVM)
+        find_package_wrapper(LLVM)
 
-               if(LLVM_ROOT_DIR)
-                       if(NOT DEFINED LLVM_VERSION)
-                               find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION} HINTS ${LLVM_ROOT_DIR}/bin NO_CMAKE_PATH)
-                       endif()
-                       if(NOT LLVM_CONFIG)
-                               find_program(LLVM_CONFIG llvm-config HINTS ${LLVM_ROOT_DIR}/bin NO_CMAKE_PATH)
-                       endif()
-               else()
-                       if(NOT DEFINED LLVM_VERSION)
-                               find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION})
-                       endif()
-                       if(NOT LLVM_CONFIG)
-                               find_program(LLVM_CONFIG llvm-config)
-                       endif()
-               endif()
-
-               if(NOT DEFINED LLVM_VERSION)
-                       execute_process(COMMAND ${LLVM_CONFIG} --version
-                                                       OUTPUT_VARIABLE LLVM_VERSION
-                                                       OUTPUT_STRIP_TRAILING_WHITESPACE)
-                       set(LLVM_VERSION ${LLVM_VERSION} CACHE STRING "Version of LLVM to use")
+        if(NOT LLVM_FOUND)
+                       set(WITH_LLVM OFF)
+                       message(STATUS "LLVM not found")
                endif()
-               if(NOT DEFINED LLVM_ROOT_DIR)
-                       execute_process(COMMAND ${LLVM_CONFIG} --prefix
-                                                       OUTPUT_VARIABLE LLVM_ROOT_DIR
-                                                       OUTPUT_STRIP_TRAILING_WHITESPACE)
-                       set(LLVM_ROOT_DIR ${LLVM_ROOT_DIR} CACHE PATH "Path to the LLVM installation")
-               endif()
-               if(NOT DEFINED LLVM_LIBPATH)
-                       execute_process(COMMAND ${LLVM_CONFIG} --libdir
-                                                       OUTPUT_VARIABLE LLVM_LIBPATH
-                                                       OUTPUT_STRIP_TRAILING_WHITESPACE)
-                       set(LLVM_LIBPATH ${LLVM_LIBPATH} CACHE PATH "Path to the LLVM library path")
-                       mark_as_advanced(LLVM_LIBPATH)
-               endif()
-
-               if(LLVM_STATIC)
-                       find_library(LLVM_LIBRARY
-                                    NAMES LLVMAnalysis # first of a whole bunch of libs to get
-                                    PATHS ${LLVM_LIBPATH})
-               else()
-                       find_library(LLVM_LIBRARY
-                                    NAMES LLVM-${LLVM_VERSION}
-                                    PATHS ${LLVM_LIBPATH})
-               endif()
-
-
-               if(LLVM_LIBRARY AND LLVM_ROOT_DIR AND LLVM_LIBPATH)
-                       if(LLVM_STATIC)
-                               # if static LLVM libraries were requested, use llvm-config to generate
-                               # the list of what libraries we need, and substitute that in the right
-                               # way for LLVM_LIBRARY.
-                               execute_process(COMMAND ${LLVM_CONFIG} --libfiles
-                                               OUTPUT_VARIABLE LLVM_LIBRARY
-                                               OUTPUT_STRIP_TRAILING_WHITESPACE)
-                               string(REPLACE " " ";" LLVM_LIBRARY "${LLVM_LIBRARY}")
-                       endif()
-               else()
-                       message(FATAL_ERROR "LLVM not found.")
-               endif()
-
        endif()
 
        if(WITH_LLVM OR WITH_SDL_DYNLOAD)
diff --git a/build_files/cmake/Modules/FindLLVM.cmake b/build_files/cmake/Modules/FindLLVM.cmake
new file mode 100644 (file)
index 0000000..43791c8
--- /dev/null
@@ -0,0 +1,94 @@
+# - Find LLVM library
+# Find the native LLVM includes and library
+# This module defines
+#  LLVM_INCLUDE_DIRS, where to find LLVM.h, Set when LLVM_INCLUDE_DIR is found.
+#  LLVM_LIBRARIES, libraries to link against to use LLVM.
+#  LLVM_ROOT_DIR, The base directory to search for LLVM.
+#                This can also be an environment variable.
+#  LLVM_FOUND, If false, do not try to use LLVM.
+#
+# also defined, but not for general use are
+#  LLVM_LIBRARY, where to find the LLVM library.
+
+#=============================================================================
+# Copyright 2015 Blender Foundation.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+
+if(LLVM_ROOT_DIR)
+       if(DEFINED LLVM_VERSION)
+               find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION} HINTS ${LLVM_ROOT_DIR}/bin NO_CMAKE_PATH)
+       endif()
+       if(NOT LLVM_CONFIG)
+               find_program(LLVM_CONFIG llvm-config HINTS ${LLVM_ROOT_DIR}/bin NO_CMAKE_PATH)
+       endif()
+else()
+       if(DEFINED LLVM_VERSION)
+        message(running llvm-config-${LLVM_VERSION})
+               find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION})
+       endif()
+       if(NOT LLVM_CONFIG)
+               find_program(LLVM_CONFIG llvm-config)
+       endif()
+endif()
+
+if(NOT DEFINED LLVM_VERSION)
+       execute_process(COMMAND ${LLVM_CONFIG} --version
+                                       OUTPUT_VARIABLE LLVM_VERSION
+                                       OUTPUT_STRIP_TRAILING_WHITESPACE)
+       set(LLVM_VERSION ${LLVM_VERSION} CACHE STRING "Version of LLVM to use")
+endif()
+if(NOT LLVM_ROOT_DIR)
+       execute_process(COMMAND ${LLVM_CONFIG} --prefix
+                                       OUTPUT_VARIABLE LLVM_ROOT_DIR
+                                       OUTPUT_STRIP_TRAILING_WHITESPACE)
+       set(LLVM_ROOT_DIR ${LLVM_ROOT_DIR} CACHE PATH "Path to the LLVM installation")
+endif()
+if(NOT LLVM_LIBPATH)
+       execute_process(COMMAND ${LLVM_CONFIG} --libdir
+                                       OUTPUT_VARIABLE LLVM_LIBPATH
+                                       OUTPUT_STRIP_TRAILING_WHITESPACE)
+       set(LLVM_LIBPATH ${LLVM_LIBPATH} CACHE PATH "Path to the LLVM library path")
+       mark_as_advanced(LLVM_LIBPATH)
+endif()
+
+if(LLVM_STATIC)
+       find_library(LLVM_LIBRARY
+                    NAMES LLVMAnalysis # first of a whole bunch of libs to get
+                    PATHS ${LLVM_LIBPATH})
+else()
+       find_library(LLVM_LIBRARY
+                    NAMES LLVM-${LLVM_VERSION}
+                    PATHS ${LLVM_LIBPATH})
+endif()
+
+
+if(LLVM_LIBRARY AND LLVM_ROOT_DIR AND LLVM_LIBPATH)
+       if(LLVM_STATIC)
+               # if static LLVM libraries were requested, use llvm-config to generate
+               # the list of what libraries we need, and substitute that in the right
+               # way for LLVM_LIBRARY.
+               execute_process(COMMAND ${LLVM_CONFIG} --libfiles
+                               OUTPUT_VARIABLE LLVM_LIBRARY
+                               OUTPUT_STRIP_TRAILING_WHITESPACE)
+               string(REPLACE " " ";" LLVM_LIBRARY "${LLVM_LIBRARY}")
+       endif()
+endif()
+
+
+# handle the QUIETLY and REQUIRED arguments and set SDL2_FOUND to TRUE if
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LLVM DEFAULT_MSG
+    LLVM_LIBRARY)
+
+MARK_AS_ADVANCED(
+  LLVM_LIBRARY
+)
+