You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ap...@apache.org on 2019/03/19 18:07:42 UTC

[arrow] branch master updated: ARROW-4946: [C++] Support detection of flatbuffers without FlatbuffersConfig.cmake

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

apitrou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new c05687d  ARROW-4946: [C++] Support detection of flatbuffers without FlatbuffersConfig.cmake
c05687d is described below

commit c05687dac02f0808dc5f2b24d1d776617ba3140f
Author: Uwe L. Korn <xh...@users.noreply.github.com>
AuthorDate: Tue Mar 19 19:07:33 2019 +0100

    ARROW-4946: [C++] Support detection of flatbuffers without FlatbuffersConfig.cmake
    
    Author: Uwe L. Korn <xh...@users.noreply.github.com>
    Author: Korn, Uwe <Uw...@blue-yonder.com>
    
    Closes #3973 from xhochy/ARROW-4946 and squashes the following commits:
    
    692bd863d <Uwe L. Korn> Add comment about FlatbuffersAlt
    897ba5e6c <Korn, Uwe> ARROW-4946:  Support detection of flatbuffers without FlatbuffersConfig.cmake
---
 cpp/cmake_modules/FindFlatbuffersAlt.cmake  | 56 +++++++++++++++++++++++++++++
 cpp/cmake_modules/ThirdpartyToolchain.cmake | 21 ++++++++++-
 run-cmake-format.py                         |  1 +
 3 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/cpp/cmake_modules/FindFlatbuffersAlt.cmake b/cpp/cmake_modules/FindFlatbuffersAlt.cmake
new file mode 100644
index 0000000..245f94a
--- /dev/null
+++ b/cpp/cmake_modules/FindFlatbuffersAlt.cmake
@@ -0,0 +1,56 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+if(Flatbuffers_ROOT)
+  find_library(FLATBUFFERS_LIB
+               NAMES flatbuffers
+               PATHS ${Flatbuffers_ROOT}
+               NO_DEFAULT_PATH
+               PATH_SUFFIXES "lib")
+  find_path(FLATBUFFERS_INCLUDE_DIR
+            NAMES flatbuffers/flatbuffers.h
+            PATHS ${Flatbuffers_ROOT}
+            NO_DEFAULT_PATH
+            PATH_SUFFIXES "include")
+  find_program(FLATC
+               NAMES flatc
+               PATHS ${Flatbuffers_ROOT}
+               NO_DEFAULT_PATH
+               PATH_SUFFIXES "bin")
+else()
+  find_library(FLATBUFFERS_LIB NAMES flatbuffers)
+  find_path(FLATBUFFERS_INCLUDE_DIR
+            NAMES flatbuffers/flatbuffers.h
+            PATH_SUFFIXES "include")
+  find_program(FLATC NAMES flatc PATHS PATH_SUFFIXES "bin")
+endif()
+
+find_package_handle_standard_args(FlatbuffersAlt
+                                  REQUIRED_VARS
+                                  FLATBUFFERS_LIB
+                                  FLATBUFFERS_INCLUDE_DIR
+                                  FLATC)
+
+if(FlatbuffersAlt_FOUND)
+  add_library(flatbuffers::flatbuffers UNKNOWN IMPORTED)
+  set_target_properties(flatbuffers::flatbuffers
+                        PROPERTIES IMPORTED_LOCATION "${FLATBUFFERS_LIB}"
+                                   INTERFACE_INCLUDE_DIRECTORIES
+                                   "${FLATBUFFERS_INCLUDE_DIR}")
+  add_executable(flatbuffers::flatc IMPORTED)
+  set_target_properties(flatbuffers::flatc PROPERTIES IMPORTED_LOCATION "${FLATC}")
+endif()
diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake
index 5c23e50..a392484 100644
--- a/cpp/cmake_modules/ThirdpartyToolchain.cmake
+++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake
@@ -1482,7 +1482,26 @@ macro(build_flatbuffers)
 endmacro()
 
 if(ARROW_WITH_FLATBUFFERS)
-  resolve_dependency(Flatbuffers)
+  get_dependency_source(Flatbuffers)
+  if(Flatbuffers_SOURCE STREQUAL "AUTO")
+    find_package(Flatbuffers QUIET)
+    # Older versions of Flatbuffers (that are not built using CMake)
+    # don't install a FlatbuffersConfig.cmake
+    # This is only supported from 1.10+ on, we support at least 1.7
+    if(NOT Flatbuffers_FOUND)
+      find_package(FlatbuffersAlt)
+    endif()
+    if(NOT Flatbuffers_FOUND AND NOT FlatbuffersAlt_FOUND)
+      build_flatbuffers()
+    endif()
+  elseif(Flatbuffers_SOURCE STREQUAL "BUNDLED")
+    build_flatbuffers()
+  elseif(Flatbuffers_SOURCE STREQUAL "SYSTEM")
+    find_package(Flatbuffers QUIET)
+    if(NOT Flatbuffers_FOUND)
+      find_package(FlatbuffersAlt REQUIRED)
+    endif()
+  endif()
 
   if(TARGET flatbuffers::flatbuffers_shared AND NOT TARGET flatbuffers::flatbuffers)
     get_target_property(FLATBUFFERS_INCLUDE_DIR flatbuffers::flatbuffers_shared
diff --git a/run-cmake-format.py b/run-cmake-format.py
index 4617fb9..9c179a8 100755
--- a/run-cmake-format.py
+++ b/run-cmake-format.py
@@ -32,6 +32,7 @@ patterns = [
     'cpp/cmake_modules/FindBrotli.cmake',
     'cpp/cmake_modules/FindClangTools.cmake',
     'cpp/cmake_modules/FindDoubleConversion.cmake',
+    'cpp/cmake_modules/FindFlatbuffersAlt.cmake',
     'cpp/cmake_modules/FindGLOG.cmake',
     'cpp/cmake_modules/FindGandiva.cmake',
     'cpp/cmake_modules/FindInferTools.cmake',