[PATCH] D74564: libclang: Add static build support for Windows
Cristian Adam via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 13 08:51:47 PST 2020
cristian.adam created this revision.
cristian.adam added reviewers: chapuni, yvvan.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.
On Linux and macOS it was possible to build libclang statically by configuring CMake with:
-D LIBCLANG_BUILD_STATIC=ON
-D LLVM_ENABLE_PIC=OFF
On Windows was not possible. This commit fixes this.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D74564
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,11 +77,11 @@
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 @@
)
if(ENABLE_SHARED)
+ target_compile_definitions(libclang PUBLIC CINDEX_EXPORTS)
if(WIN32)
set_target_properties(libclang
PROPERTIES
Index: clang/include/clang-c/Platform.h
===================================================================
--- clang/include/clang-c/Platform.h
+++ 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74564.244449.patch
Type: text/x-patch
Size: 1503 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200213/70379d3c/attachment-0001.bin>
More information about the cfe-commits
mailing list