ソースを参照

Add static compilation for win32 platforms

Fixes: #97
Alexey Edelev 4 年 前
コミット
457dd68b3a

+ 3 - 0
README.md

@@ -242,6 +242,9 @@ qtprotobuf_link_archive is cmake helper function that links whole archive to you
 
 *QT_PROTOBUF_STATIC* - if **TRUE/ON** for QtProtobuf project build, static libraries will be produced for all QtProtobuf targets except qml plugin. **FALSE** by default
 
+>**Note:** In case if you use static QtProtobuf not with cmake/qmake build system, you additionaly **need manually** add QT_PROTOBUF_STATIC compiler definition
+
+</br>
 *QT_PROTOBUF_EXECUTABLE* - contains full path to QtProtobuf generator add_executable
 
 ## Integration with qmake project

+ 5 - 1
src/grpc/CMakeLists.txt

@@ -43,8 +43,12 @@ file(GLOB HEADERS qgrpcasyncoperationbase_p.h
 
 protobuf_generate_qt_headers(PUBLIC_HEADER ${HEADERS} COMPONENT ${TARGET})
 
-if(QT_PROTOBUF_STATIC AND NOT WIN32)
+if(QT_PROTOBUF_STATIC)
+    if(WIN32)
+        message(WARNING "Static version of QtProtobuf is not fully tested on Win32 platforms")
+    endif()
     add_library(${TARGET} STATIC ${SOURCES})
+    target_compile_definitions(${TARGET} PRIVATE QT_PROTOBUF_STATIC)
 else()
     add_library(${TARGET} SHARED ${SOURCES})
 endif()

+ 10 - 6
src/grpc/qtgrpcglobal.h

@@ -27,10 +27,14 @@
 
 #include <QtCore/QtGlobal>
 
-#ifdef QT_BUILD_GRPC_LIB
-    #define Q_GRPC_EXPORT Q_DECL_EXPORT
+#ifndef QT_PROTOBUF_STATIC
+    #ifdef QT_BUILD_GRPC_LIB
+        #define Q_GRPC_EXPORT Q_DECL_EXPORT
+    #else
+        #define Q_GRPC_EXPORT Q_DECL_IMPORT
+    #endif
 #else
-    #define Q_GRPC_EXPORT Q_DECL_IMPORT
+    #define Q_GRPC_EXPORT
 #endif
 
 //Support macro for Qt versions < 5.13
@@ -42,7 +46,7 @@
 #endif
 
 #ifndef Q_DISABLE_COPY_MOVE
-#define Q_DISABLE_COPY_MOVE(Class) \
-    Q_DISABLE_COPY(Class) \
-    Q_DISABLE_MOVE(Class)
+    #define Q_DISABLE_COPY_MOVE(Class) \
+        Q_DISABLE_COPY(Class) \
+        Q_DISABLE_MOVE(Class)
 #endif

+ 6 - 1
src/protobuf/CMakeLists.txt

@@ -61,8 +61,13 @@ file(GLOB PUBLIC_HEADER
 
 protobuf_generate_qt_headers(PUBLIC_HEADER ${PUBLIC_HEADER} COMPONENT ${TARGET})
 
-if(QT_PROTOBUF_STATIC AND NOT WIN32)
+if(QT_PROTOBUF_STATIC)
+    if(WIN32)
+        message(WARNING "Static version of QtProtobuf is not fully tested on Win32 platforms")
+    endif()
     add_library(${TARGET} STATIC ${SOURCES})
+    target_compile_definitions(${TARGET} PRIVATE QT_PROTOBUF_STATIC)
+    set(QT_PROTOBUF_EXTRA_COMPILE_DIFINITIONS QT_PROTOBUF_STATIC)
 else()
     add_library(${TARGET} SHARED ${SOURCES})
 endif()

+ 5 - 0
src/protobuf/QtProtobufConfig.cmake.in

@@ -9,4 +9,9 @@ set(PROTO_PARSER "${CMAKE_CURRENT_LIST_DIR}/parsemessages.go")
 set(GENERATOR_TARGET "@GENERATOR_TARGET@")
 set(QT_PROTOBUF_PROJECT "@QT_PROTOBUF_PROJECT@")
 set(QT_PROTOBUF_EXECUTABLE_INSTALL "@QT_PROTOBUF_EXECUTABLE_INSTALL@")
+set(QT_PROTOBUF_STATIC @QT_PROTOBUF_STATIC@)
+
+if(QT_PROTOBUF_STATIC)
+    add_definitions(-DQT_PROTOBUF_STATIC)#Old cmake versions compatibility
+endif()
 include("${CMAKE_CURRENT_LIST_DIR}/QtProtobufGen.cmake")

+ 1 - 0
src/protobuf/qt_lib_protobuf.pri.in

@@ -8,6 +8,7 @@ QT.protobuf.depends = core qml
 QT.protobuf.module_config = @QT_PROTOBUF_EXTRA_CONFIG@
 
 CONFIG += c++14
+DEFINES += @QT_PROTOBUF_EXTRA_COMPILE_DIFINITIONS@
 
 defineTest(qtprotobuf_generate) {
     OK = false

+ 10 - 6
src/protobuf/qtprotobufglobal.h

@@ -27,10 +27,14 @@
 
 #include <QtCore/QtGlobal>
 
-#if defined(QT_BUILD_PROTOBUF_LIB)
-#  define Q_PROTOBUF_EXPORT Q_DECL_EXPORT
+#ifndef QT_PROTOBUF_STATIC
+    #if defined(QT_BUILD_PROTOBUF_LIB)
+        #define Q_PROTOBUF_EXPORT Q_DECL_EXPORT
+    #else
+        #define Q_PROTOBUF_EXPORT Q_DECL_IMPORT
+    #endif
 #else
-#  define Q_PROTOBUF_EXPORT Q_DECL_IMPORT
+    #define Q_PROTOBUF_EXPORT
 #endif
 
 //Support macro for Qt versions < 5.13
@@ -42,7 +46,7 @@
 #endif
 
 #ifndef Q_DISABLE_COPY_MOVE
-#define Q_DISABLE_COPY_MOVE(Class) \
-    Q_DISABLE_COPY(Class) \
-    Q_DISABLE_MOVE(Class)
+    #define Q_DISABLE_COPY_MOVE(Class) \
+        Q_DISABLE_COPY(Class) \
+        Q_DISABLE_MOVE(Class)
 #endif