FindClang.cmake 2.51 KB
Newer Older
Kevin Funk's avatar
Kevin Funk committed
1
2
3
4
# Detect Clang libraries
#
# Defines the following variables:
#  CLANG_CLANG_LIB             - LibClang library
Kevin Funk's avatar
Kevin Funk committed
5
#  CLANG_CLANGFRONTEND_LIB     - Clang Frontend Library
Kevin Funk's avatar
Kevin Funk committed
6
7
8
9
10
11
12
#  CLANG_CLANGDRIVER_LIB       - Clang Driver Library
#  ...
#
# Uses the same include and library paths detected by FindLLVM.cmake
#
# See http://clang.llvm.org/docs/InternalsManual.html for full list of libraries

Kevin Funk's avatar
Kevin Funk committed
13
14
15
16
17
18
19
20
21
22
23
#=============================================================================
# Copyright 2014 Kevin Funk <kevin@kfunk.org>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================

Kevin Funk's avatar
Kevin Funk committed
24
25
find_package(LLVM ${Clang_FIND_VERSION} REQUIRED)

26
if (NOT LLVM_INCLUDE_DIR OR NOT LLVM_LIBRARY_DIR)
Kevin Funk's avatar
Kevin Funk committed
27
  message(FATAL_ERROR "Could not detect LLVM")
Kevin Funk's avatar
Kevin Funk committed
28
else()
29

Kevin Funk's avatar
Kevin Funk committed
30
macro(FIND_AND_ADD_CLANG_LIB _libname_)
Kevin Funk's avatar
Kevin Funk committed
31
32
  string(TOUPPER ${_libname_} _prettylibname_)
  find_library(CLANG_${_prettylibname_}_LIB ${_libname_} ${LLVM_LIBRARY_DIR} ${CLANG_LIB_DIR})
Kevin Funk's avatar
Kevin Funk committed
33
  if(CLANG_${_prettylibname_}_LIB)
Kevin Funk's avatar
Kevin Funk committed
34
35
    set(CLANG_LIBS ${CLANG_LIBS} ${CLANG_${_prettylibname_}_LIB})
  endif()
Kevin Funk's avatar
Kevin Funk committed
36
endmacro(FIND_AND_ADD_CLANG_LIB)
37

Kevin Funk's avatar
Kevin Funk committed
38
FIND_AND_ADD_CLANG_LIB(clang) # LibClang: high-level C interface
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
FIND_AND_ADD_CLANG_LIB(clangFrontend)
FIND_AND_ADD_CLANG_LIB(clangDriver)
FIND_AND_ADD_CLANG_LIB(clangCodeGen)
FIND_AND_ADD_CLANG_LIB(clangSema)
FIND_AND_ADD_CLANG_LIB(clangChecker)
FIND_AND_ADD_CLANG_LIB(clangAnalysis)
FIND_AND_ADD_CLANG_LIB(clangRewrite)
FIND_AND_ADD_CLANG_LIB(clangAST)
FIND_AND_ADD_CLANG_LIB(clangParse)
FIND_AND_ADD_CLANG_LIB(clangLex)
FIND_AND_ADD_CLANG_LIB(clangBasic)
FIND_AND_ADD_CLANG_LIB(clangARCMigrate)
FIND_AND_ADD_CLANG_LIB(clangEdit)
FIND_AND_ADD_CLANG_LIB(clangFrontendTool)
FIND_AND_ADD_CLANG_LIB(clangRewrite)
FIND_AND_ADD_CLANG_LIB(clangSerialization)
FIND_AND_ADD_CLANG_LIB(clangTooling)
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerCheckers)
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerCore)
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerFrontend)
FIND_AND_ADD_CLANG_LIB(clangSema)
FIND_AND_ADD_CLANG_LIB(clangRewriteCore)

if(CLANG_LIBS)
  set(CLANG_FOUND TRUE)
Kevin Funk's avatar
Kevin Funk committed
64
endif()
65
66

if(CLANG_FOUND)
Kevin Funk's avatar
Kevin Funk committed
67
68
69
  message(STATUS "Found Clang: ${LLVM_INCLUDE_DIR}")
  message(STATUS "  Libraries: ${CLANG_LIBS}")
else()
70
  if(Clang_FIND_REQUIRED)
71
    message(FATAL_ERROR "Could NOT find Clang")
72
  endif()
Kevin Funk's avatar
Kevin Funk committed
73
endif()
74

Kevin Funk's avatar
Kevin Funk committed
75
endif()