[PATCH] D75068: libclang: Add static build support for Windows

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 25 10:36:57 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG6fb80d9383e4: libclang: Add static build support for Windows (authored by cristian.adam, committed by mstorsjo).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75068/new/

https://reviews.llvm.org/D75068

Files:
  clang/include/clang-c/Platform.h
  clang/tools/libclang/CMakeLists.txt


Index: clang/tools/libclang/CMakeLists.txt
===================================================================
--- clang/tools/libclang/CMakeLists.txt
+++ clang/tools/libclang/CMakeLists.txt
@@ -77,14 +77,18 @@
   set(LLVM_EXPORTED_SYMBOL_FILE)
 endif()
 
-if(LLVM_ENABLE_PIC OR WIN32)
+if(LLVM_ENABLE_PIC OR NOT LIBCLANG_BUILD_STATIC)
   set(ENABLE_SHARED SHARED)
 endif()
 
-if((NOT LLVM_ENABLE_PIC OR LIBCLANG_BUILD_STATIC) AND NOT WIN32)
+if(NOT LLVM_ENABLE_PIC OR LIBCLANG_BUILD_STATIC)
   set(ENABLE_STATIC STATIC)
 endif()
 
+if (WIN32 AND ENABLE_SHARED AND ENABLE_STATIC)
+  unset(ENABLE_STATIC)
+endif()
+
 if(WIN32)
   set(output_name "libclang")
 else()
@@ -113,6 +117,14 @@
   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)
   if(WIN32)
     set_target_properties(libclang
Index: clang/include/clang-c/Platform.h
===================================================================
--- clang/include/clang-c/Platform.h
+++ clang/include/clang-c/Platform.h
@@ -18,14 +18,23 @@
 
 LLVM_CLANG_C_EXTERN_C_BEGIN
 
-/* MSVC DLL import/export. */
-#ifdef _MSC_VER
-  #ifdef _CINDEX_LIB_
-    #define CINDEX_LINKAGE __declspec(dllexport)
-  #else
-    #define CINDEX_LINKAGE __declspec(dllimport)
+/* Windows DLL import/export. */
+#ifndef CINDEX_NO_EXPORTS
+  #define CINDEX_EXPORTS
+#endif
+#ifdef _WIN32
+  #ifdef CINDEX_EXPORTS
+    #ifdef _CINDEX_LIB_
+      #define CINDEX_LINKAGE __declspec(dllexport)
+    #else
+      #define CINDEX_LINKAGE __declspec(dllimport)
+    #endif
   #endif
-#else
+#elif defined(CINDEX_EXPORTS) && defined(__GNUC__)
+  #define CINDEX_LINKAGE __attribute__((visibility("default")))
+#endif
+
+#ifndef CINDEX_LINKAGE
   #define CINDEX_LINKAGE
 #endif
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75068.260121.patch
Type: text/x-patch
Size: 1885 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200425/d96270bd/attachment.bin>


More information about the cfe-commits mailing list