From cda57436a37449dfc8ca38f11d7d5ff6c094b988 Mon Sep 17 00:00:00 2001
From: Steven Murray <Steven.Murray@cern.ch>
Date: Mon, 19 Jun 2017 14:02:38 +0200
Subject: [PATCH] Moved to protocol buffer rpms built by koji

---
 ...FindProtobuf.cmake => FindProtobuf3.cmake} | 32 ++++++++++++++-----
 cta.spec.in                                   |  2 +-
 eos/messages/CMakeLists.txt                   | 11 ++++---
 mediachanger/CMakeLists.txt                   |  7 ++--
 objectstore/CMakeLists.txt                    | 16 +++++-----
 scheduler/CMakeLists.txt                      |  4 ++-
 tapeserver/CMakeLists.txt                     |  3 +-
 tapeserver/castor/messages/CMakeLists.txt     |  7 ++--
 .../tape/tapeserver/daemon/CMakeLists.txt     |  5 +--
 tapeserver/daemon/CMakeLists.txt              |  5 +--
 tests/CMakeLists.txt                          |  4 ++-
 xroot_plugins/CMakeLists.txt                  |  4 ++-
 12 files changed, 65 insertions(+), 35 deletions(-)
 rename cmake/{FindProtobuf.cmake => FindProtobuf3.cmake} (67%)

diff --git a/cmake/FindProtobuf.cmake b/cmake/FindProtobuf3.cmake
similarity index 67%
rename from cmake/FindProtobuf.cmake
rename to cmake/FindProtobuf3.cmake
index ecc6ff39a5..2c0e00b315 100644
--- a/cmake/FindProtobuf.cmake
+++ b/cmake/FindProtobuf3.cmake
@@ -15,15 +15,27 @@
 # (To distribute this file outside of CMake, substitute the full
 #  License text for the above reference.)
 
-find_program(PROTOBUF_PROTOC_EXECUTABLE
-    NAMES protoc
-    DOC "The Google Protocol Buffers Compiler"
+find_program(PROTOBUF3_PROTOC3_EXECUTABLE
+    NAMES protoc3
+    DOC "Version 3 of The Google Protocol Buffers Compiler"
 )
+message(STATUS "protoc3 is at ${PROTOBUF3_PROTOC3_EXECUTABLE} ")
 
-message(STATUS "protoc is at ${PROTOBUF_PROTOC_EXECUTABLE} ")
-function(PROTOBUF_GENERATE_CPP SRCS HDRS)
+find_path(PROTOBUF3_INCLUDE_DIRS
+  google/protobuf/message.h
+  PATHS /usr/include/protobuf3
+  NO_DEFAULT_PATH)
+message(STATUS "PROTOBUF3_INCLUDE_DIRS=${PROTOBUF3_INCLUDE_DIRS}")
+
+find_library(PROTOBUF3_LIBRARIES
+  NAME protobuf
+  PATHS /usr/lib64/protobuf3
+  NO_DEFAULT_PATH)
+message(STATUS "PROTOBUF3_LIBRARIES=${PROTOBUF3_LIBRARIES}")
+
+function(PROTOBUF3_GENERATE_CPP SRCS HDRS)
   if(NOT ARGN)
-    message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files")
+    message(SEND_ERROR "Error: PROTOBUF3_GENERATE_CPP() called without any proto files")
     return()
   endif()
 
@@ -41,7 +53,7 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS)
     add_custom_command(
       OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
              "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
-      COMMAND  ${PROTOBUF_PROTOC_EXECUTABLE}
+      COMMAND  ${PROTOBUF3_PROTOC3_EXECUTABLE}
       ARGS --cpp_out  ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
       DEPENDS ${ABS_FIL}
       COMMENT "Running C++ protocol buffer compiler on ${FIL}"
@@ -51,4 +63,8 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS)
   set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
   set(${SRCS} ${${SRCS}} PARENT_SCOPE)
   set(${HDRS} ${${HDRS}} PARENT_SCOPE)
