Skip to content

Commit

Permalink
libclang: Make shared object symbol exporting by default
Browse files Browse the repository at this point in the history
https://reviews.llvm.org/D74564 enabled static building for libclang,
and for non CMake consumers they had to set the `CMAKE_EXPORTS` define
when consuming libclang.

This commit makes the non CMake users of the static building have to define `CMAKE_NO_EXPORTS`.

Differential Revision: https://reviews.llvm.org/D74907
  • Loading branch information
cristianadam authored and nico committed Feb 20, 2020
1 parent a11ff39 commit 7a7c753
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion clang/include/clang-c/Platform.h
Expand Up @@ -19,6 +19,9 @@
LLVM_CLANG_C_EXTERN_C_BEGIN

/* Windows DLL import/export. */
#ifndef CINDEX_NO_EXPORTS
#define CINDEX_EXPORTS
#endif
#ifdef _WIN32
#ifdef CINDEX_EXPORTS
#ifdef _CINDEX_LIB_
Expand All @@ -27,7 +30,7 @@ LLVM_CLANG_C_EXTERN_C_BEGIN
#define CINDEX_LINKAGE __declspec(dllimport)
#endif
#endif
#elif defined(CINDEX_EXPORTS)
#elif defined(CINDEX_EXPORTS) && defined(__GNUC__)
#define CINDEX_LINKAGE __attribute__((visibility("default")))
#endif

Expand Down
11 changes: 9 additions & 2 deletions clang/tools/libclang/CMakeLists.txt
Expand Up @@ -77,7 +77,7 @@ if(MSVC)
set(LLVM_EXPORTED_SYMBOL_FILE)
endif()

if(LLVM_ENABLE_PIC)
if(LLVM_ENABLE_PIC OR NOT LIBCLANG_BUILD_STATIC)
set(ENABLE_SHARED SHARED)
endif()

Expand Down Expand Up @@ -113,8 +113,15 @@ add_clang_library(libclang ${ENABLE_SHARED} ${ENABLE_STATIC} INSTALL_WITH_TOOLCH
Support
)

if(ENABLE_STATIC)
foreach(name libclang obj.libclang libclang_static)
if (TARGET ${name})
target_compile_definitions(${name} PUBLIC CINDEX_NO_EXPORTS)
endif()
endforeach()
endif()

if(ENABLE_SHARED)
target_compile_definitions(libclang PUBLIC CINDEX_EXPORTS)
if(WIN32)
set_target_properties(libclang
PROPERTIES
Expand Down

0 comments on commit 7a7c753

Please sign in to comment.