brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.9 KiB · b0105f5 Raw
256 lines · plain
1# The SOVERSION should be updated only if a change is made to the libclang2# ABI, and when it is updated, it should be updated to the current3# LLVM_VERSION_MAJOR.4# Please also see clang/tools/libclang/libclang.map5 6# This option defaults to CLANG_FORCE_MATCHING_LIBCLANG_SOVERSION7# to ON - which means that it by default matches CLANG_VERSION_MAJOR8#9# TODO: This should probably not be a option going forward but we10# we should commit to a way to do it. But due to getting this out11# in LLVM 15.x we opted for a option.12set(LIBCLANG_SOVERSION_ARG)13if(NOT CLANG_FORCE_MATCHING_LIBCLANG_SOVERSION)14  set(LIBCLANG_SOVERSION_ARG SOVERSION 13)15endif()16 17# TODO: harmonize usage of LIBCLANG_SOVERSION / LIBCLANG_LIBARY_VERSION18#       below; this was added under time-pressure to avoid reverting the19#       better default from LLVM 14 for LLVM 15.0.0-rc3, hence no time20#       to clean up previous inconsistencies.21 22set(SOURCES23  BuildSystem.cpp24  CIndex.cpp25  CIndexCXX.cpp26  CIndexCodeCompletion.cpp27  CIndexDiagnostic.cpp28  CIndexHigh.cpp29  CIndexInclusionStack.cpp30  CIndexUSRs.cpp31  CIndexer.cpp32  CXComment.cpp33  CXCursor.cpp34  CXExtractAPI.cpp35  CXIndexDataConsumer.cpp36  CXCompilationDatabase.cpp37  CXLoadedDiagnostic.cpp38  CXSourceLocation.cpp39  CXStoredDiagnostic.cpp40  CXString.cpp41  CXType.cpp42  Indexing.cpp43  FatalErrorHandler.cpp44  Rewrite.cpp45  Obsolete.cpp46 47  ADDITIONAL_HEADERS48  CIndexDiagnostic.h49  CIndexer.h50  CXCursor.h51  CXLoadedDiagnostic.h52  CXSourceLocation.h53  CXString.h54  CXTranslationUnit.h55  CXType.h56  Index_Internal.h57  ../../include/clang-c/Index.h58  )59 60set(LIBS61  clangAST62  clangBasic63  clangDriver64  clangExtractAPI65  clangFrontend66  clangIndex67  clangLex68  clangOptions69  clangRewrite70  clangSema71  clangSerialization72  clangTooling73)74 75if (HAVE_LIBDL)76  list(APPEND LIBS ${CMAKE_DL_LIBS})77elseif (CLANG_BUILT_STANDALONE)78  find_library(DL_LIBRARY_PATH dl)79  if (DL_LIBRARY_PATH)80    list(APPEND LIBS dl)81  endif ()82endif ()83 84option(LIBCLANG_BUILD_STATIC85  "Build libclang as a static library (in addition to a shared one)" OFF)86 87set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_BINARY_DIR}/libclang-generic.exports)88set(LIBCLANG_VERSION_SCRIPT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libclang.map)89 90if(MSVC)91  # Avoid LNK4197 by not specifying libclang.exports here.92  # Each functions is exported as "dllexport" in include/clang-c.93  # KB83532694  set(LLVM_EXPORTED_SYMBOL_FILE)95endif()96 97if (UNIX AND NOT APPLE AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "AIX" AND NOT CYGWIN)98  set(LLVM_EXPORTED_SYMBOL_FILE)99  set(USE_VERSION_SCRIPT ${LLVM_HAVE_LINK_VERSION_SCRIPT})100endif()101 102if (LLVM_EXPORTED_SYMBOL_FILE)103  add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE}104                     COMMAND "${Python3_EXECUTABLE}"105                       ARGS ${CMAKE_CURRENT_SOURCE_DIR}/linker-script-to-export-list.py106                            ${LIBCLANG_VERSION_SCRIPT_FILE}107                            ${LLVM_EXPORTED_SYMBOL_FILE}108                     DEPENDS ${LIBCLANG_VERSION_SCRIPT_FILE})109endif()110 111if(LLVM_ENABLE_PIC OR ((WIN32 OR CYGWIN) AND NOT LIBCLANG_BUILD_STATIC))112  set(ENABLE_SHARED SHARED)113endif()114 115if(NOT LLVM_ENABLE_PIC OR LIBCLANG_BUILD_STATIC)116  set(ENABLE_STATIC STATIC)117endif()118 119if (MSVC AND ENABLE_SHARED AND ENABLE_STATIC)120  unset(ENABLE_STATIC)121endif()122 123if(MSVC)124  set(output_name "libclang")125else()126  set(output_name "clang")127endif()128 129if (UNIX AND "${CMAKE_SYSTEM_NAME}" MATCHES "AIX")130    set(CMAKE_AIX_EXPORT_ALL_SYMBOLS OFF)131    # libclang requires headers which need _ALL_SOURCE to build on AIX132    remove_definitions("-D_XOPEN_SOURCE=700")133endif()134 135add_clang_library(libclang ${ENABLE_SHARED} ${ENABLE_STATIC} INSTALL_WITH_TOOLCHAIN136  OUTPUT_NAME ${output_name}137  ${SOURCES}138 139  DEPENDS140  ClangDriverOptions141  clang-resource-headers142 143  LINK_LIBS144  ${LIBS}145 146  LINK_COMPONENTS147  ${LLVM_TARGETS_TO_BUILD}148  Core149  Support150  TargetParser151  )152 153if(ENABLE_STATIC)154  foreach(name libclang obj.libclang libclang_static)155    if (TARGET ${name})156      target_compile_definitions(${name} PUBLIC CINDEX_NO_EXPORTS)157    endif()158  endforeach()159endif()160 161if(ENABLE_SHARED)162  if(WIN32)163    set_target_properties(libclang164      PROPERTIES165      VERSION ${LIBCLANG_LIBRARY_VERSION}166      DEFINE_SYMBOL _CINDEX_LIB_)167      # Avoid declaring clang c++ symbols that are statically linked into libclang as dllimport'ed.168      # If llvm/libclang-cpp dll is also being built for windows clang c++ symbols will still be169      # implicitly be exported from libclang.170      target_compile_definitions(libclang PRIVATE CLANG_BUILD_STATIC)171  elseif(APPLE)172    set(LIBCLANG_LINK_FLAGS " -Wl,-compatibility_version -Wl,1")173    set(LIBCLANG_LINK_FLAGS "${LIBCLANG_LINK_FLAGS} -Wl,-current_version -Wl,${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")174 175    set_property(TARGET libclang APPEND_STRING PROPERTY176                 LINK_FLAGS ${LIBCLANG_LINK_FLAGS})177  else()178    set_target_properties(libclang179      PROPERTIES180      VERSION ${LIBCLANG_LIBRARY_VERSION}181      DEFINE_SYMBOL _CINDEX_LIB_)182    # FIXME: _CINDEX_LIB_ affects dllexport/dllimport on Win32.183    if(LLVM_ENABLE_MODULES AND NOT WIN32)184      target_compile_options(libclang PRIVATE185        "-fmodules-ignore-macro=_CINDEX_LIB_"186        )187    endif()188  endif()189  if (USE_VERSION_SCRIPT)190    if ("${CMAKE_SYSTEM_NAME}" MATCHES "SunOS")191      include(CheckLinkerFlag)192      # The Solaris 11.4 linker supports a subset of GNU ld version scripts,193      # but requires a special option to enable it.194      check_linker_flag(CXX "-Wl,-z,gnu-version-script-compat"195                        LINKER_SUPPORTS_Z_GNU_VERSION_SCRIPT_COMPAT)196      # Older Solaris (and illumos) linker does not support GNU ld version scripts197      # and does not support GNU version script compat.198      if (LINKER_SUPPORTS_Z_GNU_VERSION_SCRIPT_COMPAT)199        target_link_options(libclang PRIVATE "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")200        target_link_options(libclang PRIVATE "-Wl,-z,gnu-version-script-compat")201      else()202        target_link_options(libclang PRIVATE "-Wl,-M,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")203      endif()204    else()205      target_link_options(libclang PRIVATE "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")206    endif()207    # Ensure that libclang.so gets rebuilt when the linker script changes.208    set_target_properties(libclang PROPERTIES209                          VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}210                          ${LIBCLANG_SOVERSION_ARG})211  endif()212endif()213 214if(INTERNAL_INSTALL_PREFIX)215  set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${INTERNAL_INSTALL_PREFIX}/include")216else()217  set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")218endif()219 220install(DIRECTORY ../../include/clang-c221  COMPONENT libclang-headers222  DESTINATION "${LIBCLANG_HEADERS_INSTALL_DESTINATION}"223  FILES_MATCHING224  PATTERN "*.h"225  )226 227# LLVM_DISTRIBUTION_COMPONENTS requires that each component have both a228# component and an install-component target, so add a dummy libclang-headers229# target to allow using it in LLVM_DISTRIBUTION_COMPONENTS.230add_custom_target(libclang-headers)231set_target_properties(libclang-headers PROPERTIES FOLDER "Clang/Resources")232 233if (NOT LLVM_ENABLE_IDE)234  add_llvm_install_targets(install-libclang-headers235                           COMPONENT libclang-headers)236endif()237 238# Create a target to install the python bindings to make them easier to239# distribute.  Since the bindings are over libclang, which is installed240# unbundled to the clang version, follow suit.241foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS})242  install(DIRECTORY243            ${CMAKE_CURRENT_SOURCE_DIR}/../../bindings/python/clang244          COMPONENT245            libclang-python-bindings246          DESTINATION247            "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages")248endforeach()249if(NOT LLVM_ENABLE_IDE)250  add_custom_target(libclang-python-bindings)251  add_llvm_install_targets(install-libclang-python-bindings252                           COMPONENT253                             libclang-python-bindings)254endif()255 256