-endfunction()
\ No newline at end of file
+endfunction()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Protobuf3 DEFAULT_MSG
+  PROTOBUF3_INCLUDE_DIRS PROTOBUF3_LIBRARIES)
diff --git a/cta.spec.in b/cta.spec.in
index b4fbf7b5a0..04e7c8588a 100644
--- a/cta.spec.in
+++ b/cta.spec.in
@@ -42,7 +42,7 @@ BuildRequires: xrootd-devel         = 1:4.4.1
 BuildRequires: xrootd-server-devel  = 1:4.4.1
 BuildRequires: xrootd-private-devel = 1:4.4.1
 BuildRequires: librados-devel >= 11.0, libradosstriper-devel >= 11.0, 
-BuildRequires: protobuf3-compiler = 3.2.0 protobuf3-devel = 3.2.0
+BuildRequires: protobuf3-compiler >= 3.3.1 protobuf3-devel >= 3.3.1
 BuildRequires: gmock-devel >= 1.5.0 gtest-devel >= 1.5.0
 BuildRequires: sqlite-devel >= 3.6
 BuildRequires: libcap-devel >= 2.16
diff --git a/eos/messages/CMakeLists.txt b/eos/messages/CMakeLists.txt
index dbf65671bf..866bd4376d 100644
--- a/eos/messages/CMakeLists.txt
+++ b/eos/messages/CMakeLists.txt
@@ -15,14 +15,17 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 cmake_minimum_required (VERSION 2.6)
 
-find_package(Protobuf REQUIRED)
+find_package(Protobuf3 REQUIRED)
 
 file(GLOB ProtoFiles "${CMAKE_CURRENT_SOURCE_DIR}/*.proto")
-PROTOBUF_GENERATE_CPP(ProtoSources ProtoHeaders ${ProtoFiles})
-
+PROTOBUF3_GENERATE_CPP(ProtoSources ProtoHeaders ${ProtoFiles})
+foreach(PROTO_SRC ${ProtoSources})
+  set_property(SOURCE ${PROTO_SRC} PROPERTY COMPILE_FLAGS " -Wno-missing-field-initializers")
+endforeach(PROTO_SRC)
 set (CTA_FRONT_END_MESSAGES_SRC_FILES ${ProtoSources})
 
+include_directories(${PROTOBUF3_INCLUDE_DIRS})
 add_library (ctaeosmessages ${CTA_FRONT_END_MESSAGES_SRC_FILES})
 
 target_link_libraries (ctaeosmessages
-  protobuf)
+  ${PROTOBUF3_LIBRARIES})
diff --git a/mediachanger/CMakeLists.txt b/mediachanger/CMakeLists.txt
index 91a78ca728..f108728bc6 100644
--- a/mediachanger/CMakeLists.txt
+++ b/mediachanger/CMakeLists.txt
@@ -16,11 +16,11 @@
 cmake_minimum_required (VERSION 2.6)
 
 find_package(openssl REQUIRED)
-find_package(Protobuf REQUIRED)
+find_package(Protobuf3 REQUIRED)
 find_package(zeromq REQUIRED)
 
 file(GLOB ProtoFiles "${CMAKE_CURRENT_SOURCE_DIR}/*.proto")
