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
4 # Please also see clang/tools/libclang/libclang.map
6 # This option defaults to CLANG_FORCE_MATCHING_LIBCLANG_SOVERSION
7 # to ON - which means that it by default matches CLANG_VERSION_MAJOR
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)
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.
27 CIndexCodeCompletion.cpp
30 CIndexInclusionStack.cpp
36 CXIndexDataConsumer.cpp
37 CXCompilationDatabase.cpp
38 CXLoadedDiagnostic.cpp
40 CXStoredDiagnostic.cpp
57 ../../include/clang-c/Index.h
74 if (CLANG_ENABLE_ARCMT)
75 list(APPEND LIBS clangARCMigrate)
79 list(APPEND LIBS ${CMAKE_DL_LIBS})
80 elseif (CLANG_BUILT_STANDALONE)
81 find_library(DL_LIBRARY_PATH dl)
87 option(LIBCLANG_BUILD_STATIC
88 "Build libclang as a static library (in addition to a shared one)" OFF)
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)
94 # Avoid LNK4197 by not specifying libclang.exports here.
95 # Each functions is exported as "dllexport" in include/clang-c.
97 set(LLVM_EXPORTED_SYMBOL_FILE)
100 if (UNIX AND NOT APPLE)
101 set(LLVM_EXPORTED_SYMBOL_FILE)
102 set(USE_VERSION_SCRIPT ${LLVM_HAVE_LINK_VERSION_SCRIPT})
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})
114 if(LLVM_ENABLE_PIC OR (WIN32 AND NOT LIBCLANG_BUILD_STATIC))
115 set(ENABLE_SHARED SHARED)
118 if(NOT LLVM_ENABLE_PIC OR LIBCLANG_BUILD_STATIC)
119 set(ENABLE_STATIC STATIC)
122 if (MSVC AND ENABLE_SHARED AND ENABLE_STATIC)
127 set(output_name "libclang")
129 set(output_name "clang")
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")
137 add_clang_library(libclang ${ENABLE_SHARED} ${ENABLE_STATIC} INSTALL_WITH_TOOLCHAIN
138 OUTPUT_NAME ${output_name}
143 clang-resource-headers
149 ${LLVM_TARGETS_TO_BUILD}
156 foreach(name libclang obj.libclang libclang_static)
158 target_compile_definitions(${name} PUBLIC CINDEX_NO_EXPORTS)
165 set_target_properties(libclang
167 VERSION ${LIBCLANG_LIBRARY_VERSION}
168 DEFINE_SYMBOL _CINDEX_LIB_)
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}")
173 set_property(TARGET libclang APPEND_STRING PROPERTY
174 LINK_FLAGS ${LIBCLANG_LINK_FLAGS})
176 set_target_properties(libclang
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_"
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")
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)
198 set_target_properties(libclang PROPERTIES
199 VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}
200 ${LIBCLANG_SOVERSION_ARG})
204 if(INTERNAL_INSTALL_PREFIX)
205 set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${INTERNAL_INSTALL_PREFIX}/include")
207 set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
210 install(DIRECTORY ../../include/clang-c
211 COMPONENT libclang-headers
212 DESTINATION "${LIBCLANG_HEADERS_INSTALL_DESTINATION}"
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")
223 if (NOT LLVM_ENABLE_IDE)
224 add_llvm_install_targets(install-libclang-headers
225 COMPONENT libclang-headers)
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})
233 ${CMAKE_CURRENT_SOURCE_DIR}/../../bindings/python/clang
235 libclang-python-bindings
237 "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages")
239 if(NOT LLVM_ENABLE_IDE)
240 add_custom_target(libclang-python-bindings)
241 add_llvm_install_targets(install-libclang-python-bindings
243 libclang-python-bindings)