File 0004-cmake-Add-support-for-installation.patch of Package upb

From 5dbb50a82a4625ce1a1796707a56c490f25c412c Mon Sep 17 00:00:00 2001
From: Michal Rostecki <mrostecki@opensuse.org>
Date: Mon, 4 Nov 2019 12:11:44 +0100
Subject: [PATCH 4/5] cmake: Add support for installation

This change makes use of CMake GNUInstallDirs module and allows to
install upb on the system with `make install` target.

Signed-off-by: Michal Rostecki <mrostecki@opensuse.org>
---
 CMakeLists.txt | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 17bcdbf..d0a5c7e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,6 +13,12 @@ cmake_policy(SET CMP0048 NEW)
 
 project(upb)
 
+include(GNUInstallDirs)
+
+if(NOT DEFINED CMAKE_INSTALL_CMAKEDIR)
+  set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/upb")
+endif()
+
 set(upb_SOVERSION 0)
 
 # Prevent CMake from setting -rdynamic on Linux (!!).
@@ -78,6 +84,9 @@ add_library(upb
   upb/upb.h)
 set_target_properties(upb PROPERTIES
   SOVERSION ${upb_SOVERSION})
+install(TARGETS upb EXPORT upb-targets
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
 add_library(generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE)
 target_link_libraries(generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE
   upb)
@@ -86,6 +95,9 @@ add_library(descriptor_upbproto
   generated_for_cmake/google/protobuf/descriptor.upb.h)
 set_target_properties(descriptor_upbproto PROPERTIES
   SOVERSION ${upb_SOVERSION})
+install(TARGETS descriptor_upbproto EXPORT descriptor_upbproto-targets
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
 add_library(upb_reflection
   upb/def.c
   upb/msgfactory.c
@@ -97,6 +109,9 @@ target_link_libraries(upb_reflection
   descriptor_upbproto
   table
   upb)
+install(TARGETS upb_reflection EXPORT upb_reflection-targets
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
 add_library(table INTERFACE)
 target_link_libraries(table INTERFACE
   upb)
@@ -108,6 +123,9 @@ set_target_properties(upb_legacy_msg_reflection PROPERTIES
 target_link_libraries(upb_legacy_msg_reflection
   table
   upb)
+install(TARGETS upb_legacy_msg_reflection EXPORT upb_legacy_msg_reflection-targets
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
 add_library(upb_handlers
   upb/handlers.c
   upb/handlers-inl.h
@@ -120,6 +138,9 @@ target_link_libraries(upb_handlers
   upb_reflection
   table
   upb)
+install(TARGETS upb_handlers EXPORT upb_handlers-targets
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
 add_library(upb_pb
   upb/pb/compile_decoder.c
   upb/pb/decoder.c
@@ -139,6 +160,9 @@ target_link_libraries(upb_pb
   upb_reflection
   table
   upb)
+install(TARGETS upb_pb EXPORT upb_pb-targets
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
 add_library(upb_json
   generated_for_cmake/upb/json/parser.c
   upb/json/printer.c
@@ -149,6 +173,9 @@ set_target_properties(upb_json PROPERTIES
 target_link_libraries(upb_json
   upb
   upb_pb)
+install(TARGETS upb_json EXPORT upb_json-targets
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
 add_library(upb_cc_bindings INTERFACE)
 target_link_libraries(upb_cc_bindings INTERFACE
   descriptor_upbproto
@@ -161,5 +188,11 @@ add_library(upb_test
 target_link_libraries(upb_test
   upb_handlers
   upb)
-
-
+install(FILES
+  upb/decode.h
+  upb/encode.h
+  upb/generated_util.h
+  upb/msg.h
+  upb/port_def.inc
+  upb/port_undef.inc
+  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/upb)
-- 
2.16.4

openSUSE Build Service is sponsored by