libclang: Make shared object symbol exporting by default

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
This commit is contained in:
Cristian Adam 2020-02-20 14:24:52 -05:00 committed by Nico Weber
parent a11ff39ba2
commit 7a7c753b0c
2 changed files with 13 additions and 3 deletions

View File

@ -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_
@ -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

View File

@ -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()
@ -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