diff options
| author | Alexander Gavrilov | 2012-03-09 19:46:21 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-03-09 19:46:21 +0400 |
| commit | edf77cf270e3ff7c4a08cd85fcaf537b254f6273 (patch) | |
| tree | ea12836902f56ce46460377eb7aa5f5b35f4f151 | |
| parent | 9b071097de73dc19e5f3d5be31134810bad3e6f7 (diff) | |
| download | dfhack-edf77cf270e3ff7c4a08cd85fcaf537b254f6273.tar.gz dfhack-edf77cf270e3ff7c4a08cd85fcaf537b254f6273.tar.bz2 dfhack-edf77cf270e3ff7c4a08cd85fcaf537b254f6273.tar.xz | |
Link protobuf to dfhack core as a shared library.
- Change protobuf libraries to build as DLLs.
- Move some stream features to the lite library.
- Install the lite library and use it from dfhack.
Note that:
- A couple of protobuf headers had to be tweaked.
- The lite library is used because the full one is
absolutely incompatible with reloading plugins.
- Shutting down protobuf also can't be allowed.
| -rw-r--r-- | CMakeLists.txt | 4 | ||||
| -rw-r--r-- | library/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | library/depends/protobuf/CMakeLists.txt | 43 | ||||
| -rw-r--r-- | library/depends/protobuf/google/protobuf/generated_message_util.h | 2 | ||||
| -rw-r--r-- | library/depends/protobuf/google/protobuf/stubs/common.h | 3 | ||||
| -rw-r--r-- | plugins/mapexport/CMakeLists.txt | 14 | ||||
| -rw-r--r-- | plugins/mapexport/mapexport.cpp | 1 |
7 files changed, 46 insertions, 23 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a5ceb74..0bf68dc1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,10 @@ ENDIF() #add depends to include path INCLUDE_DIRECTORIES ( library/depends ) +INCLUDE_DIRECTORIES ( library/depends/protobuf/ ) + +# use shared libraries for protobuf +ADD_DEFINITIONS(-DPROTOBUF_USE_DLLS) # build the static lua for dfusion INCLUDE_DIRECTORIES ( lua/include ) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 94704beb..ca4c9d47 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -196,7 +196,7 @@ endif() #effectively disables debug builds... SET_TARGET_PROPERTIES(dfhack PROPERTIES DEBUG_POSTFIX "-debug" ) -TARGET_LINK_LIBRARIES(dfhack ${PROJECT_LIBS}) +TARGET_LINK_LIBRARIES(dfhack protobuf-lite ${PROJECT_LIBS}) IF(UNIX) # On linux, copy our version of the df launch script which sets LD_PRELOAD diff --git a/library/depends/protobuf/CMakeLists.txt b/library/depends/protobuf/CMakeLists.txt index 46711b41..cdd85014 100644 --- a/library/depends/protobuf/CMakeLists.txt +++ b/library/depends/protobuf/CMakeLists.txt @@ -91,6 +91,8 @@ google/protobuf/wire_format_lite.h google/protobuf/wire_format_lite_inl.h
google/protobuf/io/zero_copy_stream.h
google/protobuf/io/zero_copy_stream_impl_lite.h
+google/protobuf/io/gzip_stream.h
+google/protobuf/io/zero_copy_stream_impl.h
)
SET(LIBPROTOBUF_FULL_HDRS
@@ -99,7 +101,6 @@ google/protobuf/descriptor.pb.h google/protobuf/descriptor_database.h
google/protobuf/dynamic_message.h
google/protobuf/generated_message_reflection.h
-google/protobuf/io/gzip_stream.h
google/protobuf/compiler/importer.h
google/protobuf/message.h
google/protobuf/compiler/parser.h
@@ -112,7 +113,6 @@ google/protobuf/text_format.h google/protobuf/io/tokenizer.h
google/protobuf/unknown_field_set.h
google/protobuf/wire_format.h
-google/protobuf/io/zero_copy_stream_impl.h
)
LIST(APPEND LIBPROTOBUF_FULL_HDRS ${LIBPROTOBUF_LITE_HDRS})
@@ -128,6 +128,8 @@ google/protobuf/repeated_field.cc google/protobuf/wire_format_lite.cc
google/protobuf/io/zero_copy_stream.cc
google/protobuf/io/zero_copy_stream_impl_lite.cc
+google/protobuf/io/gzip_stream.cc
+google/protobuf/io/zero_copy_stream_impl.cc
)
SET(LIBPROTOBUF_FULL_SRCS
@@ -137,7 +139,6 @@ google/protobuf/descriptor_database.cc google/protobuf/dynamic_message.cc
google/protobuf/extension_set_heavy.cc
google/protobuf/generated_message_reflection.cc
-google/protobuf/io/gzip_stream.cc
google/protobuf/compiler/importer.cc
google/protobuf/message.cc
google/protobuf/compiler/parser.cc
@@ -151,7 +152,6 @@ google/protobuf/text_format.cc google/protobuf/io/tokenizer.cc
google/protobuf/unknown_field_set.cc
google/protobuf/wire_format.cc
-google/protobuf/io/zero_copy_stream_impl.cc
)
SET(LIBPROTOC_HDRS
@@ -201,9 +201,36 @@ LIST(APPEND LIBPROTOBUF_FULL_SRCS ${LIBPROTOBUF_LITE_SRCS}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${dfhack_SOURCE_DIR}/library/depends/zlib)
-ADD_LIBRARY(protobuf-lite ${LIBPROTOBUF_LITE_SRCS} ${LIBPROTOBUF_LITE_HDRS})
-ADD_LIBRARY(protobuf ${LIBPROTOBUF_FULL_SRCS} ${LIBPROTOBUF_FULL_HDRS})
-ADD_LIBRARY(protoc ${LIBPROTOC_SRCS} ${LIBPROTOC_HDRS})
+# Protobuf shared libraries
+
+ADD_LIBRARY(protobuf SHARED ${LIBPROTOBUF_FULL_SRCS} ${LIBPROTOBUF_FULL_HDRS})
+ADD_LIBRARY(protobuf-lite SHARED ${LIBPROTOBUF_LITE_SRCS} ${LIBPROTOBUF_LITE_HDRS})
+
+SET_TARGET_PROPERTIES(protobuf PROPERTIES COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS)
+SET_TARGET_PROPERTIES(protobuf-lite PROPERTIES COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS)
+
+IF(WIN32)
+ TARGET_LINK_LIBRARIES(protobuf ${CMAKE_THREAD_LIBS_INIT} zlib)
+ TARGET_LINK_LIBRARIES(protobuf-lite ${CMAKE_THREAD_LIBS_INIT} zlib)
+ELSE()
+ TARGET_LINK_LIBRARIES(protobuf ${CMAKE_THREAD_LIBS_INIT} z)
+ TARGET_LINK_LIBRARIES(protobuf-lite ${CMAKE_THREAD_LIBS_INIT} z)
+ENDIF()
+
+install(TARGETS protobuf-lite
+ LIBRARY DESTINATION ${DFHACK_LIBRARY_DESTINATION}/deplibs
+ RUNTIME DESTINATION ${DFHACK_LIBRARY_DESTINATION}/deplibs)
+
+# Protobuf compiler shared library
+
+ADD_LIBRARY(protoc SHARED ${LIBPROTOC_SRCS} ${LIBPROTOC_HDRS})
+
+SET_TARGET_PROPERTIES(protoc PROPERTIES COMPILE_DEFINITIONS LIBPROTOC_EXPORTS)
+TARGET_LINK_LIBRARIES(protoc protobuf)
+
+# Protobuf compiler executable
+
ADD_EXECUTABLE(protoc-bin google/protobuf/compiler/main.cc google/protobuf/compiler/command_line_interface.h google/protobuf/compiler/cpp/cpp_generator.h)
+
SET_TARGET_PROPERTIES(protoc-bin PROPERTIES OUTPUT_NAME protoc)
-TARGET_LINK_LIBRARIES(protoc-bin protoc protobuf ${CMAKE_THREAD_LIBS_INIT})
+TARGET_LINK_LIBRARIES(protoc-bin protoc)
diff --git a/library/depends/protobuf/google/protobuf/generated_message_util.h b/library/depends/protobuf/google/protobuf/generated_message_util.h index 1a2343d4..239daea5 100644 --- a/library/depends/protobuf/google/protobuf/generated_message_util.h +++ b/library/depends/protobuf/google/protobuf/generated_message_util.h @@ -72,7 +72,7 @@ double Infinity(); double NaN(); // Constant used for empty default strings. -extern const ::std::string kEmptyString; +extern LIBPROTOBUF_EXPORT const ::std::string kEmptyString; } // namespace internal diff --git a/library/depends/protobuf/google/protobuf/stubs/common.h b/library/depends/protobuf/google/protobuf/stubs/common.h index 7173a84d..83297357 100644 --- a/library/depends/protobuf/google/protobuf/stubs/common.h +++ b/library/depends/protobuf/google/protobuf/stubs/common.h @@ -96,6 +96,9 @@ namespace protobuf { #else #define LIBPROTOC_EXPORT __declspec(dllimport) #endif +#elif defined(PROTOBUF_USE_DLLS) + #define LIBPROTOBUF_EXPORT __attribute__ ((visibility("default"))) + #define LIBPROTOC_EXPORT __attribute__ ((visibility("default"))) #else #define LIBPROTOBUF_EXPORT #define LIBPROTOC_EXPORT diff --git a/plugins/mapexport/CMakeLists.txt b/plugins/mapexport/CMakeLists.txt index d3ff2585..bebdd08e 100644 --- a/plugins/mapexport/CMakeLists.txt +++ b/plugins/mapexport/CMakeLists.txt @@ -1,15 +1,5 @@ PROJECT(mapexport) -INCLUDE_DIRECTORIES ( - ${CMAKE_CURRENT_SOURCE_DIR} - ${dfhack_SOURCE_DIR}/library/depends/protobuf/ - ${dfhack_SOURCE_DIR}/library/depends/zlib/ -) - -LINK_DIRECTORIES( - ${dfhack_SOURCE_DIR}/library/depends/zlib/ -) - #The protobuf sources we generate will require these headers SET(PROJECT_HDRS ${dfhack_SOURCE_DIR}/library/depends/protobuf/google/protobuf/stubs/once.h @@ -51,7 +41,7 @@ DEPENDS protoc-bin ${PROJECT_PROTOS} ) IF(WIN32) - DFHACK_PLUGIN(mapexport ${PROJECT_SRCS} ${PROJECT_HDRS} LINK_LIBRARIES protobuf zlib) + DFHACK_PLUGIN(mapexport ${PROJECT_SRCS} ${PROJECT_HDRS} LINK_LIBRARIES protobuf-lite) ELSE() - DFHACK_PLUGIN(mapexport ${PROJECT_SRCS} ${PROJECT_HDRS} LINK_LIBRARIES protobuf z) + DFHACK_PLUGIN(mapexport ${PROJECT_SRCS} ${PROJECT_HDRS} LINK_LIBRARIES protobuf-lite) ENDIF() diff --git a/plugins/mapexport/mapexport.cpp b/plugins/mapexport/mapexport.cpp index 2e519771..ea7b8894 100644 --- a/plugins/mapexport/mapexport.cpp +++ b/plugins/mapexport/mapexport.cpp @@ -37,7 +37,6 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> DFhackCExport command_result plugin_shutdown ( Core * c ) { - google::protobuf::ShutdownProtobufLibrary(); return CR_OK; } |
