1set(SOURCES 2 ARCMigrate.cpp 3 BuildSystem.cpp 4 CIndex.cpp 5 CIndexCXX.cpp 6 CIndexCodeCompletion.cpp 7 CIndexDiagnostic.cpp 8 CIndexHigh.cpp 9 CIndexInclusionStack.cpp 10 CIndexUSRs.cpp 11 CIndexer.cpp 12 CXComment.cpp 13 CXCursor.cpp 14 CXIndexDataConsumer.cpp 15 CXCompilationDatabase.cpp 16 CXLoadedDiagnostic.cpp 17 CXSourceLocation.cpp 18 CXStoredDiagnostic.cpp 19 CXString.cpp 20 CXType.cpp 21 Indexing.cpp 22 FatalErrorHandler.cpp 23 Rewrite.cpp 24 25 ADDITIONAL_HEADERS 26 CIndexDiagnostic.h 27 CIndexer.h 28 CXCursor.h 29 CXLoadedDiagnostic.h 30 CXSourceLocation.h 31 CXString.h 32 CXTranslationUnit.h 33 CXType.h 34 Index_Internal.h 35 ../../include/clang-c/Index.h 36 ) 37 38set(LIBS 39 clangAST 40 clangBasic 41 clangDriver 42 clangFrontend 43 clangIndex 44 clangLex 45 clangRewrite 46 clangSema 47 clangSerialization 48 clangTooling 49) 50 51if (CLANG_ENABLE_ARCMT) 52 list(APPEND LIBS clangARCMigrate) 53endif () 54 55option(LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA 56 "Include code from clang-tools-extra in libclang." OFF) 57 58if (LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA) 59 if (TARGET clangTidyPlugin) 60 add_definitions(-DCLANG_TOOL_EXTRA_BUILD) 61 list(APPEND LIBS clangTidyPlugin) 62 list(APPEND LIBS clangIncludeFixerPlugin) 63 if(LLVM_ENABLE_MODULES) 64 list(APPEND LLVM_COMPILE_FLAGS "-fmodules-ignore-macro=CLANG_TOOL_EXTRA_BUILD") 65 endif() 66 else () 67 message(FATAL_ERROR "LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA needs clang-tools-extra in LLVM_ENABLE_PROJECTS") 68 endif () 69endif () 70 71if (HAVE_LIBDL) 72 list(APPEND LIBS ${CMAKE_DL_LIBS}) 73elseif (CLANG_BUILT_STANDALONE) 74 find_library(DL_LIBRARY_PATH dl) 75 if (DL_LIBRARY_PATH) 76 list(APPEND LIBS dl) 77 endif () 78endif () 79 80option(LIBCLANG_BUILD_STATIC 81 "Build libclang as a static library (in addition to a shared one)" OFF) 82 83set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libclang.exports) 84 85if(MSVC) 86 # Avoid LNK4197 by not specifying libclang.exports here. 87 # Each functions is exported as "dllexport" in include/clang-c. 88 # KB835326 89 set(LLVM_EXPORTED_SYMBOL_FILE) 90endif() 91 92if(LLVM_ENABLE_PIC OR (WIN32 AND NOT LIBCLANG_BUILD_STATIC)) 93 set(ENABLE_SHARED SHARED) 94endif() 95 96if(NOT LLVM_ENABLE_PIC OR LIBCLANG_BUILD_STATIC) 97 set(ENABLE_STATIC STATIC) 98endif() 99 100if (MSVC AND ENABLE_SHARED AND ENABLE_STATIC) 101 unset(ENABLE_STATIC) 102endif() 103 104if(MSVC) 105 set(output_name "libclang") 106else() 107 set(output_name "clang") 108endif() 109 110# libclang requires headers which need _ALL_SOURCE to build on AIX 111if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX") 112 remove_definitions("-D_XOPEN_SOURCE=700") 113endif() 114 115add_clang_library(libclang ${ENABLE_SHARED} ${ENABLE_STATIC} INSTALL_WITH_TOOLCHAIN 116 OUTPUT_NAME ${output_name} 117 ${SOURCES} 118 119 DEPENDS 120 ClangDriverOptions 121 clang-resource-headers 122 123 LINK_LIBS 124 ${LIBS} 125 126 LINK_COMPONENTS 127 ${LLVM_TARGETS_TO_BUILD} 128 Core 129 Support 130 ) 131 132if(ENABLE_STATIC) 133 foreach(name libclang obj.libclang libclang_static) 134 if (TARGET ${name}) 135 target_compile_definitions(${name} PUBLIC CINDEX_NO_EXPORTS) 136 endif() 137 endforeach() 138endif() 139 140if(ENABLE_SHARED) 141 if(WIN32) 142 set_target_properties(libclang 143 PROPERTIES 144 VERSION ${LIBCLANG_LIBRARY_VERSION} 145 DEFINE_SYMBOL _CINDEX_LIB_) 146 elseif(APPLE) 147 set(LIBCLANG_LINK_FLAGS " -Wl,-compatibility_version -Wl,1") 148 set(LIBCLANG_LINK_FLAGS "${LIBCLANG_LINK_FLAGS} -Wl,-current_version -Wl,${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}") 149 150 set_property(TARGET libclang APPEND_STRING PROPERTY 151 LINK_FLAGS ${LIBCLANG_LINK_FLAGS}) 152 else() 153 set_target_properties(libclang 154 PROPERTIES 155 VERSION ${LIBCLANG_LIBRARY_VERSION} 156 DEFINE_SYMBOL _CINDEX_LIB_) 157 # FIXME: _CINDEX_LIB_ affects dllexport/dllimport on Win32. 158 if(LLVM_ENABLE_MODULES AND NOT WIN32) 159 target_compile_options(libclang PRIVATE 160 "-fmodules-ignore-macro=_CINDEX_LIB_" 161 ) 162 endif() 163 endif() 164endif() 165 166if(INTERNAL_INSTALL_PREFIX) 167 set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${INTERNAL_INSTALL_PREFIX}/include") 168else() 169 set(LIBCLANG_HEADERS_INSTALL_DESTINATION include) 170endif() 171 172install(DIRECTORY ../../include/clang-c 173 COMPONENT libclang-headers 174 DESTINATION "${LIBCLANG_HEADERS_INSTALL_DESTINATION}" 175 FILES_MATCHING 176 PATTERN "*.h" 177 ) 178 179# LLVM_DISTRIBUTION_COMPONENTS requires that each component have both a 180# component and an install-component target, so add a dummy libclang-headers 181# target to allow using it in LLVM_DISTRIBUTION_COMPONENTS. 182add_custom_target(libclang-headers) 183set_target_properties(libclang-headers PROPERTIES FOLDER "Misc") 184 185if (NOT LLVM_ENABLE_IDE) 186 add_llvm_install_targets(install-libclang-headers 187 COMPONENT libclang-headers) 188endif() 189 190# Create a target to install the python bindings to make them easier to 191# distribute. Since the bindings are over libclang, which is installed 192# unbundled to the clang version, follow suit. 193foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS}) 194 install(DIRECTORY 195 ${CMAKE_CURRENT_SOURCE_DIR}/../../bindings/python/clang 196 COMPONENT 197 libclang-python-bindings 198 DESTINATION 199 "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") 200endforeach() 201if(NOT LLVM_ENABLE_IDE) 202 add_custom_target(libclang-python-bindings) 203 add_llvm_install_targets(install-libclang-python-bindings 204 COMPONENT 205 libclang-python-bindings) 206endif() 207 208