| 1 |
# The SOVERSION should be updated only if a change is made to the libclang |
| 2 |
# ABI, and when it is updated, it should be updated to the current |
| 3 |
# LLVM_VERSION_MAJOR. |
| 4 |
# Please also see clang/tools/libclang/libclang.map |
| 5 |
|
| 6 |
# This option defaults to CLANG_FORCE_MATCHING_LIBCLANG_SOVERSION |
| 7 |
# to ON - which means that it by default matches CLANG_VERSION_MAJOR |
| 8 |
# |
| 9 |
# TODO: This should probably not be a option going forward but we |
| 10 |
# we should commit to a way to do it. But due to getting this out |
| 11 |
# in LLVM 15.x we opted for a option. |
| 12 |
set(LIBCLANG_SOVERSION_ARG) |
| 13 |
if(NOT CLANG_FORCE_MATCHING_LIBCLANG_SOVERSION) |
| 14 |
set(LIBCLANG_SOVERSION_ARG SOVERSION 13) |
| 15 |
endif() |
| 16 |
|
| 17 |
# TODO: harmonize usage of LIBCLANG_SOVERSION / LIBCLANG_LIBARY_VERSION |
| 18 |
# below; this was added under time-pressure to avoid reverting the |
| 19 |
# better default from LLVM 14 for LLVM 15.0.0-rc3, hence no time |
| 20 |
# to clean up previous inconsistencies. |
| 21 |
|
| 22 |
set(SOURCES |
| 23 |
ARCMigrate.cpp |
| 24 |
BuildSystem.cpp |
| 25 |
CIndex.cpp |
| 26 |
CIndexCXX.cpp |
| 27 |
CIndexCodeCompletion.cpp |
| 28 |
CIndexDiagnostic.cpp |
| 29 |
CIndexHigh.cpp |
| 30 |
CIndexInclusionStack.cpp |
| 31 |
CIndexUSRs.cpp |
| 32 |
CIndexer.cpp |
| 33 |
CXComment.cpp |
| 34 |
CXCursor.cpp |
| 35 |
CXExtractAPI.cpp |
| 36 |
CXIndexDataConsumer.cpp |
| 37 |
CXCompilationDatabase.cpp |
| 38 |
CXLoadedDiagnostic.cpp |
| 39 |
CXSourceLocation.cpp |
| 40 |
CXStoredDiagnostic.cpp |
| 41 |
CXString.cpp |
| 42 |
CXType.cpp |
| 43 |
Indexing.cpp |
| 44 |
FatalErrorHandler.cpp |
| 45 |
Rewrite.cpp |
| 46 |
|
| 47 |
ADDITIONAL_HEADERS |
| 48 |
CIndexDiagnostic.h |
| 49 |
CIndexer.h |
| 50 |
CXCursor.h |
| 51 |
CXLoadedDiagnostic.h |
| 52 |
CXSourceLocation.h |
| 53 |
CXString.h |
| 54 |
CXTranslationUnit.h |
| 55 |
CXType.h |
| 56 |
Index_Internal.h |
| 57 |
../../include/clang-c/Index.h |
| 58 |
) |
| 59 |
|
| 60 |
set(LIBS |
| 61 |
clangAST |
| 62 |
clangBasic |
| 63 |
clangDriver |
| 64 |
clangExtractAPI |
| 65 |
clangFrontend |
| 66 |
clangIndex |
| 67 |
clangLex |
| 68 |
clangRewrite |
| 69 |
clangSema |
| 70 |
clangSerialization |
| 71 |
clangTooling |
| 72 |
) |
| 73 |
|
| 74 |
if (CLANG_ENABLE_ARCMT) |
| 75 |
list(APPEND LIBS clangARCMigrate) |
| 76 |
endif () |
| 77 |
|
| 78 |
if (HAVE_LIBDL) |
| 79 |
list(APPEND LIBS ${CMAKE_DL_LIBS}) |
| 80 |
elseif (CLANG_BUILT_STANDALONE) |
| 81 |
find_library(DL_LIBRARY_PATH dl) |
| 82 |
if (DL_LIBRARY_PATH) |
| 83 |
list(APPEND LIBS dl) |
| 84 |
endif () |
| 85 |
endif () |
| 86 |
|
| 87 |
option(LIBCLANG_BUILD_STATIC |
| 88 |
"Build libclang as a static library (in addition to a shared one)" OFF) |
| 89 |
|
| 90 |
set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_BINARY_DIR}/libclang-generic.exports) |
| 91 |
set(LIBCLANG_VERSION_SCRIPT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libclang.map) |
| 92 |
|
| 93 |
if(MSVC) |
| 94 |
# Avoid LNK4197 by not specifying libclang.exports here. |
| 95 |
# Each functions is exported as "dllexport" in include/clang-c. |
| 96 |
# KB835326 |
| 97 |
set(LLVM_EXPORTED_SYMBOL_FILE) |
| 98 |
endif() |
| 99 |
|
| 100 |
if (UNIX AND NOT APPLE) |
| 101 |
set(LLVM_EXPORTED_SYMBOL_FILE) |
| 102 |
set(USE_VERSION_SCRIPT ${LLVM_HAVE_LINK_VERSION_SCRIPT}) |
| 103 |
endif() |
| 104 |
|
| 105 |
if (LLVM_EXPORTED_SYMBOL_FILE) |
| 106 |
add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE} |
| 107 |
COMMAND "${Python3_EXECUTABLE}" |
| 108 |
ARGS ${CMAKE_CURRENT_SOURCE_DIR}/linker-script-to-export-list.py |
| 109 |
${LIBCLANG_VERSION_SCRIPT_FILE} |
| 110 |
${LLVM_EXPORTED_SYMBOL_FILE} |
| 111 |
DEPENDS ${LIBCLANG_VERSION_SCRIPT_FILE}) |
| 112 |
endif() |
| 113 |
|
| 114 |
if(LLVM_ENABLE_PIC OR (WIN32 AND NOT LIBCLANG_BUILD_STATIC)) |
| 115 |
set(ENABLE_SHARED SHARED) |
| 116 |
endif() |
| 117 |
|
| 118 |
if(NOT LLVM_ENABLE_PIC OR LIBCLANG_BUILD_STATIC) |
| 119 |
set(ENABLE_STATIC STATIC) |
| 120 |
endif() |
| 121 |
|
| 122 |
if (MSVC AND ENABLE_SHARED AND ENABLE_STATIC) |
| 123 |
unset(ENABLE_STATIC) |
| 124 |
endif() |
| 125 |
|
| 126 |
if(MSVC) |
| 127 |
set(output_name "libclang") |
| 128 |
else() |
| 129 |
set(output_name "clang") |
| 130 |
endif() |
| 131 |
|
| 132 |
# libclang requires headers which need _ALL_SOURCE to build on AIX |
| 133 |
if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX") |
| 134 |
remove_definitions("-D_XOPEN_SOURCE=700") |
| 135 |
endif() |
| 136 |
|
| 137 |
add_clang_library(libclang ${ENABLE_SHARED} ${ENABLE_STATIC} INSTALL_WITH_TOOLCHAIN |
| 138 |
OUTPUT_NAME ${output_name} |
| 139 |
${SOURCES} |
| 140 |
|
| 141 |
DEPENDS |
| 142 |
ClangDriverOptions |
| 143 |
clang-resource-headers |
| 144 |
|
| 145 |
LINK_LIBS |
| 146 |
${LIBS} |
| 147 |
|
| 148 |
LINK_COMPONENTS |
| 149 |
${LLVM_TARGETS_TO_BUILD} |
| 150 |
Core |
| 151 |
Support |
| 152 |
TargetParser |
| 153 |
) |
| 154 |
|
| 155 |
if(ENABLE_STATIC) |
| 156 |
foreach(name libclang obj.libclang libclang_static) |
| 157 |
if (TARGET ${name}) |
| 158 |
target_compile_definitions(${name} PUBLIC CINDEX_NO_EXPORTS) |
| 159 |
endif() |
| 160 |
endforeach() |
| 161 |
endif() |
| 162 |
|
| 163 |
if(ENABLE_SHARED) |
| 164 |
if(WIN32) |
| 165 |
set_target_properties(libclang |
| 166 |
PROPERTIES |
| 167 |
VERSION ${LIBCLANG_LIBRARY_VERSION} |
| 168 |
DEFINE_SYMBOL _CINDEX_LIB_) |
| 169 |
elseif(APPLE) |
| 170 |
set(LIBCLANG_LINK_FLAGS " -Wl,-compatibility_version -Wl,1") |
| 171 |
set(LIBCLANG_LINK_FLAGS "${LIBCLANG_LINK_FLAGS} -Wl,-current_version -Wl,${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}") |
| 172 |
|
| 173 |
set_property(TARGET libclang APPEND_STRING PROPERTY |
| 174 |
LINK_FLAGS ${LIBCLANG_LINK_FLAGS}) |
| 175 |
else() |
| 176 |
set_target_properties(libclang |
| 177 |
PROPERTIES |
| 178 |
VERSION ${LIBCLANG_LIBRARY_VERSION} |
| 179 |
DEFINE_SYMBOL _CINDEX_LIB_) |
| 180 |
# FIXME: _CINDEX_LIB_ affects dllexport/dllimport on Win32. |
| 181 |
if(LLVM_ENABLE_MODULES AND NOT WIN32) |
| 182 |
target_compile_options(libclang PRIVATE |
| 183 |
"-fmodules-ignore-macro=_CINDEX_LIB_" |
| 184 |
) |
| 185 |
endif() |
| 186 |
endif() |
| 187 |
if (USE_VERSION_SCRIPT) |
| 188 |
target_link_options(libclang PRIVATE "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map") |
| 189 |
# The Solaris 11.4 linker supports a subset of GNU ld version scripts, |
| 190 |
# but requires a special option to enable it. |
| 191 |
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") |
| 192 |
target_link_options(libclang PRIVATE "-Wl,-z,gnu-version-script-compat") |
| 193 |
endif() |
| 194 |
# Ensure that libclang.so gets rebuilt when the linker script changes. |
| 195 |
set_property(SOURCE ARCMigrate.cpp APPEND PROPERTY |
| 196 |
OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libclang.map) |
| 197 |
|
| 198 |
set_target_properties(libclang PROPERTIES |
| 199 |
VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX} |
| 200 |
${LIBCLANG_SOVERSION_ARG}) |
| 201 |
endif() |
| 202 |
endif() |
| 203 |
|
| 204 |
if(INTERNAL_INSTALL_PREFIX) |
| 205 |
set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${INTERNAL_INSTALL_PREFIX}/include") |
| 206 |
else() |
| 207 |
set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") |
| 208 |
endif() |
| 209 |
|
| 210 |
install(DIRECTORY ../../include/clang-c |
| 211 |
COMPONENT libclang-headers |
| 212 |
DESTINATION "${LIBCLANG_HEADERS_INSTALL_DESTINATION}" |
| 213 |
FILES_MATCHING |
| 214 |
PATTERN "*.h" |
| 215 |
) |
| 216 |
|
| 217 |
# LLVM_DISTRIBUTION_COMPONENTS requires that each component have both a |
| 218 |
# component and an install-component target, so add a dummy libclang-headers |
| 219 |
# target to allow using it in LLVM_DISTRIBUTION_COMPONENTS. |
| 220 |
add_custom_target(libclang-headers) |
| 221 |
set_target_properties(libclang-headers PROPERTIES FOLDER "Misc") |
| 222 |
|
| 223 |
if (NOT LLVM_ENABLE_IDE) |
| 224 |
add_llvm_install_targets(install-libclang-headers |
| 225 |
COMPONENT libclang-headers) |
| 226 |
endif() |
| 227 |
|
| 228 |
# Create a target to install the python bindings to make them easier to |
| 229 |
# distribute. Since the bindings are over libclang, which is installed |
| 230 |
# unbundled to the clang version, follow suit. |
| 231 |
foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS}) |
| 232 |
install(DIRECTORY |
| 233 |
${CMAKE_CURRENT_SOURCE_DIR}/../../bindings/python/clang |
| 234 |
COMPONENT |
| 235 |
libclang-python-bindings |
| 236 |
DESTINATION |
| 237 |
"lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") |
| 238 |
endforeach() |
| 239 |
if(NOT LLVM_ENABLE_IDE) |
| 240 |
add_custom_target(libclang-python-bindings) |
| 241 |
add_llvm_install_targets(install-libclang-python-bindings |
| 242 |
COMPONENT |
| 243 |
libclang-python-bindings) |
| 244 |
endif() |
| 245 |
|