Skip to content

[libclang][Cygwin] Provide unversioned DLL file alongside versioned one #147132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions clang/tools/libclang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,22 @@ if(ENABLE_STATIC)
endif()

if(ENABLE_SHARED)
if(WIN32)
if(WIN32 OR CYGWIN)
set_target_properties(libclang
PROPERTIES
VERSION ${LIBCLANG_LIBRARY_VERSION}
DEFINE_SYMBOL _CINDEX_LIB_)
# Avoid declaring clang c++ symbols that are statically linked into libclang as dllimport'ed.
# If llvm/libclang-cpp dll is also being built for windows clang c++ symbols will still be
# implicitly be exported from libclang.
target_compile_definitions(libclang PRIVATE CLANG_BUILD_STATIC)
if (CYGWIN)
# We need cygclang.dll in build-tree additional to installed-tree for testsuite of python bindings.
set(plain_name "$<TARGET_FILE_DIR:libclang>/$<TARGET_FILE_PREFIX:libclang>clang$<TARGET_FILE_SUFFIX:libclang>")
add_custom_command(TARGET libclang POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink "$<TARGET_FILE_NAME:libclang>" "${plain_name}")
install(FILES "${plain_name}" DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT libclang)
endif()
# Avoid declaring clang c++ symbols that are statically linked into libclang as dllimport'ed.
# If llvm/libclang-cpp dll is also being built for windows clang c++ symbols will still be
# implicitly be exported from libclang.
target_compile_definitions(libclang PRIVATE CLANG_BUILD_STATIC)
elseif(APPLE)
set(LIBCLANG_LINK_FLAGS " -Wl,-compatibility_version -Wl,1")
set(LIBCLANG_LINK_FLAGS "${LIBCLANG_LINK_FLAGS} -Wl,-current_version -Wl,${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")
Expand Down
10 changes: 9 additions & 1 deletion llvm/cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -750,12 +750,20 @@ function(llvm_add_library name)
set(library_name ${output_name}-${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX})
set(api_name ${output_name}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX})
set_target_properties(${name} PROPERTIES OUTPUT_NAME ${library_name})
if(UNIX AND NOT CYGWIN)
if(UNIX)
llvm_install_library_symlink(${api_name} ${library_name} SHARED
COMPONENT ${name})
llvm_install_library_symlink(${output_name} ${library_name} SHARED
COMPONENT ${name})
endif()
elseif(CYGWIN)
get_target_property(output_name ${name} OUTPUT_NAME)
if(${output_name} STREQUAL "output_name-NOTFOUND")
set(output_name ${name})
endif()
set(library_name ${output_name}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX})
llvm_install_library_symlink(${output_name} ${library_name} SHARED
COMPONENT ${name})
endif()
endif()

Expand Down
6 changes: 5 additions & 1 deletion llvm/tools/llvm-shlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ if(LLVM_BUILD_LLVM_DYLIB)
if (LLVM_LINK_LLVM_DYLIB)
set(INSTALL_WITH_TOOLCHAIN INSTALL_WITH_TOOLCHAIN)
endif()
if (WIN32 OR CYGWIN)
if (WIN32)
add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${INSTALL_WITH_TOOLCHAIN} ${SOURCES})
elseif(CYGWIN)
add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${INSTALL_WITH_TOOLCHAIN} ${SOURCES})
llvm_install_library_symlink(LLVM-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX} $<TARGET_FILE_NAME:LLVM> SHARED FULL_DEST COMPONENT LLVM)
llvm_install_library_symlink(LLVM $<TARGET_LINKER_FILE_NAME:LLVM> IMPORT FULL_DEST COMPONENT LLVM)
else()
add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB OUTPUT_NAME LLVM ${INSTALL_WITH_TOOLCHAIN} ${SOURCES})
# Add symlink for backwards compatibility with old library name
Expand Down