Dep/Protobuf: Link protobuf dynamically when building with shared libs

* Fixes issues with linux and dynamic linking
* Closes #16993
This commit is contained in:
Naios
2016-04-17 15:54:46 +02:00
parent 040a54e687
commit 9701fca7df

View File

@@ -57,7 +57,14 @@ else()
)
endif()
add_library(protobuf STATIC ${protobuf_STAT_SRCS})
if (UNIX)
# Enable the default unix export behaviour for protobuf so we don't
# need to patch it's sources.
string(REPLACE "-fvisibility=hidden" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
string(REPLACE "-fvisibility=hidden" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()
add_library(protobuf ${protobuf_STAT_SRCS})
target_include_directories(protobuf
PUBLIC
@@ -69,7 +76,28 @@ target_link_libraries(protobuf
PUBLIC
threads)
if (BUILD_SHARED_LIBS)
target_compile_definitions(protobuf
PRIVATE
-DLIBPROTOBUF_EXPORTS
-DLIBPROTOC_EXPORTS
PUBLIC
-DPROTOBUF_USE_DLLS)
endif()
set_target_properties(protobuf
PROPERTIES
FOLDER
"dep")
PROPERTIES
FOLDER
"dep")
if (BUILD_SHARED_LIBS)
if (UNIX)
install(TARGETS protobuf
LIBRARY
DESTINATION lib)
elseif (WIN32)
install(TARGETS protobuf
RUNTIME
DESTINATION "${CMAKE_INSTALL_PREFIX}")
endif()
endif()