THRIFT-4759:add thrift export to fix windows shared lib building (#1714)
* add THRIFT_EXPORT to fix windows shared lib building
* use shared libraries on vs2017 appveyor build, leave msvc2017 static link
diff --git a/appveyor.yml b/appveyor.yml
index 39aba4f..74c92f1 100755
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -39,7 +39,7 @@
- PROFILE: MSVC2017
PLATFORM: x64
CONFIGURATION: Release
- BUILD_SHARED_LIBS: OFF
+ BUILD_SHARED_LIBS: ON
BOOST_VERSION: 1.67.0
LIBEVENT_VERSION: 2.1.8
PYTHON_VERSION: 3.6
diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt
index dd90c80..e92da60 100755
--- a/lib/cpp/CMakeLists.txt
+++ b/lib/cpp/CMakeLists.txt
@@ -23,6 +23,10 @@
include_directories(src)
+if(NOT BUILD_SHARED_LIBS)
+ add_definitions("-DTHRIFT_STATIC_DEFINE")
+endif()
+
# SYSLIBS contains libraries that need to be linked to all lib targets
set(SYSLIBS "")
diff --git a/lib/cpp/Makefile.am b/lib/cpp/Makefile.am
index 616effd..114ff17 100755
--- a/lib/cpp/Makefile.am
+++ b/lib/cpp/Makefile.am
@@ -132,6 +132,7 @@
include_thrift_HEADERS = \
$(top_builddir)/config.h \
src/thrift/thrift-config.h \
+ src/thrift/thrift_export.h \
src/thrift/TDispatchProcessor.h \
src/thrift/Thrift.h \
src/thrift/TOutput.h \
diff --git a/lib/cpp/src/thrift/TOutput.cpp b/lib/cpp/src/thrift/TOutput.cpp
index f25b566..8d163a9 100644
--- a/lib/cpp/src/thrift/TOutput.cpp
+++ b/lib/cpp/src/thrift/TOutput.cpp
@@ -27,7 +27,7 @@
namespace apache {
namespace thrift {
-TOutput GlobalOutput;
+THRIFT_EXPORT TOutput GlobalOutput;
TOutput::TOutput() : f_(&errorTimeWrapper) {}
diff --git a/lib/cpp/src/thrift/TOutput.h b/lib/cpp/src/thrift/TOutput.h
index 6135cfa..26c9a56 100644
--- a/lib/cpp/src/thrift/TOutput.h
+++ b/lib/cpp/src/thrift/TOutput.h
@@ -20,6 +20,8 @@
#ifndef _THRIFT_OUTPUT_H_
#define _THRIFT_OUTPUT_H_ 1
+#include <thrift/thrift_export.h>
+
namespace apache {
namespace thrift {
@@ -51,7 +53,7 @@
void (*f_)(const char*);
};
-extern TOutput GlobalOutput;
+THRIFT_EXPORT extern TOutput GlobalOutput;
}
} // namespace apache::thrift
diff --git a/lib/cpp/src/thrift/thrift_export.h b/lib/cpp/src/thrift/thrift_export.h
new file mode 100644
index 0000000..f5c059f
--- /dev/null
+++ b/lib/cpp/src/thrift/thrift_export.h
@@ -0,0 +1,20 @@
+#ifndef THRIFT_EXPORT_H
+#define THRIFT_EXPORT_H
+
+#ifdef THRIFT_STATIC_DEFINE
+# define THRIFT_EXPORT
+#elif defined(_MSC_VER )
+# ifndef THRIFT_EXPORT
+# ifdef thrift_EXPORTS
+ /* We are building this library */
+# define THRIFT_EXPORT __declspec(dllexport)
+# else
+ /* We are using this library */
+# define THRIFT_EXPORT __declspec(dllimport)
+# endif
+# endif
+#else
+# define THRIFT_EXPORT
+#endif
+
+#endif /* THRIFT_EXPORT_H */
diff --git a/lib/cpp/src/thrift/transport/TSSLServerSocket.cpp b/lib/cpp/src/thrift/transport/TSSLServerSocket.cpp
index 34605c0..b20c174 100644
--- a/lib/cpp/src/thrift/transport/TSSLServerSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TSSLServerSocket.cpp
@@ -17,6 +17,7 @@
* under the License.
*/
+#include <thrift/thrift_export.h>
#include <thrift/transport/TSSLServerSocket.h>
#include <thrift/transport/TSSLSocket.h>
diff --git a/lib/cpp/src/thrift/transport/TSSLSocket.h b/lib/cpp/src/thrift/transport/TSSLSocket.h
index 8f095dc..4d46998 100644
--- a/lib/cpp/src/thrift/transport/TSSLSocket.h
+++ b/lib/cpp/src/thrift/transport/TSSLSocket.h
@@ -321,7 +321,7 @@
std::shared_ptr<AccessManager> access_;
static concurrency::Mutex mutex_;
static uint64_t count_;
- static bool manualOpenSSLInitialization_;
+ THRIFT_EXPORT static bool manualOpenSSLInitialization_;
void setup(std::shared_ptr<TSSLSocket> ssl);
static int passwordCallback(char* password, int size, int, void* data);
};