[clang] 7ff1f55 - libclang: Add static build support for Windows

Martin Storsjö via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 19 14:05:56 PST 2020


Author: Cristian Adam
Date: 2020-02-20T00:05:46+02:00
New Revision: 7ff1f55a1219719f57a6f7905c26ce41d1767e4c

URL: https://github.com/llvm/llvm-project/commit/7ff1f55a1219719f57a6f7905c26ce41d1767e4c
DIFF: https://github.com/llvm/llvm-project/commit/7ff1f55a1219719f57a6f7905c26ce41d1767e4c.diff

LOG: libclang: Add static build support for Windows

Differential Revision: https://reviews.llvm.org/D74564

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/include/clang-c/Platform.h b/clang/include/clang-c/Platform.h
index 3bb66bb0df48..9c15516f362f 100644
--- a/clang/include/clang-c/Platform.h
+++ b/clang/include/clang-c/Platform.h
@@ -18,14 +18,20 @@
 
 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. */
+#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)
+  #define CINDEX_LINKAGE __attribute__((visibility("default")))
+#endif
+
+#ifndef CINDEX_LINKAGE
   #define CINDEX_LINKAGE
 #endif
 

diff  --git a/clang/tools/libclang/CMakeLists.txt b/clang/tools/libclang/CMakeLists.txt
index bd0c945a5e12..99de3b399855 100644
--- a/clang/tools/libclang/CMakeLists.txt
+++ b/clang/tools/libclang/CMakeLists.txt
@@ -77,11 +77,11 @@ if(MSVC)
   set(LLVM_EXPORTED_SYMBOL_FILE)
 endif()
 
-if(LLVM_ENABLE_PIC OR WIN32)
+if(LLVM_ENABLE_PIC)
   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()
 
@@ -114,6 +114,7 @@ add_clang_library(libclang ${ENABLE_SHARED} ${ENABLE_STATIC} INSTALL_WITH_TOOLCH
   )
 
 if(ENABLE_SHARED)
+  target_compile_definitions(libclang PUBLIC CINDEX_EXPORTS)
   if(WIN32)
     set_target_properties(libclang
       PROPERTIES


        


More information about the cfe-commits mailing list