-PROTOBUF_GENERATE_CPP(ProtoSources ProtoHeaders ${ProtoFiles})
+PROTOBUF3_GENERATE_CPP(ProtoSources ProtoHeaders ${ProtoFiles})
 
 set (MEDIACHANGER_LIB_SRC_FILES
   AcsLibrarySlot.cpp
@@ -52,12 +52,13 @@ set (MEDIACHANGER_LIB_SRC_FILES
   ZmqMsg.cpp
   ZmqSocket.cpp)
 
+include_directories (${PROTOBUF3_INCLUDE_DIRS})
 add_library (ctamediachanger SHARED
   ${MEDIACHANGER_LIB_SRC_FILES})
 
 target_link_libraries (ctamediachanger
   ctacommon
-  protobuf
+  ${PROTOBUF3_LIBRARIES}
   ssl
   zmq)
 
diff --git a/objectstore/CMakeLists.txt b/objectstore/CMakeLists.txt
index 59b55d8be7..c6e2b65c83 100644
--- a/objectstore/CMakeLists.txt
+++ b/objectstore/CMakeLists.txt
@@ -22,12 +22,12 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../middletier)
 
 find_package(json-c REQUIRED)
 find_package(librados2 REQUIRED)
-find_package(Protobuf REQUIRED)
+find_package(Protobuf3 REQUIRED)
 
 set (CTAProtoFiles
   cta.proto)
 
-PROTOBUF_GENERATE_CPP(CTAProtoSources CTAProtoHeaders ${CTAProtoFiles})
+PROTOBUF3_GENERATE_CPP(CTAProtoSources CTAProtoHeaders ${CTAProtoFiles})
 
 set (CTAProtoDependants objectstore/Agent.hpp
   objectstore/ArchiveRequest.hpp
@@ -46,7 +46,7 @@ SET_SOURCE_FILES_PROPERTIES(${CTAProtoHeaders} PROPERTIES HEADER_FILE_ONLY TRUE)
 SET_SOURCE_FILES_PROPERTIES(${CTAProtoDependants} 
   PROPERTIES OBJECT_DEPENDS ${CTAProtoHeaders})
 
-
+include_directories (${PROTOBUF3_INCLUDE_DIRS})
 add_library (ctaobjectstore SHARED
   ${CTAProtoSources}
   RootEntry.cpp
@@ -83,24 +83,24 @@ set(ObjectStoreUnitTests
 
 add_library(ctaobjectstoreunittests SHARED ${ObjectStoreUnitTests})
 target_link_libraries(ctaobjectstoreunittests
-  protobuf rados ctacommon gtest ctaobjectstore)
+  ${PROTOBUF3_LIBRARIES} rados ctacommon gtest ctaobjectstore)
 install(TARGETS ctaobjectstoreunittests DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
 
 add_executable(cta-objectstore-initialize cta-objectstore-initialize.cpp)
 target_link_libraries(cta-objectstore-initialize
-  protobuf ctaobjectstore ctacommon ctautils)
+  ${PROTOBUF3_LIBRARIES} ctaobjectstore ctacommon ctautils)
 
 add_executable(cta-objectstore-list cta-objectstore-list.cpp)
 target_link_libraries(cta-objectstore-list
-  protobuf ctaobjectstore ctacommon)
+  ${PROTOBUF3_LIBRARIES} ctaobjectstore ctacommon)
 
 add_executable(cta-objectstore-dump-object cta-objectstore-dump-object.cpp)
 target_link_libraries(cta-objectstore-dump-object
-  protobuf ctaobjectstore ctacommon)
+  ${PROTOBUF3_LIBRARIES} ctaobjectstore ctacommon)
 
 add_executable(cta-objectstore-unfollow-agent cta-objectstore-unfollow-agent.cpp)
 target_link_libraries(cta-objectstore-unfollow-agent
-  protobuf ctaobjectstore ctacommon)
+  ${PROTOBUF3_LIBRARIES} ctaobjectstore ctacommon)
 
 install(TARGETS cta-objectstore-initialize cta-objectstore-list cta-objectstore-dump-object
   DESTINATION usr/bin)
diff --git a/scheduler/CMakeLists.txt b/scheduler/CMakeLists.txt
index 6a3a468966..f85148c63b 100644
--- a/scheduler/CMakeLists.txt
+++ b/scheduler/CMakeLists.txt
@@ -21,11 +21,13 @@ set (CTA_SCHEDULER_SRC_FILES
   OStoreDB/OStoreDBWithAgent.cpp
   LabelMount.cpp)
 
