You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by do...@apache.org on 2023/06/10 05:17:15 UTC

[orc] branch main updated: ORC-1440: Check for protobuf config based module

This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/orc.git


The following commit(s) were added to refs/heads/main by this push:
     new b3b57dad9 ORC-1440: Check for protobuf config based module
b3b57dad9 is described below

commit b3b57dad9af071ca56fad2f5a33fd2237d8e8546
Author: Nehal J Wani <ne...@gmail.com>
AuthorDate: Fri Jun 9 22:17:07 2023 -0700

    ORC-1440: Check for protobuf config based module
    
    The recent versions of `libprotobuf` (>=4.22.0) provide their own CMake configs. We should check for the existence of the config and use the hand-rolled version as a fallback as it does not capture all deps.
    
    See also: https://gitlab.kitware.com/cmake/cmake/-/issues/24321
    
    Closes #1529 from nehaljwani/protobuf+cmake.
    
    Authored-by: Nehal J Wani <ne...@gmail.com>
    Signed-off-by: Dongjoon Hyun <do...@apache.org>
---
 cmake_modules/FindProtobuf.cmake | 82 +++++++++++++++++++++++++---------------
 1 file changed, 52 insertions(+), 30 deletions(-)

diff --git a/cmake_modules/FindProtobuf.cmake b/cmake_modules/FindProtobuf.cmake
index c52f3131d..cca7c8b87 100644
--- a/cmake_modules/FindProtobuf.cmake
+++ b/cmake_modules/FindProtobuf.cmake
@@ -32,36 +32,58 @@ endif()
 
 message (STATUS "PROTOBUF_HOME: ${PROTOBUF_HOME}")
 
-find_path (PROTOBUF_INCLUDE_DIR google/protobuf/io/zero_copy_stream.h HINTS
-  ${_protobuf_path}
-  NO_DEFAULT_PATH
-  PATH_SUFFIXES "include")
-
-find_path (PROTOBUF_INCLUDE_DIR google/protobuf/io/coded_stream.h HINTS
-  ${_protobuf_path}
-  NO_DEFAULT_PATH
-  PATH_SUFFIXES "include")
-
-find_library (PROTOBUF_LIBRARY NAMES protobuf HINTS
-  ${_protobuf_path}
-  PATH_SUFFIXES "lib")
-
-find_library (PROTOBUF_STATIC_LIB NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}protobuf${CMAKE_STATIC_LIBRARY_SUFFIX} HINTS
-  ${_protobuf_path}
-  PATH_SUFFIXES "lib")
-
-find_library (PROTOC_LIBRARY NAMES protoc HINTS
-  ${_protobuf_path}
-  PATH_SUFFIXES "lib")
-
-find_library (PROTOC_STATIC_LIB NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}protoc${CMAKE_STATIC_LIBRARY_SUFFIX} HINTS
-  ${_protobuf_path}
-  PATH_SUFFIXES "lib")
-
-find_program(PROTOBUF_EXECUTABLE protoc HINTS
-  ${_protobuf_path}
-  NO_DEFAULT_PATH
-  PATH_SUFFIXES "bin")
+find_package (Protobuf CONFIG)
+if (Protobuf_FOUND)
+    set (PROTOBUF_LIBRARY protobuf::libprotobuf)
+    set (PROTOBUF_STATIC_LIB PROTOBUF_STATIC_LIB-NOTFOUND)
+    set (PROTOC_LIBRARY protobuf::libprotoc)
+    set (PROTOC_STATIC_LIB PROTOC_STATIC_LIB-NOTFOUND)
+    set (PROTOBUF_EXECUTABLE protobuf::protoc)
+
+    get_target_property (target_type protobuf::libprotobuf TYPE)
+    if (target_type STREQUAL "STATIC_LIBRARY")
+        set(PROTOBUF_STATIC_LIB protobuf::libprotobuf)
+    endif ()
+
+    get_target_property (target_type protobuf::libprotoc TYPE)
+    if (target_type STREQUAL "STATIC_LIBRARY")
+        set (PROTOC_STATIC_LIB protobuf::libprotoc)
+    endif ()
+
+    get_target_property (PROTOBUF_INCLUDE_DIR protobuf::libprotoc INTERFACE_INCLUDE_DIRECTORIES)
+
+else()
+    find_path (PROTOBUF_INCLUDE_DIR google/protobuf/io/zero_copy_stream.h HINTS
+      ${_protobuf_path}
+      NO_DEFAULT_PATH
+      PATH_SUFFIXES "include")
+
+    find_path (PROTOBUF_INCLUDE_DIR google/protobuf/io/coded_stream.h HINTS
+      ${_protobuf_path}
+      NO_DEFAULT_PATH
+      PATH_SUFFIXES "include")
+
+    find_library (PROTOBUF_LIBRARY NAMES protobuf HINTS
+      ${_protobuf_path}
+      PATH_SUFFIXES "lib")
+
+    find_library (PROTOBUF_STATIC_LIB NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}protobuf${CMAKE_STATIC_LIBRARY_SUFFIX} HINTS
+      ${_protobuf_path}
+      PATH_SUFFIXES "lib")
+
+    find_library (PROTOC_LIBRARY NAMES protoc HINTS
+      ${_protobuf_path}
+      PATH_SUFFIXES "lib")
+
+    find_library (PROTOC_STATIC_LIB NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}protoc${CMAKE_STATIC_LIBRARY_SUFFIX} HINTS
+      ${_protobuf_path}
+      PATH_SUFFIXES "lib")
+
+    find_program(PROTOBUF_EXECUTABLE protoc HINTS
+      ${_protobuf_path}
+      NO_DEFAULT_PATH
+      PATH_SUFFIXES "bin")
+endif ()
 
 if (PROTOBUF_INCLUDE_DIR AND PROTOBUF_LIBRARY AND PROTOC_LIBRARY AND PROTOBUF_EXECUTABLE)
   set (PROTOBUF_FOUND TRUE)