Lines 1-152
Link Here
|
1 |
# Detect Clang libraries |
|
|
2 |
# |
3 |
# Defines the following variables: |
4 |
# CLANG_FOUND - True if Clang was found |
5 |
# CLANG_INCLUDE_DIRS - Where to find Clang includes |
6 |
# CLANG_LIBRARY_DIRS - Where to find Clang libraries |
7 |
# CLANG_BUILTIN_DIR - Where to find Clang builtin includes |
8 |
# |
9 |
# CLANG_CLANG_LIB - Libclang C library |
10 |
# |
11 |
# CLANG_CLANGFRONTEND_LIB - Clang Frontend (C++) Library |
12 |
# CLANG_CLANGDRIVER_LIB - Clang Driver (C++) Library |
13 |
# ... |
14 |
# |
15 |
# CLANG_LIBS - All the Clang C++ libraries |
16 |
# |
17 |
# Uses the same include and library paths detected by FindLLVM.cmake |
18 |
# |
19 |
# See https://clang.llvm.org/docs/InternalsManual.html for full list of libraries |
20 |
|
21 |
#============================================================================= |
22 |
# SPDX-FileCopyrightText: 2014-2015 Kevin Funk <kfunk@kde.org> |
23 |
# |
24 |
# SPDX-License-Identifier: BSD-3-Clause |
25 |
#============================================================================= |
26 |
|
27 |
set(KNOWN_VERSIONS 14 13 12 11 10 9 8 7 6.0 5.0 4.0 3.9 3.8) |
28 |
|
29 |
foreach(version ${KNOWN_VERSIONS}) |
30 |
if(LLVM_FOUND OR (DEFINED Clang_FIND_VERSION AND Clang_FIND_VERSION VERSION_GREATER version)) |
31 |
# already found or version doesn't match |
32 |
break() |
33 |
endif() |
34 |
|
35 |
find_package(LLVM ${version} QUIET) |
36 |
endforeach() |
37 |
|
38 |
if (${Clang_FIND_REQUIRED}) |
39 |
if(NOT DEFINED Clang_FIND_VERSION) |
40 |
message(SEND_ERROR "Could not find Clang.") |
41 |
else() |
42 |
message("Found version ${Clang_FIND_VERSION}") |
43 |
endif() |
44 |
endif() |
45 |
|
46 |
set(CLANG_FOUND FALSE) |
47 |
|
48 |
if (LLVM_FOUND AND LLVM_LIBRARY_DIRS) |
49 |
macro(FIND_AND_ADD_CLANG_LIB _libname_) |
50 |
string(TOUPPER ${_libname_} _prettylibname_) |
51 |
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_} HINTS ${LLVM_LIBRARY_DIRS} ${ARGN}) |
52 |
if (CLANG_${_prettylibname_}_LIB) |
53 |
set(CLANG_LIBS ${CLANG_LIBS} ${CLANG_${_prettylibname_}_LIB}) |
54 |
endif() |
55 |
endmacro(FIND_AND_ADD_CLANG_LIB) |
56 |
|
57 |
FIND_AND_ADD_CLANG_LIB(clangFrontend) |
58 |
|
59 |
# note: On Windows there's 'libclang.dll' instead of 'clang.dll' -> search for 'libclang', too |
60 |
FIND_AND_ADD_CLANG_LIB(clang NAMES clang libclang) # LibClang: high-level C interface |
61 |
|
62 |
FIND_AND_ADD_CLANG_LIB(clangDriver) |
63 |
FIND_AND_ADD_CLANG_LIB(clangCodeGen) |
64 |
FIND_AND_ADD_CLANG_LIB(clangSema) |
65 |
FIND_AND_ADD_CLANG_LIB(clangChecker) |
66 |
FIND_AND_ADD_CLANG_LIB(clangAnalysis) |
67 |
FIND_AND_ADD_CLANG_LIB(clangRewriteFrontend) |
68 |
FIND_AND_ADD_CLANG_LIB(clangRewrite) |
69 |
FIND_AND_ADD_CLANG_LIB(clangAST) |
70 |
FIND_AND_ADD_CLANG_LIB(clangParse) |
71 |
FIND_AND_ADD_CLANG_LIB(clangLex) |
72 |
FIND_AND_ADD_CLANG_LIB(clangBasic) |
73 |
FIND_AND_ADD_CLANG_LIB(clangARCMigrate) |
74 |
FIND_AND_ADD_CLANG_LIB(clangEdit) |
75 |
FIND_AND_ADD_CLANG_LIB(clangFrontendTool) |
76 |
FIND_AND_ADD_CLANG_LIB(clangSerialization) |
77 |
FIND_AND_ADD_CLANG_LIB(clangTooling) |
78 |
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerCheckers) |
79 |
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerCore) |
80 |
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerFrontend) |
81 |
FIND_AND_ADD_CLANG_LIB(clangRewriteCore) |
82 |
endif() |
83 |
|
84 |
if(CLANG_LIBS OR CLANG_CLANG_LIB) |
85 |
set(CLANG_FOUND TRUE) |
86 |
else() |
87 |
message(STATUS "Could not find any Clang libraries in ${LLVM_LIBRARY_DIRS}") |
88 |
endif() |
89 |
|
90 |
if(CLANG_FOUND) |
91 |
set(CLANG_LIBRARY_DIRS ${LLVM_LIBRARY_DIRS}) |
92 |
set(CLANG_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS}) |
93 |
set(CLANG_VERSION ${LLVM_VERSION}) |
94 |
|
95 |
# svn version of clang has a svn suffix "8.0.0svn" but installs the header in "8.0.0", without the suffix |
96 |
string(REPLACE "svn" "" CLANG_VERSION_CLEAN "${CLANG_VERSION}") |
97 |
# dito for git |
98 |
string(REPLACE "git" "" CLANG_VERSION_CLEAN "${CLANG_VERSION}") |
99 |
|
100 |
find_path(CLANG_BUILTIN_DIR |
101 |
# cpuid.h because it is defined in ClangSupport constructor as valid clang builtin dir indicator |
102 |
NAMES "cpuid.h" |
103 |
PATHS "${CLANG_LIBRARY_DIRS}" |
104 |
"${CLANG_INCLUDE_DIRS}" |
105 |
PATH_SUFFIXES "clang/${CLANG_VERSION}/include" |
106 |
"../../../clang/${CLANG_VERSION}/include" |
107 |
"clang/${CLANG_VERSION_CLEAN}/include" |
108 |
"../../../clang/${CLANG_VERSION_CLEAN}/include" |
109 |
NO_DEFAULT_PATH |
110 |
) |
111 |
|
112 |
if (NOT CLANG_BUILTIN_DIR) |
113 |
message(FATAL_ERROR "Could not find Clang builtin directory") |
114 |
endif() |
115 |
get_filename_component(CLANG_BUILTIN_DIR ${CLANG_BUILTIN_DIR} ABSOLUTE) |
116 |
|
117 |
# check whether llvm-config comes from an install prefix |
118 |
execute_process( |
119 |
COMMAND ${LLVM_CONFIG_EXECUTABLE} --src-root |
120 |
OUTPUT_VARIABLE _llvmSourceRoot |
121 |
OUTPUT_STRIP_TRAILING_WHITESPACE |
122 |
) |
123 |
string(FIND "${LLVM_INCLUDE_DIRS}" "${_llvmSourceRoot}" _llvmIsInstalled) |
124 |
if (NOT _llvmIsInstalled) |
125 |
message(STATUS "Detected that llvm-config comes from a build-tree, adding more include directories for Clang") |
126 |
list(APPEND CLANG_INCLUDE_DIRS |
127 |
"${LLVM_INSTALL_PREFIX}/tools/clang/include" # build dir |
128 |
) |
129 |
|
130 |
# check whether the source is from llvm-project.git (currently recommended way to clone the LLVM projects) |
131 |
# contains all LLVM projects in the top-level directory |
132 |
get_filename_component(_llvmProjectClangIncludeDir ${_llvmSourceRoot}/../clang/include REALPATH) |
133 |
if (EXISTS ${_llvmProjectClangIncludeDir}) |
134 |
message(STATUS " Note: llvm-project.git structure detected, using different include path pointing into source dir") |
135 |
list(APPEND CLANG_INCLUDE_DIRS "${_llvmProjectClangIncludeDir}") # source dir |
136 |
else() |
137 |
list(APPEND CLANG_INCLUDE_DIRS "${_llvmSourceRoot}/tools/clang/include") # source dir |
138 |
endif() |
139 |
endif() |
140 |
|
141 |
if(NOT Clang_FIND_QUIETLY) |
142 |
message(STATUS "Found Clang (LLVM version: ${CLANG_VERSION})") |
143 |
message(STATUS " Include dirs: ${CLANG_INCLUDE_DIRS}") |
144 |
message(STATUS " Clang libraries: ${CLANG_LIBS}") |
145 |
message(STATUS " Libclang C library: ${CLANG_CLANG_LIB}") |
146 |
message(STATUS " Builtin include dir: ${CLANG_BUILTIN_DIR}") |
147 |
endif() |
148 |
else() |
149 |
if(Clang_FIND_REQUIRED) |
150 |
message(FATAL_ERROR "Could NOT find Clang") |
151 |
endif() |
152 |
endif() |