+find_package(Protobuf3 REQUIRED)
+include_directories (${PROTOBUF3_INCLUDE_DIRS})
 add_library (ctascheduler SHARED
   ${CTA_SCHEDULER_SRC_FILES})
 install (TARGETS ctascheduler DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
 
-target_link_libraries (ctascheduler ctacommon ctaobjectstore protobuf ctautils ctaeos)
+target_link_libraries (ctascheduler ctacommon ctaobjectstore ${PROTOBUF3_LIBRARIES} ctautils ctaeos)
 
 #add_library (ctaschedulerutils SHARED
 #  _old_prototype_DummyScheduler.cpp)
diff --git a/tapeserver/CMakeLists.txt b/tapeserver/CMakeLists.txt
index ef4a7c477e..31881c29f0 100644
--- a/tapeserver/CMakeLists.txt
+++ b/tapeserver/CMakeLists.txt
@@ -10,8 +10,9 @@ add_subdirectory (session)
 # from the previous one to create a single library).
 
 add_executable (cta-taped cta-taped.cpp)
+find_package(Protobuf3 REQUIRED)
 target_link_libraries(cta-taped
-  ctatapedaemon ctacommon protobuf)
+  ctatapedaemon ctacommon ${PROTOBUF3_LIBRARIES})
 install (TARGETS cta-taped DESTINATION usr/bin)
 install (FILES TPCONFIG.example DESTINATION /etc/cta)
 install (FILES cta-taped.1cta DESTINATION /usr/share/man/man1)
diff --git a/tapeserver/castor/messages/CMakeLists.txt b/tapeserver/castor/messages/CMakeLists.txt
index 3cd7032bbd..bcc9f6a09a 100644
--- a/tapeserver/castor/messages/CMakeLists.txt
+++ b/tapeserver/castor/messages/CMakeLists.txt
@@ -21,12 +21,13 @@ include_directories(${PROJECT_SOURCE_DIR}/tapeserver)
 include_directories(${PROJECT_BINARY_DIR}/tapeserver)
 
 find_package(openssl REQUIRED)
-find_package(Protobuf REQUIRED)
+find_package(Protobuf3 REQUIRED)
 find_package(zeromq REQUIRED)
 
 file(GLOB ProtoFiles "${CMAKE_CURRENT_SOURCE_DIR}/*.proto")
-PROTOBUF_GENERATE_CPP(ProtoSources ProtoHeaders ${ProtoFiles})
+PROTOBUF3_GENERATE_CPP(ProtoSources ProtoHeaders ${ProtoFiles})
 
+include_directories (${PROTOBUF3_INCLUDE_DIRS})
 add_library(ctamessagesprotobuf
   ${ProtoSources})
 
@@ -52,5 +53,5 @@ target_link_libraries(ctamessages
   ctamediachanger
   ctautils
   ctatapesession
-  protobuf
+  ${PROTOBUF3_LIBRARIES}
   ssl)
diff --git a/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt b/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt
index a34cc31f4c..00ee282cca 100644
--- a/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt
+++ b/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt
@@ -26,7 +26,7 @@ include_directories(${PROJECT_BINARY_DIR}/tapeserver)
 include_directories(${CMAKE_SOURCE_DIR})
 include_directories(${PROJECT_BINARY_DIR})
 
