-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathClangLLVM.cmake
81 lines (72 loc) · 1.98 KB
/
ClangLLVM.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
81
# LLVM related stuff (XXX Do we actually need LLVM?)
find_package(
LLVM
REQUIRED
CONFIG
)
# Clang related stuff
find_package(
Clang
REQUIRED
CONFIG
)
# Test if the LLVM major version is one of the allowed ones
function(test_llvm_major_version version_string)
# List of all supported major LLVM versions
set(supported_llvm_versions
10
13
14
15
16
17
18
)
# Set to indicate after loop if supported version was found
set(valid_version FALSE)
if(${version_string}
IN_LIST
supported_llvm_versions
)
message(STATUS "Supported LLVM Found! Version ${version_string}")
set(valid_version TRUE)
endif()
if(NOT ${valid_version})
message(WARNING "Support for LLVM Version ${version_string} is not tested! Proceed with care.")
message(WARNING "LLVM/Clang version 10, 13, 14, 15, 16, 17, 18 are supported and tested")
endif()
endfunction()
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message(STATUS "Using ClangConfig.cmake in: ${Clang_DIR}")
# Check for LLVM compatibility
test_llvm_major_version(${LLVM_VERSION_MAJOR})
function(add_clang target)
# clang specified as system lib to suppress all warnings from clang headers
target_include_directories(${target} SYSTEM PUBLIC ${CLANG_INCLUDE_DIRS})
# Try clang-cpp first, fallback to individual libs
find_library(
CLANG_CPP_LIB clang-cpp
PATHS ${LLVM_LIBRARY_DIR}
NO_DEFAULT_PATH
)
if(CLANG_CPP_LIB)
target_link_libraries(${target} PUBLIC clang-cpp)
else()
target_link_libraries(
${target}
PUBLIC clangTooling
clangFrontend
clangSerialization
clangAST
clangBasic
clangIndex
)
endif()
if(LLVM_LINK_LLVM_DYLIB)
target_link_libraries(${target} PUBLIC LLVM)
else()
llvm_map_components_to_libnames(llvm_libs support)
target_link_libraries(${target} PUBLIC ${llvm_libs})
endif()
endfunction()