Factored out LLVM detection into separate CMake module.

This commit is contained in:
David Nadlinger
2011-11-12 17:47:11 +01:00
parent 6e714f999e
commit bafe9c8e03
2 changed files with 91 additions and 56 deletions

View File

@@ -0,0 +1,73 @@
# - Find LLVM headers and libraries.
# This module locates LLVM and adapts the llvm-config output for use with
# CMake.
#
# A given list of COMPONENTS is passed to llvm-config.
#
# The following variables are defined:
# LLVM_FOUND - true if LLVM was found
# LLVM_CXXFLAGS - C++ compiler flags for files that include LLVM headers.
# LLVM_HOST_TARGET - Target triple used to configure LLVM.
# LLVM_INCLUDE_DIRS - Directory containing LLVM include files.
# LLVM_LDFLAGS - Linker flags to add when linking against LLVM
# (includes -LLLVM_LIBRARY_DIRS).
# LLVM_LIBRARIES - Full paths to the library files to link against.
# LLVM_LIBRARY_DIRS - Directory containing LLVM libraries.
# LLVM_ROOT_DIR - The root directory of the LLVM installation.
# llvm-config is searched for in ${LLVM_ROOT_DIR}/bin.
# LLVM_VERSION_MAJOR - Major version of LLVM.
# LLVM_VERSION_MINOR - Minor version of LLVM.
# LLVM_VERSION_STRING - Full LLVM version string (e.g. 2.9).
#
# Note: The variable names were chosen in conformance with the offical CMake
# guidelines, see ${CMAKE_ROOT}/Modules/readme.txt.
find_program(LLVM_CONFIG llvm-config ${LLVM_ROOT_DIR}/bin
DOC "Path to llvm-config tool.")
if (NOT LLVM_CONFIG)
if (NOT FIND_LLVM_QUIETLY)
message(WARNING "Could not find llvm-config. Consider manually setting LLVM_ROOT_DIR.")
endif()
else()
# llvm-config is written in Perl, thus we need to locate it first.
if(LLVM_FIND_QUIETLY)
set(_quiet_arg QUIET)
endif()
find_package(Perl ${_quiet_arg})
if(NOT PERL_FOUND)
if (NOT FIND_LLVM_QUIETLY)
message(WARNING "Need Perl to execute llvm-config.")
endif()
else()
macro(llvm_set var flag)
if(LLVM_FIND_QUIETLY)
set(_quiet_arg ERROR_QUIET)
endif()
execute_process(
COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --${flag} ${LLVM_FIND_COMPONENTS}
OUTPUT_VARIABLE LLVM_${var}
OUTPUT_STRIP_TRAILING_WHITESPACE ${_quiet_arg}
)
endmacro()
llvm_set(CXXFLAGS cxxflags)
llvm_set(HOST_TARGET host-target)
llvm_set(INCLUDE_DIRS includedir)
llvm_set(LDFLAGS ldflags)
llvm_set(LIBRARIES libfiles)
llvm_set(LIBRARY_DIRS libdir)
llvm_set(ROOT_DIR prefix)
llvm_set(VERSION_STRING version)
endif()
endif()
string(REGEX REPLACE "([0-9]+).*" "\\1" LLVM_VERSION_MAJOR "${LLVM_VERSION_STRING}" )
string(REGEX REPLACE "[0-9]+\\.([0-9]+).*" "\\1" LLVM_VERSION_MINOR "${LLVM_VERSION_STRING}" )
# Use the default CMake facilities for handling QUIET/REQUIRED.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LLVM
REQUIRED_VARS LLVM_ROOT_DIR LLVM_HOST_TARGET
VERSION_VAR LLVM_VERSION_STRING)