forked from Andersbakken/rtags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindLibClang.cmake
72 lines (65 loc) · 3 KB
/
FindLibClang.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
if(NOT DEFINED CLANG_ROOT)
set(CLANG_ROOT $ENV{CLANG_ROOT})
endif()
find_path(CLANG_INCLUDE clang-c/Index.h
HINTS
${CLANG_ROOT}/include
/opt/local/libexec/llvm-3.3/include
/opt/local/libexec/llvm-3.2/include
/opt/local/libexec/llvm-3.1/include
/opt/local/libexec/llvm-3.0/include
NO_DEFAULT_PATH)
if (NOT EXISTS ${CLANG_INCLUDE})
find_path(CLANG_INCLUDE clang-c/Index.h)
endif ()
if (EXISTS ${CLANG_INCLUDE})
if ("${CLANG_ROOT}" STREQUAL "")
string(REGEX REPLACE "\\/include" "" CLANG_ROOT ${CLANG_INCLUDE})
endif()
endif()
if (EXISTS "${CLANG_ROOT}/lib/libclang.so")
set(CLANG_LIBS "${CLANG_ROOT}/lib/libclang.so")
elseif (EXISTS "${CLANG_ROOT}/lib/libclang.dylib")
set(CLANG_LIBS "${CLANG_ROOT}/lib/libclang.dylib")
else ()
find_library(CLANG_LIBS NAMES clang HINTS ${CLANG_ROOT}/lib/ ${CLANG_ROOT}/lib64/llvm/)
endif()
if (EXISTS "${CLANG_INCLUDE}/clang/Basic/Version.inc")
file(READ "${CLANG_INCLUDE}/clang/Basic/Version.inc" CLANG_VERSION_DATA)
string(REGEX REPLACE ";" "\\\\;" CLANG_VERSION_DATA ${CLANG_VERSION_DATA})
string(REGEX REPLACE "\n" ";" CLANG_VERSION_DATA ${CLANG_VERSION_DATA})
foreach (line ${CLANG_VERSION_DATA})
string(REGEX REPLACE "^#define CLANG_VERSION ([0-9]+\\.[0-9]+)$" "\\1" CLANG_VERSION_STRING ${line})
if (DEFINED CLANG_VERSION_STRING)
string(REGEX REPLACE "^([0-9]+)\\.[0-9]+$" "\\1" CLANG_VERSION_MAJOR ${CLANG_VERSION_STRING})
string(REGEX REPLACE "^[0-9]+\\.([0-9]+)$" "\\1" CLANG_VERSION_MINOR ${CLANG_VERSION_STRING})
if (NOT ${CLANG_VERSION_MAJOR} STREQUAL "" AND NOT ${CLANG_VERSION_MINOR} STREQUAL "")
set(CLANG_VERSION "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}")
break()
endif ()
endif ()
endforeach ()
endif ()
if ("${CLANG_VERSION}" STREQUAL "")
message(FATAL_ERROR "Unable to parse ClangVersion from ${CLANG_INCLUDE}/clang/Basic/Version.inc")
endif ()
message("Using Clang version ${CLANG_VERSION} from ${CLANG_INCLUDE}/clang-c/")
if (EXISTS "${CLANG_INCLUDE}/clang/${CLANG_VERSION}/include/limits.h")
set(CLANG_SYSTEM_INCLUDE "${CLANG_INCLUDE}/clang/${CLANG_VERSION}/include/")
else ()
set(CLANG_SYSTEM_INCLUDE ${CLANG_LIBS})
string(REGEX REPLACE "\\/libclang\\.[dylibso]+$" "" CLANG_SYSTEM_INCLUDE ${CLANG_SYSTEM_INCLUDE})
if (EXISTS "${CLANG_SYSTEM_INCLUDE}/clang/${CLANG_VERSION}/include/limits.h")
set(CLANG_SYSTEM_INCLUDE "${CLANG_SYSTEM_INCLUDE}/clang/${CLANG_VERSION}/include/")
else ()
set(CLANG_SYSTEM_INCLUDE "")
if (EXISTS "${CLANG_ROOT}/lib/clang/${CLANG_VERSION}/include/limits.h")
set(CLANG_SYSTEM_INCLUDE "${CLANG_ROOT}/lib/clang/${CLANG_VERSION}/include/")
else ()
message(FATAL_ERROR "Couldn't find limits.h in either ${CLANG_INCLUDE}/clang/${CLANG_VERSION}/include/ or ${CLANG_SYSTEM_INCLUDE}/clang/${CLANG_VERSION}/include/")
endif ()
endif ()
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CLANG DEFAULT_MSG CLANG_LIBS CLANG_INCLUDE)
mark_as_advanced(CLANG_INCLUDE CLANG_LIBS)