-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindLLVM.cmake
81 lines (68 loc) · 3.3 KB
/
FindLLVM.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Detect LLVM and set various variable to link against the different component of LLVM
#
# NOTE: This is a modified version of the module originally found in the OpenGTL project
# at www.opengtl.org
#
# LLVM_BIN_DIR : directory with LLVM binaries
# LLVM_LIB_DIR : directory with LLVM library
# LLVM_INCLUDE_DIR : directory with LLVM include
#
# LLVM_COMPILE_FLAGS : compile flags needed to build a program using LLVM headers
# LLVM_LDFLAGS : ldflags needed to link
# LLVM_LIBS_CORE : ldflags needed to link against a LLVM core library
# LLVM_LIBS_JIT : ldflags needed to link against a LLVM JIT
# LLVM_LIBS_JIT_OBJECTS : objects you need to add to your source when using LLVM JIT
if (LLVM_INCLUDE_DIR)
set(LLVM_FOUND TRUE)
else (LLVM_INCLUDE_DIR)
find_program(LLVM_CONFIG_EXECUTABLE
NAMES llvm-config
PATHS
/opt/local/bin
)
# find_program(LLVM_GXX_EXECUTABLE
# NAMES llvm-g++ llvmg++
# PATHS
# /opt/local/bin
# )
#if (LLVM_GXX_EXECUTABLE)
# MESSAGE(STATUS "LLVM llvm-g++ found at: ${LLVM_GXX_EXECUTABLE}")
# else(LLVM_GXX_EXECUTABLE)
# MESSAGE(FATAL_ERROR "LLVM llvm-g++ is required, but not found!")
# endif(LLVM_GXX_EXECUTABLE)
MACRO(FIND_LLVM_LIBS LLVM_CONFIG_EXECUTABLE _libname_ LIB_VAR OBJECT_VAR)
exec_program( ${LLVM_CONFIG_EXECUTABLE} ARGS --libs ${_libname_} OUTPUT_VARIABLE ${LIB_VAR} )
STRING(REGEX MATCHALL "[^ ]*[.]o[ $]" ${OBJECT_VAR} ${${LIB_VAR}})
SEPARATE_ARGUMENTS(${OBJECT_VAR})
STRING(REGEX REPLACE "[^ ]*[.]o[ $]" "" ${LIB_VAR} ${${LIB_VAR}})
ENDMACRO(FIND_LLVM_LIBS)
exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --version OUTPUT_VARIABLE LLVM_STRING_VERSION )
MESSAGE(STATUS "LLVM version: " ${LLVM_STRING_VERSION})
# transform_version(LLVM_VERSION ${LLVM_STRING_VERSION})
exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --bindir OUTPUT_VARIABLE LLVM_BIN_DIR )
exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --libdir OUTPUT_VARIABLE LLVM_LIB_DIR )
# MESSAGE(STATUS "LLVM lib dir: " ${LLVM_LIB_DIR})
exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --includedir OUTPUT_VARIABLE LLVM_INCLUDE_DIR )
exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --cppflags OUTPUT_VARIABLE LLVM_COMPILE_FLAGS )
MESSAGE(STATUS "LLVM CXX flags: " ${LLVM_COMPILE_FLAGS})
exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --ldflags OUTPUT_VARIABLE LLVM_LDFLAGS )
MESSAGE(STATUS "LLVM LD flags: " ${LLVM_LDFLAGS})
exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --libs core bitreader bitwriter linker OUTPUT_VARIABLE LLVM_LIBS_CORE )
MESSAGE(STATUS "LLVM core libs: " ${LLVM_LIBS_CORE})
exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --libs support OUTPUT_VARIABLE LLVM_LIBS_SUPPORT )
MESSAGE(STATUS "LLVM support libs: " ${LLVM_LIBS_SUPPORT})
FIND_LLVM_LIBS( ${LLVM_CONFIG_EXECUTABLE} "jit native linker bitwriter" LLVM_LIBS_JIT LLVM_LIBS_JIT_OBJECTS )
#STRING(REPLACE " -lLLVMCore -lLLVMSupport -lLLVMSystem" "" LLVM_LIBS_JIT ${LLVM_LIBS_JIT})
MESSAGE(STATUS "LLVM JIT libs: " ${LLVM_LIBS_JIT})
MESSAGE(STATUS "LLVM JIT objs: " ${LLVM_LIBS_JIT_OBJECTS})
if(LLVM_INCLUDE_DIR)
set(LLVM_FOUND TRUE)
endif(LLVM_INCLUDE_DIR)
if(LLVM_FOUND)
message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIR}")
else(LLVM_FOUND)
if(LLVM_FIND_REQUIRED)
message(FATAL_ERROR "Could NOT find LLVM")
endif(LLVM_FIND_REQUIRED)
endif(LLVM_FOUND)
endif (LLVM_INCLUDE_DIR)