-find_package(Protobuf REQUIRED)
+find_package(Protobuf3 REQUIRED)
 find_package( ZLIB REQUIRED )
 
 set(CTATAPESERVERDAEMON_LIBRARY_SRCS
@@ -76,9 +76,10 @@ endif(CMAKE_COMPILER_IS_GNUCC)
 add_library(ctaTapeServerDaemon 
   ${CTATAPESERVERDAEMON_LIBRARY_SRCS})
 
-target_link_libraries(ctaTapeServerDaemon ctamessages ctacommon protobuf ctascheduler ctalegacymsg ctacatalogue TapeDrive)
+target_link_libraries(ctaTapeServerDaemon ctamessages ctacommon ${PROTOBUF3_LIBRARIES} ctascheduler ctalegacymsg ctacatalogue TapeDrive)
 add_dependencies(ctaTapeServerDaemon ctamessagesprotobuf)
 
+include_directories(${PROTOBUF3_INCLUDE_DIRS})
 add_library(ctatapeserverdaemonunittests SHARED
   DataTransferSessionTest.cpp
   DiskReadTaskTest.cpp
diff --git a/tapeserver/daemon/CMakeLists.txt b/tapeserver/daemon/CMakeLists.txt
index 0398d28f9f..e8de0817e0 100644
--- a/tapeserver/daemon/CMakeLists.txt
+++ b/tapeserver/daemon/CMakeLists.txt
@@ -1,14 +1,15 @@
 cmake_minimum_required (VERSION 2.6)
 
-find_package(Protobuf REQUIRED)
+find_package(Protobuf3 REQUIRED)
 
 include_directories(${PROJECT_BINARY_DIR}/tapeserver)
 
-PROTOBUF_GENERATE_CPP(WDMsgSources WDMsgHeaders WatchdogMessage.proto)
+PROTOBUF3_GENERATE_CPP(WDMsgSources WDMsgHeaders WatchdogMessage.proto)
 
 SET_SOURCE_FILES_PROPERTIES(${WDMsgHeaders} PROPERTIES HEADER_FILE_ONLY TRUE)
 SET_SOURCE_FILES_PROPERTIES(DriveHandler.cpp PROPERTIES OBJECT_DEPENDS ${WDMsgHeaders})
 
+include_directories(${PROTOBUF3_INCLUDE_DIRS})
 add_library(ctatapedaemon
   ${WDMsgSources}
   CommandLineParams.cpp
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index f818d1958b..9f459e3a2d 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -56,13 +56,15 @@ add_executable(cta-unitTests-multiProcess
   unit_tests.cpp
   ${GMOCK_SRC})
 
+find_package(Protobuf3 REQUIRED)
+
 target_link_libraries(cta-unitTests-multiProcess
   ctadaemonunittests-multiprocess
   ctacommon
   ${GMOCK_LIB}
   gtest
   pthread
-  protobuf
+  ${PROTOBUF3_LIBRAIRES}
   sqlite3)
 
 add_library(unitTestHelper
diff --git a/xroot_plugins/CMakeLists.txt b/xroot_plugins/CMakeLists.txt
index 386b5a3d35..6b7b6f898e 100644
--- a/xroot_plugins/CMakeLists.txt
+++ b/xroot_plugins/CMakeLists.txt
@@ -22,8 +22,10 @@ include_directories(${XROOTD_INCLUDE_DIR} ${XROOTD_PRIVATE_INCLUDE_DIR})
 include_directories(${CMAKE_BINARY_DIR})
 include_directories(${CMAKE_SOURCE_DIR}/tapeserver)
 
+find_package(Protobuf3 REQUIRED)
+include_directories(${PROTOBUF3_INCLUDE_DIRS})
 add_library (XrdCtaOfs MODULE XrdCtaFilesystem.cpp XrdCtaFile.cpp XrdCtaDir.cpp)
-target_link_libraries (XrdCtaOfs ctacatalogue ctaeosmessages ctascheduler ctacommon protobuf ctaobjectstore cryptopp)
+target_link_libraries (XrdCtaOfs ctacatalogue ctaeosmessages ctascheduler ctacommon ${PROTOBUF3_LIBRARIES} ctaobjectstore cryptopp)
 
 INSTALL (TARGETS XrdCtaOfs DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
 INSTALL (FILES xrootd-cta.cfg DESTINATION /etc/xrootd/)
-- 
GitLab