Skip to content

Commit

Permalink
Merge pull request #5112 from rouault/cmake_hdfs
Browse files Browse the repository at this point in the history
CMake: add support for libhdfs (for /vsihdfs)
  • Loading branch information
rouault authored Jan 15, 2022
2 parents 446aa07 + 6ed403b commit e0fda92
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmake/helpers/CheckDependentLibraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ else ()
endif ()
unset(TMP_GRASS)

gdal_check_package(HDFS "Enable Hadoop File System through native library" CAN_DISABLE)

# PDF library: one of them enables PDF driver
gdal_check_package(Poppler "Enable PDF driver (read side)" CAN_DISABLE)

Expand Down
46 changes: 46 additions & 0 deletions cmake/modules/packages/FindHDFS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

#[=======================================================================[.rst:
FindHDFS
--------
The following vars are set if HDFS (the native library provided with Hadoop) is found.
.. variable:: HDFS_FOUND
True if found, otherwise all other vars are undefined
.. variable:: HDFS_INCLUDE_DIR
The include dir for hdfs.h
.. variable:: HDFS_LIBRARY
The library file
#]=======================================================================]


include(FindPackageHandleStandardArgs)

find_path(HDFS_INCLUDE_DIR NAMES hdfs.h)
find_library(HDFS_LIBRARY NAMES hdfs PATH_SUFFIXES native)

mark_as_advanced(HDFS_INCLUDE_DIR HDFS_LIBRARY)
find_package_handle_standard_args(HDFS
FOUND_VAR HDFS_FOUND
REQUIRED_VARS HDFS_LIBRARY HDFS_INCLUDE_DIR)

if(HDFS_FOUND)
set(HDFS_LIBRARIES ${HDFS_LIBRARY})
set(HDFS_INCLUDE_DIRS ${HDFS_INCLUDE_DIR})

if(NOT TARGET HDFS::HDFS)
add_library(HDFS::HDFS UNKNOWN IMPORTED)
set_target_properties(HDFS::HDFS PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${HDFS_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${HDFS_LIBRARY}")
endif()
endif()
19 changes: 19 additions & 0 deletions doc/source/build_hints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,25 @@ The https://cmake.org/cmake/help/latest/module/FindHDF5.html module is used to
detect the HDF5 library.


HDFS
****

The `Hadoop File System <https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-hdfs/LibHdfs.html>`_ native library is needed
for the :ref:`/vsihdfs/ <vsihdfs>` virtual file system.

.. option:: HDFS_INCLUDE_DIR

Path to an include directory with the ``hdfs.h`` header file.

.. option:: HDFS_LIBRARY

Path to a shared or static ``hdfs`` library file.

.. option:: GDAL_USE_HDFS=ON/OFF

Control whether to use HDFS. Defaults to ON when HDFS is found.


Iconv
*****

Expand Down
6 changes: 6 additions & 0 deletions port/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,9 @@ if (GDAL_USE_BLOSC)
target_include_directories(cpl PRIVATE $<TARGET_PROPERTY:Blosc::Blosc,INTERFACE_INCLUDE_DIRECTORIES>)
gdal_add_private_link_libraries(Blosc::Blosc)
endif ()

if (GDAL_USE_HDFS)
target_compile_definitions(cpl PRIVATE -DHDFS_ENABLED)
target_include_directories(cpl PRIVATE $<TARGET_PROPERTY:HDFS::HDFS,INTERFACE_INCLUDE_DIRECTORIES>)
gdal_add_private_link_libraries(HDFS::HDFS)
endif ()

0 comments on commit e0fda92

Please sign in to comment.