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.
develop
Alexander Gavrilov 2012-03-09 19:46:21 +04:00
parent 9b071097de
commit edf77cf270
7 changed files with 46 additions and 23 deletions

@ -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 )

@ -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

@ -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)

@ -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

@ -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

@ -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()

@ -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;
}