Skip to content

Commit

Permalink
Add iceberg_arrow library
Browse files Browse the repository at this point in the history
- add libiceberg_arrow
- use single config file with three separate targets to support components
- add fetchcontent support
  • Loading branch information
wgtmac committed Dec 25, 2024
1 parent 9f99f85 commit 65021dc
Show file tree
Hide file tree
Showing 15 changed files with 443 additions and 83 deletions.
18 changes: 12 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,30 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(WIN32 AND NOT MINGW)
# This is used to handle builds using e.g. clang in an MSVC setting.
set(MSVC_TOOLCHAIN TRUE)
else()
set(MSVC_TOOLCHAIN FALSE)
endif()

option(ICEBERG_BUILD_STATIC "Build static library" ON)
option(ICEBERG_BUILD_SHARED "Build shared library" OFF)
option(ICEBERG_BUILD_TESTS "Build tests" ON)
option(ICEBERG_ARROW "Build Arrow" ON)

include(CMakePackageConfigHelpers)
include(CMakeParseArguments)
include(BuildUtils)
include(ExternalProject)
include(FindPackageHandleStandardArgs)
include(GNUInstallDirs)

set(ICEBERG_API_DIR "${CMAKE_SOURCE_DIR}/api")
set(ICEBERG_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
set(ICEBERG_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}")
set(ICEBERG_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(ICEBERG_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake")
set(ICEBERG_INSTALL_DOCDIR "share/doc/${PROJECT_NAME}")

include(CMakeParseArguments)
include(BuildUtils)
include(ThirdpartyToolchain)

add_subdirectory(api)
add_subdirectory(src)

Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@ cmake --build .
cmake --install .
```

### Build and Install Iceberg Arrow Libraries

#### Vendored Apache Arrow (default)
```bash
cd iceberg-cpp/src/arrow
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/install -DICEBERG_ARROW=ON
cmake --build .
cmake --install .
```

#### Provided Apache Arrow

```bash
cd iceberg-cpp/src/arrow
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/install -DArrow_SOURCE=SYSTEM -DArrow_ROOT=/path/to/arrow
cmake --build .
cmake --install .
```

Please note that `-DArrow_ROOT=/path/to/arrow` is required when building examples below when using provided Apache Arrow.

### Build Examples

After installing the core libraries, you can build the examples:
Expand Down
33 changes: 8 additions & 25 deletions cmake_modules/BuildUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,11 @@
# Borrowed the file from Apache Arrow:
# https://github.com/apache/arrow/blob/main/cpp/cmake_modules/BuildUtils.cmake

function(iceberg_install_cmake_package PACKAGE_NAME EXPORT_NAME)
set(CONFIG_CMAKE "${PACKAGE_NAME}Config.cmake")
set(BUILT_CONFIG_CMAKE "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_CMAKE}")
configure_package_config_file("${CONFIG_CMAKE}.in" "${BUILT_CONFIG_CMAKE}"
INSTALL_DESTINATION "${ICEBERG_INSTALL_CMAKEDIR}/${PACKAGE_NAME}"
)
set(CONFIG_VERSION_CMAKE "${PACKAGE_NAME}ConfigVersion.cmake")
set(BUILT_CONFIG_VERSION_CMAKE "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_VERSION_CMAKE}")
write_basic_package_version_file("${BUILT_CONFIG_VERSION_CMAKE}"
COMPATIBILITY SameMajorVersion)
install(FILES "${BUILT_CONFIG_CMAKE}" "${BUILT_CONFIG_VERSION_CMAKE}"
DESTINATION "${ICEBERG_INSTALL_CMAKEDIR}/${PACKAGE_NAME}")
set(TARGETS_CMAKE "${PACKAGE_NAME}Targets.cmake")
install(EXPORT ${EXPORT_NAME}
DESTINATION "${ICEBERG_INSTALL_CMAKEDIR}/${PACKAGE_NAME}"
NAMESPACE "${PACKAGE_NAME}::"
FILE "${TARGETS_CMAKE}")
endfunction()

function(ADD_ICEBERG_LIB LIB_NAME)
set(options)
set(one_value_args
BUILD_SHARED
BUILD_STATIC
CMAKE_PACKAGE_NAME
INSTALL_ARCHIVE_DIR
INSTALL_LIBRARY_DIR
INSTALL_RUNTIME_DIR
Expand Down Expand Up @@ -146,7 +126,7 @@ function(ADD_ICEBERG_LIB LIB_NAME)
"$<INSTALL_INTERFACE:${ARG_SHARED_INSTALL_INTERFACE_LIBS}>"
PRIVATE ${ARG_SHARED_PRIVATE_LINK_LIBS})

install(TARGETS ${LIB_NAME}_shared ${INSTALL_IS_OPTIONAL}
install(TARGETS ${LIB_NAME}_shared
EXPORT ${LIB_NAME}_targets
ARCHIVE DESTINATION ${INSTALL_ARCHIVE_DIR}
LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}
Expand Down Expand Up @@ -201,7 +181,7 @@ function(ADD_ICEBERG_LIB LIB_NAME)
PUBLIC "$<BUILD_INTERFACE:${ARG_STATIC_LINK_LIBS}>")
endif()

install(TARGETS ${LIB_NAME}_static ${INSTALL_IS_OPTIONAL}
install(TARGETS ${LIB_NAME}_static
EXPORT ${LIB_NAME}_targets
ARCHIVE DESTINATION ${INSTALL_ARCHIVE_DIR}
LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}
Expand All @@ -210,9 +190,12 @@ function(ADD_ICEBERG_LIB LIB_NAME)
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()

if(ARG_CMAKE_PACKAGE_NAME)
iceberg_install_cmake_package(${ARG_CMAKE_PACKAGE_NAME} ${LIB_NAME}_targets)
endif()
string(TOLOWER ${LIB_NAME} LIB_NAME_LOWER_CASE)
string(REPLACE "_" "-" LIB_NAME_DASH_SEPARATED_LOWER_CASE ${LIB_NAME_LOWER_CASE})
install(EXPORT ${LIB_NAME}_targets
DESTINATION "${ICEBERG_INSTALL_CMAKEDIR}/Iceberg"
NAMESPACE "Iceberg::"
FILE "${LIB_NAME_DASH_SEPARATED_LOWER_CASE}-targets.cmake")

# Modify variable in calling scope
if(ARG_OUTPUTS)
Expand Down
133 changes: 133 additions & 0 deletions cmake_modules/ThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# 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.

# Accumulate all dependencies to provide suitable static link parameters to the
# third party libraries.
set(ICEBERG_SYSTEM_DEPENDENCIES)
set(ICEBERG_VENDOR_DEPENDENCIES)
set(ICEBERG_ARROW_INSTALL_INTERFACE_LIBS)

# ----------------------------------------------------------------------
# Versions and URLs for toolchain builds

set(ICEBERG_ARROW_BUILD_VERSION "18.1.0")
set(ICEBERG_ARROW_BUILD_SHA256_CHECKSUM
"2dc8da5f8796afe213ecc5e5aba85bb82d91520eff3cf315784a52d0fa61d7fc")
set(ARROW_VENDORED TRUE)

if(DEFINED ENV{ICEBERG_ARROW_URL})
set(ARROW_SOURCE_URL "$ENV{ICEBERG_ARROW_URL}")
else()
set(ARROW_SOURCE_URL
"https://www.apache.org/dyn/closer.cgi?action=download&filename=/arrow/arrow-${ICEBERG_ARROW_BUILD_VERSION}/apache-arrow-${ICEBERG_ARROW_BUILD_VERSION}.tar.gz"
"https://downloads.apache.org/arrow/arrow-${ICEBERG_ARROW_BUILD_VERSION}/apache-arrow-${ICEBERG_ARROW_BUILD_VERSION}.tar.gz"
"https://github.com/apache/arrow/releases/download/apache-arrow-${ICEBERG_ARROW_BUILD_VERSION}/apache-arrow-${ICEBERG_ARROW_BUILD_VERSION}.tar.gz"
)
endif()

# ----------------------------------------------------------------------
# FetchContent

include(FetchContent)
set(FC_DECLARE_COMMON_OPTIONS)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
list(APPEND FC_DECLARE_COMMON_OPTIONS EXCLUDE_FROM_ALL TRUE)
endif()

macro(prepare_fetchcontent)
set(BUILD_SHARED_LIBS OFF)
set(BUILD_STATIC_LIBS ON)
set(CMAKE_COMPILE_WARNING_AS_ERROR FALSE)
set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY TRUE)
endmacro()

# ----------------------------------------------------------------------
# Apache Arrow

function(resolve_arrow_dependency)
set(ARROW_BUILD_SHARED
OFF
CACHE BOOL "" FORCE)
set(ARROW_BUILD_STATIC
ON
CACHE BOOL "" FORCE)
set(ARROW_FILESYSTEM
OFF
CACHE BOOL "" FORCE)
set(ARROW_SIMD_LEVEL
"NONE"
CACHE STRING "" FORCE)
set(ARROW_RUNTIME_SIMD_LEVEL
"NONE"
CACHE STRING "" FORCE)

fetchcontent_declare(Arrow
${FC_DECLARE_COMMON_OPTIONS}
URL ${ARROW_SOURCE_URL}
URL_HASH "SHA256=${ICEBERG_ARROW_BUILD_SHA256_CHECKSUM}"
SOURCE_SUBDIR
cpp
FIND_PACKAGE_ARGS
NAMES
Arrow
CONFIG)

# Add Arrow cmake modules to the search path
list(PREPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_BINARY_DIR}/_deps/arrow-src/cpp/cmake_modules)

fetchcontent_makeavailable(Arrow)

if(NOT TARGET Arrow::arrow_static)
add_library(Arrow::arrow_static INTERFACE IMPORTED)
target_link_libraries(Arrow::arrow_static INTERFACE arrow_static)
target_include_directories(Arrow::arrow_static INTERFACE ${arrow_SOURCE_DIR}/cpp/src
${arrow_BINARY_DIR}/src)
endif()

fetchcontent_getproperties(Arrow)
if(arrow_SOURCE_DIR)
set(ARROW_VENDORED TRUE)
install(TARGETS arrow_static
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")

get_target_property(ARROW_STATIC_LIB arrow_static OUTPUT_NAME)
set(ARROW_STATIC_LIB_NAME
"${CMAKE_STATIC_LIBRARY_PREFIX}${ARROW_STATIC_LIB}${CMAKE_STATIC_LIBRARY_SUFFIX}")
list(APPEND ICEBERG_VENDOR_DEPENDENCIES
"Iceberg::arrow_vendored|${ARROW_STATIC_LIB_NAME}")
else()
set(ARROW_VENDORED FALSE)
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES Arrow)
endif()

set(ICEBERG_VENDOR_DEPENDENCIES
${ICEBERG_VENDOR_DEPENDENCIES}
PARENT_SCOPE)
set(ICEBERG_SYSTEM_DEPENDENCIES
${ICEBERG_SYSTEM_DEPENDENCIES}
PARENT_SCOPE)
set(ARROW_VENDORED
${ARROW_VENDORED}
PARENT_SCOPE)
endfunction()

if(ICEBERG_ARROW)
resolve_arrow_dependency()
endif()
8 changes: 4 additions & 4 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ project(example)

set(CMAKE_CXX_STANDARD 20)

find_package(iceberg CONFIG REQUIRED)
find_package(puffin CONFIG REQUIRED)
find_package(Iceberg CONFIG REQUIRED)

add_executable(demo_example demo_example.cc)

target_link_libraries(demo_example PRIVATE iceberg::iceberg_core_static
puffin::iceberg_puffin_static)
target_link_libraries(demo_example
PRIVATE Iceberg::iceberg_core_static Iceberg::iceberg_puffin_static
Iceberg::iceberg_arrow_static)
2 changes: 2 additions & 0 deletions example/demo_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@

#include <iostream>

#include "iceberg/arrow/demo_arrow.h"
#include "iceberg/puffin.h"
#include "iceberg/table.h"

int main() {
std::cout << iceberg::Table::create()->print() << std::endl;
std::cout << iceberg::Puffin::create()->print() << std::endl;
std::cout << iceberg::arrow::DemoArrow().print() << std::endl;
return 0;
}
15 changes: 15 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,20 @@
# specific language governing permissions and limitations
# under the License.

add_subdirectory(arrow)
add_subdirectory(core)
add_subdirectory(puffin)

include(CMakePackageConfigHelpers)

configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/iceberg-config.cmake"
INSTALL_DESTINATION "${ICEBERG_INSTALL_CMAKEDIR}/Iceberg")

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/iceberg-config-version.cmake"
COMPATIBILITY SameMajorVersion)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/iceberg-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/iceberg-config-version.cmake"
DESTINATION "${ICEBERG_INSTALL_CMAKEDIR}/Iceberg")
65 changes: 65 additions & 0 deletions src/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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(NOT ICEBERG_ARROW)
return()
endif()

set(ICEBERG_ARROW_SOURCES demo_arrow.cc)
set(ICEBERG_ARROW_INCLUDES "${ICEBERG_API_DIR}")

# Libraries to link with exported libiceberg_arrow.{so,a}.
set(ICEBERG_ARROW_STATIC_BUILD_INTERFACE_LIBS)
set(ICEBERG_ARROW_SHARED_BUILD_INTERFACE_LIBS)
set(ICEBERG_ARROW_STATIC_INSTALL_INTERFACE_LIBS)
set(ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS)

list(APPEND ICEBERG_ARROW_STATIC_BUILD_INTERFACE_LIBS
"$<IF:$<TARGET_EXISTS:Arrow::arrow_static>,Arrow::arrow_static,Arrow::arrow_shared>")
list(APPEND ICEBERG_ARROW_SHARED_BUILD_INTERFACE_LIBS
"$<IF:$<TARGET_EXISTS:Arrow::arrow_shared>,Arrow::arrow_shared,Arrow::arrow_static>")

if(ARROW_VENDORED)
list(APPEND ICEBERG_ARROW_STATIC_INSTALL_INTERFACE_LIBS Iceberg::arrow_vendored)
list(APPEND ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS Iceberg::arrow_vendored)
else()
list(APPEND
ICEBERG_ARROW_STATIC_INSTALL_INTERFACE_LIBS
"$<IF:$<TARGET_EXISTS:Arrow::arrow_static>,Arrow::arrow_static,Arrow::arrow_shared>"
)
list(APPEND
ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS
"$<IF:$<TARGET_EXISTS:Arrow::arrow_shared>,Arrow::arrow_shared,Arrow::arrow_static>"
)
endif()

add_iceberg_lib(iceberg_arrow
SOURCES
${ICEBERG_ARROW_SOURCES}
PRIVATE_INCLUDES
${ICEBERG_ARROW_INCLUDES}
SHARED_LINK_LIBS
${ICEBERG_ARROW_SHARED_BUILD_INTERFACE_LIBS}
STATIC_LINK_LIBS
${ICEBERG_ARROW_STATIC_BUILD_INTERFACE_LIBS}
STATIC_INSTALL_INTERFACE_LIBS
${ICEBERG_ARROW_STATIC_INSTALL_INTERFACE_LIBS}
SHARED_INSTALL_INTERFACE_LIBS
${ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS})

install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/demo_arrow.h"
DESTINATION "${ICEBERG_INSTALL_INCLUDEDIR}/iceberg/arrow")
Loading

0 comments on commit 65021dc

Please sign in to comment.