Skip to content

Commit 81317e8

Browse files
committed
Try to fully control the mode of clang visibility macros from CMake
1 parent bd891fa commit 81317e8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

clang/cmake/modules/AddClang.cmake

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,15 @@ macro(add_clang_library name)
108108
endif()
109109
llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
110110

111-
if(NOT ARG_SHARED AND NOT ARG_STATIC)
112-
target_compile_definitions("obj.${name}" PRIVATE CLANG_EXPORTS)
111+
if(MSVC AND NOT CLANG_LINK_CLANG_DYLIB)
112+
# Make sure all consumers also turn off visibility macros so there not trying to dllimport symbols.
113+
target_compile_definitions(${name} PUBLIC CLANG_BUILD_STATIC)
114+
if(TARGET "obj.${name}")
115+
target_compile_definitions("obj.${name}" PUBLIC CLANG_BUILD_STATIC)
116+
endif()
117+
elseif(NOT ARG_SHARED AND NOT ARG_STATIC)
118+
# Clang component libraries linked in to clang-cpp are declared without SHARED or STATIC
119+
target_compile_definitions("obj.${name}" PUBLIC CLANG_EXPORTS)
113120
endif()
114121

115122
set(libs ${name})

clang/include/clang/Support/Compiler.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
// Marker to add to classes or functions in public headers that should not have
3232
// export macros added to them by the clang tool
3333
#define CLANG_ABI_NOT_EXPORTED
34-
#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS)
3534
// Some libraries like those for tablegen are linked in to tools that used
3635
// in the build so can't depend on the llvm shared library. If export macros
3736
// were left enabled when building these we would get duplicate or
@@ -64,6 +63,5 @@
6463
#define CLANG_TEMPLATE_ABI
6564
#define CLANG_EXPORT_TEMPLATE
6665
#endif
67-
#endif
6866

6967
#endif

0 commit comments

Comments
 (0)