Warning, /sdk/clazy/cmake/FindClang.cmake is written in an unsupported language. File is not indexed.

0001 # Detect Clang libraries
0002 #
0003 # Defines the following variables:
0004 #  CLANG_FOUND                 - True if Clang was found
0005 #  CLANG_INCLUDE_DIRS          - Where to find Clang includes
0006 #  CLANG_LIBRARY_DIRS          - Where to find Clang libraries
0007 #
0008 #  CLANG_LIBCLANG_LIB          - Libclang C library
0009 #
0010 #  CLANG_CLANGFRONTEND_LIB     - Clang Frontend (C++) Library
0011 #  CLANG_CLANGDRIVER_LIB       - Clang Driver (C++) Library
0012 #  ...
0013 #
0014 #  CLANG_LIBS                  - All the Clang C++ libraries
0015 #
0016 # Uses the same include and library paths detected by FindLLVM.cmake
0017 #
0018 # See http://clang.llvm.org/docs/InternalsManual.html for full list of libraries
0019 
0020 #=============================================================================
0021 # Copyright 2014-2015 Kevin Funk <kfunk@kde.org>
0022 #
0023 # Redistribution and use in source and binary forms, with or without
0024 # modification, are permitted provided that the following conditions
0025 # are met:
0026 #
0027 # 1. Redistributions of source code must retain the above copyright
0028 # notice, this list of conditions and the following disclaimer.
0029 # 2. Redistributions in binary form must reproduce the above copyright
0030 # notice, this list of conditions and the following disclaimer in the
0031 # documentation and/or other materials provided with the distribution.
0032 #
0033 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0034 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0035 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0036 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0037 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0038 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0039 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0040 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0041 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0042 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0043 #=============================================================================
0044 
0045 if (${Clang_FIND_REQUIRED})
0046     find_package(LLVM ${Clang_FIND_VERSION} REQUIRED)
0047 else ()
0048     find_package(LLVM ${Clang_FIND_VERSION})
0049 endif ()
0050 
0051 set(CLANG_FOUND FALSE)
0052 
0053 if (LLVM_FOUND AND LLVM_LIBRARY_DIRS)
0054   macro(FIND_CLANG_LIB _libname_)
0055     string(TOUPPER ${_libname_} _prettylibname_)
0056     find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_} HINTS ${LLVM_LIBRARY_DIRS})
0057   endmacro(FIND_CLANG_LIB)
0058   macro(FIND_AND_ADD_CLANG_LIB _libname_)
0059     string(TOUPPER ${_libname_} _prettylibname_)
0060     find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_} HINTS ${LLVM_LIBRARY_DIRS})
0061     if(CLANG_${_prettylibname_}_LIB)
0062       set(CLANG_LIBS ${CLANG_LIBS} ${CLANG_${_prettylibname_}_LIB})
0063     endif()
0064   endmacro(FIND_AND_ADD_CLANG_LIB)
0065 
0066   # note: On Windows there's 'libclang.dll' instead of 'clang.dll' -> search for 'libclang', too
0067   find_library(CLANG_LIBCLANG_LIB NAMES clang libclang HINTS ${LLVM_LIBRARY_DIRS}) # LibClang: high-level C interface
0068 
0069   FIND_CLANG_LIB(clang-cpp)
0070   FIND_AND_ADD_CLANG_LIB(clangFrontend)
0071   FIND_AND_ADD_CLANG_LIB(clangDriver)
0072   FIND_AND_ADD_CLANG_LIB(clangCodeGen)
0073   FIND_AND_ADD_CLANG_LIB(clangSema)
0074   FIND_AND_ADD_CLANG_LIB(clangChecker)
0075   FIND_AND_ADD_CLANG_LIB(clangAnalysis)
0076   FIND_AND_ADD_CLANG_LIB(clangRewriteFrontend)
0077   FIND_AND_ADD_CLANG_LIB(clangRewrite)
0078   FIND_AND_ADD_CLANG_LIB(clangAST)
0079   FIND_AND_ADD_CLANG_LIB(clangASTMatchers)
0080   FIND_AND_ADD_CLANG_LIB(clangParse)
0081   FIND_AND_ADD_CLANG_LIB(clangLex)
0082   FIND_AND_ADD_CLANG_LIB(clangBasic)
0083   FIND_AND_ADD_CLANG_LIB(clangARCMigrate)
0084   FIND_AND_ADD_CLANG_LIB(clangEdit)
0085   FIND_AND_ADD_CLANG_LIB(clangFrontendTool)
0086   FIND_AND_ADD_CLANG_LIB(clangRewrite)
0087   FIND_AND_ADD_CLANG_LIB(clangSerialization)
0088   FIND_AND_ADD_CLANG_LIB(clangTooling)
0089   FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerCheckers)
0090   FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerCore)
0091   FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerFrontend)
0092   FIND_AND_ADD_CLANG_LIB(clangSema)
0093   FIND_AND_ADD_CLANG_LIB(clangRewriteCore)
0094 endif()
0095 
0096 if(CLANG_LIBS OR CLANG_LIBCLANG_LIB OR CLANG_CLANG-CPP_LIB)
0097   set(CLANG_FOUND TRUE)
0098 else()
0099   message(STATUS "Could not find any Clang libraries in ${LLVM_LIBRARY_DIRS}")
0100 endif()
0101 
0102 if(CLANG_FOUND)
0103   set(CLANG_LIBRARY_DIRS ${LLVM_LIBRARY_DIRS})
0104   set(CLANG_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS})
0105 
0106   # check whether llvm-config comes from an install prefix
0107   execute_process(
0108     COMMAND ${LLVM_CONFIG_EXECUTABLE} --src-root
0109     OUTPUT_VARIABLE _llvmSourceRoot
0110     OUTPUT_STRIP_TRAILING_WHITESPACE
0111   )
0112   string(FIND "${LLVM_INCLUDE_DIRS}" "${_llvmSourceRoot}" _llvmIsInstalled)
0113   if (NOT _llvmIsInstalled)
0114     message(STATUS "Detected that llvm-config comes from a build-tree, adding more include directories for Clang")
0115     list(APPEND CLANG_INCLUDE_DIRS
0116          "${LLVM_INSTALL_PREFIX}/tools/clang/include" # build dir
0117          "${_llvmSourceRoot}/tools/clang/include"     # source dir
0118     )
0119   endif()
0120 
0121   message(STATUS "Found Clang (LLVM version: ${LLVM_VERSION})")
0122   message(STATUS "  Include dirs:          ${CLANG_INCLUDE_DIRS}")
0123   message(STATUS "  Clang libraries:       ${CLANG_LIBS}")
0124   message(STATUS "  Libclang C library:    ${CLANG_LIBCLANG_LIB}")
0125   message(STATUS "  Clang dynamic library: ${CLANG_CLANG-CPP_LIB}")
0126 else()
0127   if(Clang_FIND_REQUIRED)
0128     message(FATAL_ERROR "Could NOT find Clang")
0129   endif()
0130 endif()