From 2279e30be5796e9b185545543ea54fe68633cbdd Mon Sep 17 00:00:00 2001
From: Alexey Firago <alexey_firago@mentor.com>
Date: Mon, 30 Oct 2017 23:24:49 +0300
Subject: [PATCH] CMakeLists.txt: Fix libraries installation for Linux

* Set libs versions as in Makefile

Signed-off-by: Alexey Firago <alexey_firago@mentor.com>

---
 CMakeLists.txt | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,6 +30,15 @@ set(PACKAGE_TARNAME   "${PACKAGE_NAME}-$
 set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/")
 project(${PACKAGE_NAME} C CXX)
 
+set (CORE_VERSION_MAJOR "6")
+set (CORE_VERSION "6.0.0")
+
+set (CPP_VERSION_MAJOR "1")
+set (CPP_VERSION "${PACKAGE_VERSION}")
+
+set (CSHARP_VERSION_MAJOR "1")
+set (CSHARP_VERSION "${PACKAGE_VERSION}")
+
 set(gRPC_INSTALL_BINDIR "bin" CACHE STRING "Installation directory for executables")
 set(gRPC_INSTALL_LIBDIR "lib" CACHE STRING "Installation directory for libraries")
 set(gRPC_INSTALL_INCLUDEDIR "include" CACHE STRING "Installation directory for headers")
@@ -777,6 +786,10 @@ if(WIN32 AND MSVC)
   endif()
 endif()
 
+if(_gRPC_PLATFORM_LINUX)
+  set_property(TARGET address_sorting PROPERTY VERSION ${CORE_VERSION})
+  set_property(TARGET address_sorting PROPERTY SOVERSION ${CORE_VERSION_MAJOR})
+endif()
 
 target_include_directories(address_sorting
   PUBLIC $<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@@ -903,6 +916,10 @@ if(WIN32 AND MSVC)
   endif()
 endif()
 
+if(_gRPC_PLATFORM_LINUX)
+  set_property(TARGET gpr PROPERTY VERSION ${CORE_VERSION})
+  set_property(TARGET gpr PROPERTY SOVERSION ${CORE_VERSION_MAJOR})
+endif()
 
 target_include_directories(gpr
   PUBLIC $<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@@ -1367,6 +1384,10 @@ if(WIN32 AND MSVC)
   endif()
 endif()
 
+if(_gRPC_PLATFORM_LINUX)
+  set_property(TARGET grpc PROPERTY VERSION ${CORE_VERSION})
+  set_property(TARGET grpc PROPERTY SOVERSION ${CORE_VERSION_MAJOR})
+endif()
 
 target_include_directories(grpc
   PUBLIC $<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@@ -1782,6 +1803,10 @@ if(WIN32 AND MSVC)
   endif()
 endif()
 
+if(_gRPC_PLATFORM_LINUX)
+  set_property(TARGET grpc_cronet PROPERTY VERSION ${CORE_VERSION})
+  set_property(TARGET grpc_cronet PROPERTY SOVERSION ${CORE_VERSION_MAJOR})
+endif()
 
 target_include_directories(grpc_cronet
   PUBLIC $<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@@ -2869,6 +2894,10 @@ if(WIN32 AND MSVC)
   endif()
 endif()
 
+if(_gRPC_PLATFORM_LINUX)
+  set_property(TARGET grpc_unsecure PROPERTY VERSION ${CORE_VERSION})
+  set_property(TARGET grpc_unsecure PROPERTY SOVERSION ${CORE_VERSION_MAJOR})
+endif()
 
 target_include_directories(grpc_unsecure
   PUBLIC $<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@@ -3206,6 +3235,10 @@ if(WIN32 AND MSVC)
   endif()
 endif()
 
+if(_gRPC_PLATFORM_LINUX)
+  set_property(TARGET grpc++ PROPERTY VERSION ${CPP_VERSION})
+  set_property(TARGET grpc++ PROPERTY SOVERSION ${CPP_VERSION_MAJOR})
+endif()
 
 target_include_directories(grpc++
   PUBLIC $<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@@ -3589,6 +3622,11 @@ protobuf_generate_grpc_cpp(
   src/proto/grpc/status/status.proto
 )
 
+if(_gRPC_PLATFORM_LINUX)
+  set_property(TARGET grpc++_error_details PROPERTY VERSION ${CPP_VERSION})
+  set_property(TARGET grpc++_error_details PROPERTY SOVERSION ${CPP_VERSION_MAJOR})
+endif()
+
 target_include_directories(grpc++_error_details
   PUBLIC $<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
   PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
@@ -3727,6 +3765,11 @@ protobuf_generate_grpc_cpp(
   src/proto/grpc/reflection/v1alpha/reflection.proto
 )
 
+if(_gRPC_PLATFORM_LINUX)
+  set_property(TARGET grpc++_reflection PROPERTY VERSION ${CPP_VERSION})
+  set_property(TARGET grpc++_reflection PROPERTY SOVERSION ${CPP_VERSION_MAJOR})
+endif()
+
 target_include_directories(grpc++_reflection
   PUBLIC $<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
   PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
@@ -3816,6 +3859,10 @@ target_link_libraries(grpc++_test_config
   ${_gRPC_GFLAGS_LIBRARIES}
 )
 
+if(_gRPC_PLATFORM_LINUX)
+  set_property(TARGET grpc++_cronet PROPERTY VERSION ${CPP_VERSION})
+  set_property(TARGET grpc++_cronet PROPERTY SOVERSION ${CPP_VERSION_MAJOR})
+endif()
 
 endif (gRPC_BUILD_TESTS)
 if (gRPC_BUILD_TESTS)
@@ -4307,6 +4354,10 @@ if(WIN32 AND MSVC)
   endif()
 endif()
 
+if(_gRPC_PLATFORM_LINUX)
+  set_property(TARGET grpc++_unsecure PROPERTY VERSION ${CPP_VERSION})
+  set_property(TARGET grpc++_unsecure PROPERTY SOVERSION ${CPP_VERSION_MAJOR})
+endif()
 
 target_include_directories(grpc++_unsecure
   PUBLIC $<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@@ -4745,6 +4796,10 @@ if(WIN32 AND MSVC)
   endif()
 endif()
 
+if(_gRPC_PLATFORM_LINUX)
+  set_property(TARGET grpc_plugin_support PROPERTY VERSION ${CORE_VERSION})
+  set_property(TARGET grpc_plugin_support PROPERTY SOVERSION ${CORE_VERSION_MAJOR})
+endif()
 
 target_include_directories(grpc_plugin_support
   PUBLIC $<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@@ -4813,6 +4868,11 @@ protobuf_generate_grpc_cpp(
   src/proto/grpc/channelz/channelz.proto
 )
 
+if(_gRPC_PLATFORM_LINUX)
+	set_property(TARGET grpcpp_channelz PROPERTY VERSION ${CPP_VERSION})
+  set_property(TARGET grpcpp_channelz PROPERTY SOVERSION ${CPP_VERSION_MAJOR})
+endif()
+
 target_include_directories(grpcpp_channelz
   PUBLIC $<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
   PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
@@ -5367,6 +5427,10 @@ if(WIN32 AND MSVC)
   endif()
 endif()
 
+if(_gRPC_PLATFORM_LINUX)
+  set_property(TARGET grpc_csharp_ext PROPERTY VERSION ${CSHARP_VERSION})
+  set_property(TARGET grpc_csharp_ext PROPERTY SOVERSION ${CSHARP_VERSION_MAJOR})
+endif()
 
 target_include_directories(grpc_csharp_ext
   PUBLIC $<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
