From a15659e9f8958289f05c75fb1ad9dd04bbe4072d Mon Sep 17 00:00:00 2001
From: changnet <940477049@qq.com>
Date: Wed, 7 Sep 2016 01:12:04 +0800
Subject: [PATCH] option to build shared library,defeault off

---
 .gitignore     |  1 +
 CMakeLists.txt | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/.gitignore b/.gitignore
index e07fbae9..79c70d0c 100755
--- a/.gitignore
+++ b/.gitignore
@@ -64,3 +64,4 @@ target
 build/VS2010/FlatBuffers.sdf
 build/VS2010/FlatBuffers.opensdf
 build/VS2010/ipch/**/*.ipch
+*.so
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1af3d333..ad01c211 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,6 +12,9 @@ option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler"
        ON)
 option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON)
 option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF)
+option(FLATBUFFERS_BUILD_SHAREDLIB
+       "Enable the build of the flatbuffers shared library"
+       OFF)
 
 if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
     message(WARNING
@@ -164,6 +167,11 @@ if(FLATBUFFERS_BUILD_FLATHASH)
   add_executable(flathash ${FlatHash_SRCS})
 endif()
 
+if(FLATBUFFERS_BUILD_SHAREDLIB)
+  add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
+  set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers)
+endif()
+
 function(compile_flatbuffers_schema_to_cpp SRC_FBS)
   get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
   string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
@@ -212,6 +220,9 @@ if(FLATBUFFERS_INSTALL)
   if(FLATBUFFERS_BUILD_FLATC)
     install(TARGETS flatc DESTINATION bin)
   endif()
+  if(FLATBUFFERS_BUILD_SHAREDLIB)
+    install(TARGETS flatbuffers_shared DESTINATION lib)
+  endif()
 endif()
 
 if(FLATBUFFERS_BUILD_TESTS)
-- 
GitLab