From 65021dc2656d795406cad32506f6b79349abfdda Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Fri, 6 Dec 2024 23:32:09 +0800 Subject: [PATCH 01/34] Add iceberg_arrow library - add libiceberg_arrow - use single config file with three separate targets to support components - add fetchcontent support --- CMakeLists.txt | 18 ++-- README.md | 23 ++++ cmake_modules/BuildUtils.cmake | 33 ++---- cmake_modules/ThirdpartyToolchain.cmake | 133 ++++++++++++++++++++++++ example/CMakeLists.txt | 8 +- example/demo_example.cc | 2 + src/CMakeLists.txt | 15 +++ src/arrow/CMakeLists.txt | 65 ++++++++++++ src/arrow/demo_arrow.cc | 28 +++++ src/arrow/demo_arrow.h | 31 ++++++ src/config.cmake.in | 122 ++++++++++++++++++++++ src/core/CMakeLists.txt | 2 - src/core/icebergConfig.cmake.in | 22 ---- src/puffin/CMakeLists.txt | 2 - src/puffin/puffinConfig.cmake.in | 22 ---- 15 files changed, 443 insertions(+), 83 deletions(-) create mode 100644 cmake_modules/ThirdpartyToolchain.cmake create mode 100644 src/arrow/CMakeLists.txt create mode 100644 src/arrow/demo_arrow.cc create mode 100644 src/arrow/demo_arrow.h create mode 100644 src/config.cmake.in delete mode 100644 src/core/icebergConfig.cmake.in delete mode 100644 src/puffin/puffinConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 22e24d678..cb67091f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,17 +33,19 @@ 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}") @@ -51,6 +53,10 @@ 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) diff --git a/README.md b/README.md index 56cedaf73..41ab510bb 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index 4d6bf1db0..db45357c8 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -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 @@ -146,7 +126,7 @@ function(ADD_ICEBERG_LIB LIB_NAME) "$" 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} @@ -201,7 +181,7 @@ function(ADD_ICEBERG_LIB LIB_NAME) PUBLIC "$") 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} @@ -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) diff --git a/cmake_modules/ThirdpartyToolchain.cmake b/cmake_modules/ThirdpartyToolchain.cmake new file mode 100644 index 000000000..7d65ce4d7 --- /dev/null +++ b/cmake_modules/ThirdpartyToolchain.cmake @@ -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() diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 0d21c3af3..8e2ebb45e 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -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) diff --git a/example/demo_example.cc b/example/demo_example.cc index 99d4bcf47..da95e100c 100644 --- a/example/demo_example.cc +++ b/example/demo_example.cc @@ -19,11 +19,13 @@ #include +#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; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bec762228..cb5209bfa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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") diff --git a/src/arrow/CMakeLists.txt b/src/arrow/CMakeLists.txt new file mode 100644 index 000000000..0d545b68f --- /dev/null +++ b/src/arrow/CMakeLists.txt @@ -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 + "$,Arrow::arrow_static,Arrow::arrow_shared>") +list(APPEND ICEBERG_ARROW_SHARED_BUILD_INTERFACE_LIBS + "$,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 + "$,Arrow::arrow_static,Arrow::arrow_shared>" + ) + list(APPEND + ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS + "$,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") diff --git a/src/arrow/demo_arrow.cc b/src/arrow/demo_arrow.cc new file mode 100644 index 000000000..ae2105be3 --- /dev/null +++ b/src/arrow/demo_arrow.cc @@ -0,0 +1,28 @@ +/* + * 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. + */ + +#include "demo_arrow.h" + +#include + +namespace iceberg::arrow { + +std::string DemoArrow::print() const { return ::arrow::GetBuildInfo().version_string; } + +} // namespace iceberg::arrow diff --git a/src/arrow/demo_arrow.h b/src/arrow/demo_arrow.h new file mode 100644 index 000000000..69517f692 --- /dev/null +++ b/src/arrow/demo_arrow.h @@ -0,0 +1,31 @@ +/* + * 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. + */ + +#pragma once + +#include + +namespace iceberg::arrow { + +class DemoArrow { + public: + std::string print() const; +}; + +} // namespace iceberg::arrow diff --git a/src/config.cmake.in b/src/config.cmake.in new file mode 100644 index 000000000..49f97ca0d --- /dev/null +++ b/src/config.cmake.in @@ -0,0 +1,122 @@ +# 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. +# +# This config sets the following variables in your project:: +# +# Iceberg_FOUND - true if Iceberg found on the system +# Iceberg_VERSION - version of the found Iceberg +# +# This config sets the following targets (if built) in your project:: +# +# Iceberg::iceberg_core_shared +# Iceberg::iceberg_core_static +# Iceberg::iceberg_puffin_shared +# Iceberg::iceberg_puffin_static +# Iceberg::iceberg_arrow_shared +# Iceberg::iceberg_arrow_static + +@PACKAGE_INIT@ + +set(ICEBERG_BUILD_STATIC "@ICEBERG_BUILD_STATIC@") +set(ICEBERG_VENDOR_DEPENDENCIES "@ICEBERG_VENDOR_DEPENDENCIES@") +set(ICEBERG_SYSTEM_DEPENDENCIES "@ICEBERG_SYSTEM_DEPENDENCIES@") + +include(CMakeFindDependencyMacro) + +macro(iceberg_find_dependencies dependencies) + if(DEFINED CMAKE_MODULE_PATH) + set(ICEBERG_CMAKE_MODULE_PATH_OLD ${CMAKE_MODULE_PATH}) + else() + unset(ICEBERG_CMAKE_MODULE_PATH_OLD) + endif() + set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + + foreach(dependency ${dependencies}) + find_dependency(${dependency}) + endforeach() + + if(DEFINED ICEBERG_CMAKE_MODULE_PATH_OLD) + set(CMAKE_MODULE_PATH ${ICEBERG_CMAKE_MODULE_PATH_OLD}) + unset(ICEBERG_CMAKE_MODULE_PATH_OLD) + else() + unset(CMAKE_MODULE_PATH) + endif() +endmacro() + +macro(iceberg_find_components components) + file(GLOB_RECURSE target_cmake_files "${CMAKE_CURRENT_LIST_DIR}/*-targets.cmake") + foreach(target_cmake_file ${target_cmake_files}) + include(${target_cmake_file}) + endforeach() + + foreach(comp ${components}) + if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/iceberg-${comp}-targets.cmake") + set(Iceberg_${comp}_FOUND TRUE) + else() + set(Iceberg_${comp}_FOUND FALSE) + set(Iceberg_NOT_FOUND_MESSAGE "Component ${comp} was not installed") + endif() + endforeach() +endmacro() + +macro(iceberg_find_vendor_dependencies dependencies) + get_target_property(iceberg_static_configurations + Iceberg::iceberg_core_static IMPORTED_CONFIGURATIONS) + + foreach(dependency ${dependencies}) + string(REPLACE "|" ";" dependency_pair ${dependency}) + list(LENGTH dependency_pair dependency_pair_length) + if(NOT dependency_pair_length EQUAL 2) + message(FATAL_ERROR "Invalid vendor dependency: ${dependency}") + endif() + list(GET dependency_pair 0 target_name) + list(GET dependency_pair 1 static_lib_name) + + add_library("${target_name}" STATIC IMPORTED) + + foreach(configuration ${iceberg_static_configurations}) + string(TOUPPER "${configuration}" CONFIGURATION) + get_target_property( + iceberg_core_static_location + Iceberg::iceberg_core_static LOCATION_${CONFIGURATION}) + get_filename_component( + iceberg_core_lib_dir + "${iceberg_core_static_location}" DIRECTORY) + set_property( + TARGET "${target_name}" + APPEND + PROPERTY IMPORTED_CONFIGURATIONS ${CONFIGURATION}) + set_target_properties( + "${target_name}" + PROPERTIES IMPORTED_LOCATION_${CONFIGURATION} + "${iceberg_core_lib_dir}/${static_lib_name}") + endforeach() + endforeach() +endmacro() + +# Find components and include targets +iceberg_find_components("${Iceberg_FIND_COMPONENTS}") + +# Find system dependencies +iceberg_find_dependencies("${ICEBERG_SYSTEM_DEPENDENCIES}") + +# Find vendor dependencies +if(ICEBERG_BUILD_STATIC) + iceberg_find_vendor_dependencies("${ICEBERG_VENDOR_DEPENDENCIES}") +endif() + +check_required_components(Iceberg) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 83787d70c..673258167 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -19,8 +19,6 @@ set(ICEBERG_CORE_SOURCES demo_table.cc) set(ICEBERG_CORE_INCLUDES "${ICEBERG_API_DIR}") add_iceberg_lib(iceberg_core - CMAKE_PACKAGE_NAME - iceberg SOURCES ${ICEBERG_CORE_SOURCES} PRIVATE_INCLUDES diff --git a/src/core/icebergConfig.cmake.in b/src/core/icebergConfig.cmake.in deleted file mode 100644 index 2e12a8f0d..000000000 --- a/src/core/icebergConfig.cmake.in +++ /dev/null @@ -1,22 +0,0 @@ -# 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. -# - -@PACKAGE_INIT@ - -include("${CMAKE_CURRENT_LIST_DIR}/icebergTargets.cmake") -check_required_components(iceberg) diff --git a/src/puffin/CMakeLists.txt b/src/puffin/CMakeLists.txt index ff353e2e3..7c38e26ad 100644 --- a/src/puffin/CMakeLists.txt +++ b/src/puffin/CMakeLists.txt @@ -19,8 +19,6 @@ set(ICEBERG_PUFFIN_SOURCES demo_puffin.cc) set(ICEBERG_PUFFIN_INCLUDES "${ICEBERG_API_DIR}") add_iceberg_lib(iceberg_puffin - CMAKE_PACKAGE_NAME - puffin SOURCES ${ICEBERG_PUFFIN_SOURCES} PRIVATE_INCLUDES diff --git a/src/puffin/puffinConfig.cmake.in b/src/puffin/puffinConfig.cmake.in deleted file mode 100644 index c55b0182f..000000000 --- a/src/puffin/puffinConfig.cmake.in +++ /dev/null @@ -1,22 +0,0 @@ -# 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. -# - -@PACKAGE_INIT@ - -include("${CMAKE_CURRENT_LIST_DIR}/puffinTargets.cmake") -check_required_components(puffin) From f84b307acea4d6b7f2330fcc9e9de59ea8147d0e Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Thu, 26 Dec 2024 10:13:13 +0800 Subject: [PATCH 02/34] fix linux build --- README.md | 17 +++++++++++------ cmake_modules/ThirdpartyToolchain.cmake | 6 ++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 41ab510bb..0757a33d9 100644 --- a/README.md +++ b/README.md @@ -33,14 +33,15 @@ C++ implementation of [Apache Iceberg™](https://iceberg.apache.org/). ```bash cd iceberg-cpp mkdir build && cd build -cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/iceberg -DICEBERG_BUILD_STATIC=ON -DICEBERG_BUILD_SHARED=ON +cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/install -DICEBERG_BUILD_STATIC=ON -DICEBERG_BUILD_SHARED=ON cmake --build . cmake --install . ``` -### Build and Install Iceberg Arrow Libraries +### Build and Install Iceberg Arrow Library #### Vendored Apache Arrow (default) + ```bash cd iceberg-cpp/src/arrow mkdir build && cd build @@ -54,13 +55,11 @@ cmake --install . ```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 .. -DCMAKE_INSTALL_PREFIX=/path/to/install -DCMAKE_PREFIX_PATH=/path/to/arrow -DICEBERG_ARROW=ON 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: @@ -68,10 +67,16 @@ After installing the core libraries, you can build the examples: ```bash cd iceberg-cpp/example mkdir build && cd build -cmake .. -DCMAKE_PREFIX_PATH=/tmp/iceberg +cmake .. -DCMAKE_PREFIX_PATH=/path/to/install cmake --build . ``` +If you are using provided Apache Arrow, you need to include `/path/to/arrow` in `CMAKE_PREFIX_PATH` as below. + +```bash +cmake .. -DCMAKE_PREFIX_PATH="/path/to/install;/path/to/arrow" +``` + ## Contribute Apache Iceberg is an active open-source project, governed under the Apache Software Foundation (ASF). Iceberg-cpp is open to people who want to contribute to it. Here are some ways to get involved: diff --git a/cmake_modules/ThirdpartyToolchain.cmake b/cmake_modules/ThirdpartyToolchain.cmake index 7d65ce4d7..180a4e479 100644 --- a/cmake_modules/ThirdpartyToolchain.cmake +++ b/cmake_modules/ThirdpartyToolchain.cmake @@ -53,12 +53,15 @@ macro(prepare_fetchcontent) set(BUILD_STATIC_LIBS ON) set(CMAKE_COMPILE_WARNING_AS_ERROR FALSE) set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY TRUE) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) endmacro() # ---------------------------------------------------------------------- # Apache Arrow function(resolve_arrow_dependency) + prepare_fetchcontent() + set(ARROW_BUILD_SHARED OFF CACHE BOOL "" FORCE) @@ -74,6 +77,9 @@ function(resolve_arrow_dependency) set(ARROW_RUNTIME_SIMD_LEVEL "NONE" CACHE STRING "" FORCE) + set(ARROW_POSITION_INDEPENDENT_CODE + ON + CACHE BOOL "" FORCE) fetchcontent_declare(Arrow ${FC_DECLARE_COMMON_OPTIONS} From 2cfd71573b4e0866b341a184c1c8babd2cf813e3 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Thu, 26 Dec 2024 11:10:21 +0800 Subject: [PATCH 03/34] use internal cmake variables --- src/config.cmake.in | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/config.cmake.in b/src/config.cmake.in index 49f97ca0d..f7e3a8908 100644 --- a/src/config.cmake.in +++ b/src/config.cmake.in @@ -58,13 +58,14 @@ macro(iceberg_find_dependencies dependencies) endmacro() macro(iceberg_find_components components) - file(GLOB_RECURSE target_cmake_files "${CMAKE_CURRENT_LIST_DIR}/*-targets.cmake") - foreach(target_cmake_file ${target_cmake_files}) - include(${target_cmake_file}) + file(GLOB_RECURSE _target_cmake_files "${CMAKE_CURRENT_LIST_DIR}/*-targets.cmake") + foreach(_target_cmake_file ${_target_cmake_files}) + include(${_target_cmake_file}) endforeach() foreach(comp ${components}) - if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/iceberg-${comp}-targets.cmake") + string(TOLOWER "${comp}" _comp_lower_case) + if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/iceberg-${_comp_lower_case}-targets.cmake") set(Iceberg_${comp}_FOUND TRUE) else() set(Iceberg_${comp}_FOUND FALSE) @@ -74,36 +75,36 @@ macro(iceberg_find_components components) endmacro() macro(iceberg_find_vendor_dependencies dependencies) - get_target_property(iceberg_static_configurations + get_target_property(_iceberg_static_configurations Iceberg::iceberg_core_static IMPORTED_CONFIGURATIONS) foreach(dependency ${dependencies}) - string(REPLACE "|" ";" dependency_pair ${dependency}) - list(LENGTH dependency_pair dependency_pair_length) - if(NOT dependency_pair_length EQUAL 2) + string(REPLACE "|" ";" _dependency_pair ${dependency}) + list(LENGTH _dependency_pair _dependency_pair_length) + if(NOT _dependency_pair_length EQUAL 2) message(FATAL_ERROR "Invalid vendor dependency: ${dependency}") endif() - list(GET dependency_pair 0 target_name) - list(GET dependency_pair 1 static_lib_name) + list(GET _dependency_pair 0 _target_name) + list(GET _dependency_pair 1 _static_lib_name) - add_library("${target_name}" STATIC IMPORTED) + add_library("${_target_name}" STATIC IMPORTED) - foreach(configuration ${iceberg_static_configurations}) - string(TOUPPER "${configuration}" CONFIGURATION) + foreach(configuration ${_iceberg_static_configurations}) + string(TOUPPER "${configuration}" _configuration_upper_case) get_target_property( - iceberg_core_static_location - Iceberg::iceberg_core_static LOCATION_${CONFIGURATION}) + _iceberg_core_static_location + Iceberg::iceberg_core_static LOCATION_${_configuration_upper_case}) get_filename_component( iceberg_core_lib_dir - "${iceberg_core_static_location}" DIRECTORY) + "${_iceberg_core_static_location}" DIRECTORY) set_property( - TARGET "${target_name}" + TARGET "${_target_name}" APPEND - PROPERTY IMPORTED_CONFIGURATIONS ${CONFIGURATION}) + PROPERTY IMPORTED_CONFIGURATIONS ${_configuration_upper_case}) set_target_properties( - "${target_name}" - PROPERTIES IMPORTED_LOCATION_${CONFIGURATION} - "${iceberg_core_lib_dir}/${static_lib_name}") + "${_target_name}" + PROPERTIES IMPORTED_LOCATION_${_configuration_upper_case} + "${iceberg_core_lib_dir}/${_static_lib_name}") endforeach() endforeach() endmacro() From 10ef3e5aa89f237826273f4f512ce6db56cfdbe6 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Thu, 26 Dec 2024 22:20:32 +0800 Subject: [PATCH 04/34] fix windows build --- cmake_modules/ThirdpartyToolchain.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake_modules/ThirdpartyToolchain.cmake b/cmake_modules/ThirdpartyToolchain.cmake index 180a4e479..6a64a8877 100644 --- a/cmake_modules/ThirdpartyToolchain.cmake +++ b/cmake_modules/ThirdpartyToolchain.cmake @@ -80,6 +80,9 @@ function(resolve_arrow_dependency) set(ARROW_POSITION_INDEPENDENT_CODE ON CACHE BOOL "" FORCE) + set(ARROW_DEPENDENCY_SOURCE + "AUTO" + CACHE STRING "" FORCE) fetchcontent_declare(Arrow ${FC_DECLARE_COMMON_OPTIONS} From 200bd2fa2f1bdd7569c752499b6b7ce3ef4185af Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Fri, 27 Dec 2024 00:07:42 +0800 Subject: [PATCH 05/34] fix msvc build to not add _static suffix --- cmake_modules/BuildUtils.cmake | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index db45357c8..64fd48811 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -162,11 +162,11 @@ function(ADD_ICEBERG_LIB LIB_NAME) target_include_directories(${LIB_NAME}_static PRIVATE ${ARG_PRIVATE_INCLUDES}) endif() - if(MSVC_TOOLCHAIN) - set(LIB_NAME_STATIC ${LIB_NAME}_static) - else() - set(LIB_NAME_STATIC ${LIB_NAME}) - endif() + # if(MSVC_TOOLCHAIN) + # set(LIB_NAME_STATIC ${LIB_NAME}_static) + # else() + set(LIB_NAME_STATIC ${LIB_NAME}) + # endif() set_target_properties(${LIB_NAME}_static PROPERTIES OUTPUT_NAME ${LIB_NAME_STATIC}) From b750758ee4d7d36c3595142caf08a867ab81aa3d Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Fri, 27 Dec 2024 09:38:21 +0800 Subject: [PATCH 06/34] remove MSVC_TOOLCHAIN --- CMakeLists.txt | 7 ------- cmake_modules/BuildUtils.cmake | 8 +------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb67091f0..634de1358 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,13 +33,6 @@ 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) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index 64fd48811..a273a2e45 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -162,13 +162,7 @@ function(ADD_ICEBERG_LIB LIB_NAME) target_include_directories(${LIB_NAME}_static PRIVATE ${ARG_PRIVATE_INCLUDES}) endif() - # if(MSVC_TOOLCHAIN) - # set(LIB_NAME_STATIC ${LIB_NAME}_static) - # else() - set(LIB_NAME_STATIC ${LIB_NAME}) - # endif() - - set_target_properties(${LIB_NAME}_static PROPERTIES OUTPUT_NAME ${LIB_NAME_STATIC}) + set_target_properties(${LIB_NAME}_static PROPERTIES OUTPUT_NAME ${LIB_NAME}) if(ARG_STATIC_INSTALL_INTERFACE_LIBS) target_link_libraries(${LIB_NAME}_static From 4e766d994a92b96f785a344bc69a3896ec5ceceb Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Tue, 31 Dec 2024 14:39:18 +0800 Subject: [PATCH 07/34] simplify ThirdpartyToolchain.cmake --- README.md | 28 ++++++++++--------------- cmake_modules/ThirdpartyToolchain.cmake | 20 ++++++++---------- src/config.cmake.in | 3 ++- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 0757a33d9..251f454a1 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,9 @@ C++ implementation of [Apache Iceberg™](https://iceberg.apache.org/). ```bash cd iceberg-cpp -mkdir build && cd build -cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/install -DICEBERG_BUILD_STATIC=ON -DICEBERG_BUILD_SHARED=ON -cmake --build . -cmake --install . +cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install -DICEBERG_BUILD_STATIC=ON -DICEBERG_BUILD_SHARED=ON +cmake --build build +cmake --install build ``` ### Build and Install Iceberg Arrow Library @@ -43,21 +42,17 @@ cmake --install . #### 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 . +cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install -DICEBERG_ARROW=ON +cmake --build build +cmake --install build ``` #### Provided Apache Arrow ```bash -cd iceberg-cpp/src/arrow -mkdir build && cd build -cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/install -DCMAKE_PREFIX_PATH=/path/to/arrow -DICEBERG_ARROW=ON -cmake --build . -cmake --install . +cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install -DCMAKE_PREFIX_PATH=/path/to/arrow -DICEBERG_ARROW=ON +cmake --build build +cmake --install build ``` ### Build Examples @@ -66,9 +61,8 @@ After installing the core libraries, you can build the examples: ```bash cd iceberg-cpp/example -mkdir build && cd build -cmake .. -DCMAKE_PREFIX_PATH=/path/to/install -cmake --build . +cmake -S . -B build -DCMAKE_PREFIX_PATH=/path/to/install +cmake --build build ``` If you are using provided Apache Arrow, you need to include `/path/to/arrow` in `CMAKE_PREFIX_PATH` as below. diff --git a/cmake_modules/ThirdpartyToolchain.cmake b/cmake_modules/ThirdpartyToolchain.cmake index 6a64a8877..3f0aad15f 100644 --- a/cmake_modules/ThirdpartyToolchain.cmake +++ b/cmake_modules/ThirdpartyToolchain.cmake @@ -27,7 +27,6 @@ set(ICEBERG_ARROW_INSTALL_INTERFACE_LIBS) 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}") @@ -35,7 +34,6 @@ 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() @@ -101,18 +99,18 @@ function(resolve_arrow_dependency) 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) + 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_BINARY_DIR}/src + ${arrow_SOURCE_DIR}/cpp/src) + endif() + set(ARROW_VENDORED TRUE) install(TARGETS arrow_static - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}" ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}" LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}") diff --git a/src/config.cmake.in b/src/config.cmake.in index f7e3a8908..aec96d3b7 100644 --- a/src/config.cmake.in +++ b/src/config.cmake.in @@ -65,7 +65,8 @@ macro(iceberg_find_components components) foreach(comp ${components}) string(TOLOWER "${comp}" _comp_lower_case) - if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/iceberg-${_comp_lower_case}-targets.cmake") + if(TARGET "Iceberg::iceberg_${_comp_lower_case}_shared" OR + TARGET "Iceberg::iceberg_${_comp_lower_case}_static") set(Iceberg_${comp}_FOUND TRUE) else() set(Iceberg_${comp}_FOUND FALSE) From 2866d6e730ff137048ff8189b805506fb1313511 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Tue, 31 Dec 2024 14:55:11 +0800 Subject: [PATCH 08/34] use same target --- cmake_modules/BuildUtils.cmake | 11 ++--------- src/CMakeLists.txt | 5 +++++ src/config.cmake.in | 9 +++------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index a273a2e45..573ef74c1 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -127,7 +127,7 @@ function(ADD_ICEBERG_LIB LIB_NAME) PRIVATE ${ARG_SHARED_PRIVATE_LINK_LIBS}) install(TARGETS ${LIB_NAME}_shared - EXPORT ${LIB_NAME}_targets + EXPORT iceberg_targets ARCHIVE DESTINATION ${INSTALL_ARCHIVE_DIR} LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR} RUNTIME DESTINATION ${INSTALL_RUNTIME_DIR} @@ -176,7 +176,7 @@ function(ADD_ICEBERG_LIB LIB_NAME) endif() install(TARGETS ${LIB_NAME}_static - EXPORT ${LIB_NAME}_targets + EXPORT iceberg_targets ARCHIVE DESTINATION ${INSTALL_ARCHIVE_DIR} LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR} RUNTIME DESTINATION ${INSTALL_RUNTIME_DIR} @@ -184,13 +184,6 @@ function(ADD_ICEBERG_LIB LIB_NAME) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 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) set(${ARG_OUTPUTS} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cb5209bfa..233ab8b1c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,6 +29,11 @@ write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/iceberg-config-version.cmake" COMPATIBILITY SameMajorVersion) +install(EXPORT iceberg_targets + DESTINATION "${ICEBERG_INSTALL_CMAKEDIR}/Iceberg" + NAMESPACE "Iceberg::" + FILE "iceberg-targets.cmake") + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/iceberg-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/iceberg-config-version.cmake" DESTINATION "${ICEBERG_INSTALL_CMAKEDIR}/Iceberg") diff --git a/src/config.cmake.in b/src/config.cmake.in index aec96d3b7..220ce753b 100644 --- a/src/config.cmake.in +++ b/src/config.cmake.in @@ -58,11 +58,6 @@ macro(iceberg_find_dependencies dependencies) endmacro() macro(iceberg_find_components components) - file(GLOB_RECURSE _target_cmake_files "${CMAKE_CURRENT_LIST_DIR}/*-targets.cmake") - foreach(_target_cmake_file ${_target_cmake_files}) - include(${_target_cmake_file}) - endforeach() - foreach(comp ${components}) string(TOLOWER "${comp}" _comp_lower_case) if(TARGET "Iceberg::iceberg_${_comp_lower_case}_shared" OR @@ -110,7 +105,9 @@ macro(iceberg_find_vendor_dependencies dependencies) endforeach() endmacro() -# Find components and include targets +include("${CMAKE_CURRENT_LIST_DIR}/iceberg-targets.cmake") + +# Find required components iceberg_find_components("${Iceberg_FIND_COMPONENTS}") # Find system dependencies From 51839812660e2b42674310482bed37e76f2264b4 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Tue, 31 Dec 2024 15:37:43 +0800 Subject: [PATCH 09/34] simplify vendored lib --- cmake_modules/ThirdpartyToolchain.cmake | 12 ++------ src/arrow/CMakeLists.txt | 4 +-- src/config.cmake.in | 41 ------------------------- 3 files changed, 4 insertions(+), 53 deletions(-) diff --git a/cmake_modules/ThirdpartyToolchain.cmake b/cmake_modules/ThirdpartyToolchain.cmake index 3f0aad15f..2dcc7b334 100644 --- a/cmake_modules/ThirdpartyToolchain.cmake +++ b/cmake_modules/ThirdpartyToolchain.cmake @@ -18,7 +18,6 @@ # 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) # ---------------------------------------------------------------------- @@ -109,24 +108,17 @@ function(resolve_arrow_dependency) endif() set(ARROW_VENDORED TRUE) + set_target_properties(arrow_static PROPERTIES OUTPUT_NAME "iceberg_vendored_arrow") install(TARGETS arrow_static + EXPORT iceberg_targets RUNTIME DESTINATION "${ICEBERG_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) diff --git a/src/arrow/CMakeLists.txt b/src/arrow/CMakeLists.txt index 0d545b68f..107e86104 100644 --- a/src/arrow/CMakeLists.txt +++ b/src/arrow/CMakeLists.txt @@ -34,8 +34,8 @@ list(APPEND ICEBERG_ARROW_SHARED_BUILD_INTERFACE_LIBS "$,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) + list(APPEND ICEBERG_ARROW_STATIC_INSTALL_INTERFACE_LIBS Iceberg::arrow_static) + list(APPEND ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS Iceberg::arrow_static) else() list(APPEND ICEBERG_ARROW_STATIC_INSTALL_INTERFACE_LIBS diff --git a/src/config.cmake.in b/src/config.cmake.in index 220ce753b..8f888f344 100644 --- a/src/config.cmake.in +++ b/src/config.cmake.in @@ -32,7 +32,6 @@ @PACKAGE_INIT@ set(ICEBERG_BUILD_STATIC "@ICEBERG_BUILD_STATIC@") -set(ICEBERG_VENDOR_DEPENDENCIES "@ICEBERG_VENDOR_DEPENDENCIES@") set(ICEBERG_SYSTEM_DEPENDENCIES "@ICEBERG_SYSTEM_DEPENDENCIES@") include(CMakeFindDependencyMacro) @@ -70,41 +69,6 @@ macro(iceberg_find_components components) endforeach() endmacro() -macro(iceberg_find_vendor_dependencies dependencies) - get_target_property(_iceberg_static_configurations - Iceberg::iceberg_core_static IMPORTED_CONFIGURATIONS) - - foreach(dependency ${dependencies}) - string(REPLACE "|" ";" _dependency_pair ${dependency}) - list(LENGTH _dependency_pair _dependency_pair_length) - if(NOT _dependency_pair_length EQUAL 2) - message(FATAL_ERROR "Invalid vendor dependency: ${dependency}") - endif() - list(GET _dependency_pair 0 _target_name) - list(GET _dependency_pair 1 _static_lib_name) - - add_library("${_target_name}" STATIC IMPORTED) - - foreach(configuration ${_iceberg_static_configurations}) - string(TOUPPER "${configuration}" _configuration_upper_case) - get_target_property( - _iceberg_core_static_location - Iceberg::iceberg_core_static LOCATION_${_configuration_upper_case}) - get_filename_component( - iceberg_core_lib_dir - "${_iceberg_core_static_location}" DIRECTORY) - set_property( - TARGET "${_target_name}" - APPEND - PROPERTY IMPORTED_CONFIGURATIONS ${_configuration_upper_case}) - set_target_properties( - "${_target_name}" - PROPERTIES IMPORTED_LOCATION_${_configuration_upper_case} - "${iceberg_core_lib_dir}/${_static_lib_name}") - endforeach() - endforeach() -endmacro() - include("${CMAKE_CURRENT_LIST_DIR}/iceberg-targets.cmake") # Find required components @@ -113,9 +77,4 @@ iceberg_find_components("${Iceberg_FIND_COMPONENTS}") # Find system dependencies iceberg_find_dependencies("${ICEBERG_SYSTEM_DEPENDENCIES}") -# Find vendor dependencies -if(ICEBERG_BUILD_STATIC) - iceberg_find_vendor_dependencies("${ICEBERG_VENDOR_DEPENDENCIES}") -endif() - check_required_components(Iceberg) From 312b13da923c9ced8fff5253ea809ef84540227b Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Tue, 31 Dec 2024 15:56:05 +0800 Subject: [PATCH 10/34] use PackageNameConfig --- CMakeLists.txt | 2 +- cmake_modules/BuildUtils.cmake | 21 +++++++++++++++++++ src/CMakeLists.txt | 19 +---------------- ...config.cmake.in => IcebergConfig.cmake.in} | 2 +- 4 files changed, 24 insertions(+), 20 deletions(-) rename src/{config.cmake.in => IcebergConfig.cmake.in} (97%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 634de1358..344c1218e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules") -project(iceberg +project(Iceberg VERSION 0.1.0 DESCRIPTION "Iceberg C++ Project" LANGUAGES CXX) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index 573ef74c1..b8e60b844 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -18,6 +18,27 @@ # Borrowed the file from Apache Arrow: # https://github.com/apache/arrow/blob/main/cpp/cmake_modules/BuildUtils.cmake +include(CMakePackageConfigHelpers) + +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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 233ab8b1c..9822da3ff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,21 +19,4 @@ 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(EXPORT iceberg_targets - DESTINATION "${ICEBERG_INSTALL_CMAKEDIR}/Iceberg" - NAMESPACE "Iceberg::" - FILE "iceberg-targets.cmake") - -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/iceberg-config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/iceberg-config-version.cmake" - DESTINATION "${ICEBERG_INSTALL_CMAKEDIR}/Iceberg") +iceberg_install_cmake_package(Iceberg iceberg_targets) diff --git a/src/config.cmake.in b/src/IcebergConfig.cmake.in similarity index 97% rename from src/config.cmake.in rename to src/IcebergConfig.cmake.in index 8f888f344..e995b4cf4 100644 --- a/src/config.cmake.in +++ b/src/IcebergConfig.cmake.in @@ -69,7 +69,7 @@ macro(iceberg_find_components components) endforeach() endmacro() -include("${CMAKE_CURRENT_LIST_DIR}/iceberg-targets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/IcebergTargets.cmake") # Find required components iceberg_find_components("${Iceberg_FIND_COMPONENTS}") From 3c5bdfbd52405e4152961204987bb73f50a78fc4 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Tue, 31 Dec 2024 23:26:32 +0800 Subject: [PATCH 11/34] Update README.md Co-authored-by: Sutou Kouhei --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 251f454a1..7009aee1d 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ cmake --build build If you are using provided Apache Arrow, you need to include `/path/to/arrow` in `CMAKE_PREFIX_PATH` as below. ```bash -cmake .. -DCMAKE_PREFIX_PATH="/path/to/install;/path/to/arrow" +cmake -S . -B build -DCMAKE_PREFIX_PATH="/path/to/install;/path/to/arrow" ``` ## Contribute From a6abfd4574a1e871ea9a1d4b0410f70b78d54826 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Tue, 31 Dec 2024 23:26:45 +0800 Subject: [PATCH 12/34] Update cmake_modules/ThirdpartyToolchain.cmake Co-authored-by: Sutou Kouhei --- cmake_modules/ThirdpartyToolchain.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake_modules/ThirdpartyToolchain.cmake b/cmake_modules/ThirdpartyToolchain.cmake index 2dcc7b334..efd587af4 100644 --- a/cmake_modules/ThirdpartyToolchain.cmake +++ b/cmake_modules/ThirdpartyToolchain.cmake @@ -31,7 +31,7 @@ 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://www.apache.org/dyn/closer.lua?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" ) endif() From 8c09208b9a07067890e6002cfb25726e211b026c Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Tue, 31 Dec 2024 23:30:16 +0800 Subject: [PATCH 13/34] Update src/arrow/CMakeLists.txt Co-authored-by: Sutou Kouhei --- src/arrow/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/arrow/CMakeLists.txt b/src/arrow/CMakeLists.txt index 107e86104..490332ab7 100644 --- a/src/arrow/CMakeLists.txt +++ b/src/arrow/CMakeLists.txt @@ -46,6 +46,14 @@ else() "$,Arrow::arrow_shared,Arrow::arrow_static>" ) endif() +list(APPEND + ICEBERG_ARROW_STATIC_INSTALL_INTERFACE_LIBS + "$,Iceberg::iceberg_core_static,Iceberg::iceberg_core_shared>" +) +list(APPEND + ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS + "$,Iceberg::iceberg_core_shared,Iceberg::iceberg_core_static>" +) add_iceberg_lib(iceberg_arrow SOURCES From 80e0a4b3b378a49858cdd128d0cee54cf999fdbe Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 1 Jan 2025 13:51:20 +0800 Subject: [PATCH 14/34] let libiceberg_arrow depend on libiceberg_core --- CMakeLists.txt | 2 +- example/CMakeLists.txt | 5 ++--- src/CMakeLists.txt | 2 +- src/IcebergConfig.cmake.in | 6 +++--- src/arrow/CMakeLists.txt | 5 +++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 344c1218e..033dfdf78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) endif() -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules") +list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules") project(Iceberg VERSION 0.1.0 diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 8e2ebb45e..4da20ca3d 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -26,6 +26,5 @@ find_package(Iceberg CONFIG REQUIRED) add_executable(demo_example demo_example.cc) -target_link_libraries(demo_example - PRIVATE Iceberg::iceberg_core_static Iceberg::iceberg_puffin_static - Iceberg::iceberg_arrow_static) +target_link_libraries(demo_example PRIVATE Iceberg::iceberg_puffin_static + Iceberg::iceberg_arrow_static) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9822da3ff..2f4599f15 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,8 +15,8 @@ # specific language governing permissions and limitations # under the License. -add_subdirectory(arrow) add_subdirectory(core) add_subdirectory(puffin) +add_subdirectory(arrow) iceberg_install_cmake_package(Iceberg iceberg_targets) diff --git a/src/IcebergConfig.cmake.in b/src/IcebergConfig.cmake.in index e995b4cf4..6a42e31c4 100644 --- a/src/IcebergConfig.cmake.in +++ b/src/IcebergConfig.cmake.in @@ -69,12 +69,12 @@ macro(iceberg_find_components components) endforeach() endmacro() +# Find system dependencies +iceberg_find_dependencies("${ICEBERG_SYSTEM_DEPENDENCIES}") + include("${CMAKE_CURRENT_LIST_DIR}/IcebergTargets.cmake") # Find required components iceberg_find_components("${Iceberg_FIND_COMPONENTS}") -# Find system dependencies -iceberg_find_dependencies("${ICEBERG_SYSTEM_DEPENDENCIES}") - check_required_components(Iceberg) diff --git a/src/arrow/CMakeLists.txt b/src/arrow/CMakeLists.txt index 490332ab7..87bc0ff14 100644 --- a/src/arrow/CMakeLists.txt +++ b/src/arrow/CMakeLists.txt @@ -46,13 +46,14 @@ else() "$,Arrow::arrow_shared,Arrow::arrow_static>" ) endif() + list(APPEND ICEBERG_ARROW_STATIC_INSTALL_INTERFACE_LIBS - "$,Iceberg::iceberg_core_static,Iceberg::iceberg_core_shared>" + "$,Iceberg::iceberg_core_static,Iceberg::iceberg_core_shared>" ) list(APPEND ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS - "$,Iceberg::iceberg_core_shared,Iceberg::iceberg_core_static>" + "$,Iceberg::iceberg_core_shared,Iceberg::iceberg_core_static>" ) add_iceberg_lib(iceberg_arrow From 5a064c980f218b861e0330241437c0bcca89d8dd Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 1 Jan 2025 14:00:23 +0800 Subject: [PATCH 15/34] add back MSVC_TOOLCHAIN --- CMakeLists.txt | 6 ++++++ cmake_modules/BuildUtils.cmake | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 033dfdf78..a02745322 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,12 @@ set(ICEBERG_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}") set(ICEBERG_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake") set(ICEBERG_INSTALL_DOCDIR "share/doc/${PROJECT_NAME}") +if(WIN32 AND NOT MINGW) + set(MSVC_TOOLCHAIN TRUE) +else() + set(MSVC_TOOLCHAIN FALSE) +endif() + include(CMakeParseArguments) include(BuildUtils) include(ThirdpartyToolchain) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index b8e60b844..5390a366c 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -183,7 +183,13 @@ function(ADD_ICEBERG_LIB LIB_NAME) target_include_directories(${LIB_NAME}_static PRIVATE ${ARG_PRIVATE_INCLUDES}) endif() - set_target_properties(${LIB_NAME}_static PROPERTIES OUTPUT_NAME ${LIB_NAME}) + if(MSVC_TOOLCHAIN) + set(LIB_NAME_STATIC ${LIB_NAME}_static) + else() + set(LIB_NAME_STATIC ${LIB_NAME}) + endif() + + set_target_properties(${LIB_NAME}_static PROPERTIES OUTPUT_NAME ${LIB_NAME_STATIC}) if(ARG_STATIC_INSTALL_INTERFACE_LIBS) target_link_libraries(${LIB_NAME}_static From 93c4228d20b9cc4b9b32c67f4189a7d9e8e36e93 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 1 Jan 2025 16:28:46 +0800 Subject: [PATCH 16/34] try to fix windows build --- src/arrow/CMakeLists.txt | 10 ++++++++++ src/arrow/demo_arrow.h | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/arrow/CMakeLists.txt b/src/arrow/CMakeLists.txt index 87bc0ff14..fe0070e5b 100644 --- a/src/arrow/CMakeLists.txt +++ b/src/arrow/CMakeLists.txt @@ -59,6 +59,8 @@ list(APPEND add_iceberg_lib(iceberg_arrow SOURCES ${ICEBERG_ARROW_SOURCES} + OUTPUTS + ICEBERG_ARROW_LIBRARIES PRIVATE_INCLUDES ${ICEBERG_ARROW_INCLUDES} SHARED_LINK_LIBS @@ -70,5 +72,13 @@ add_iceberg_lib(iceberg_arrow SHARED_INSTALL_INTERFACE_LIBS ${ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS}) +if(ICEBERG_BUILD_STATIC AND WIN32) + target_compile_definitions(iceberg_arrow_static PUBLIC ICEBERG_ARROW_STATIC) +endif() + +foreach(LIB_TARGET ${ICEBERG_ARROW_LIBRARIES}) + target_compile_definitions(${LIB_TARGET} PRIVATE ICEBERG_ARROW_EXPORTING) +endforeach() + install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/demo_arrow.h" DESTINATION "${ICEBERG_INSTALL_INCLUDEDIR}/iceberg/arrow") diff --git a/src/arrow/demo_arrow.h b/src/arrow/demo_arrow.h index 69517f692..8fe014a11 100644 --- a/src/arrow/demo_arrow.h +++ b/src/arrow/demo_arrow.h @@ -21,9 +21,23 @@ #include +#ifdef _WIN32 +# ifdef ICEBERG_ARROW_STATIC +# define ICEBERG_ARROW_EXPORT +# else +# ifdef ICEBERG_ARROW_EXPORTING +# define ICEBERG_ARROW_EXPORT __declspec(dllexport) +# else +# define ICEBERG_ARROW_EXPORT __declspec(dllimport) +# endif +# endif +#else +# define ICEBERG_ARROW_EXPORT +#endif + namespace iceberg::arrow { -class DemoArrow { +class ICEBERG_ARROW_EXPORT DemoArrow { public: std::string print() const; }; From fdc0294983e22f249fe76b72d087a734cd87aff4 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 1 Jan 2025 17:03:10 +0800 Subject: [PATCH 17/34] add visibility.h --- api/iceberg/puffin.h | 4 +++- api/iceberg/table.h | 4 +++- api/iceberg/visibility.h | 34 ++++++++++++++++++++++++++++++++++ src/arrow/CMakeLists.txt | 4 ++-- src/arrow/demo_arrow.h | 16 ++-------------- src/core/CMakeLists.txt | 10 ++++++++++ src/core/demo_table.h | 2 +- src/puffin/CMakeLists.txt | 10 ++++++++++ src/puffin/demo_puffin.h | 2 +- 9 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 api/iceberg/visibility.h diff --git a/api/iceberg/puffin.h b/api/iceberg/puffin.h index b3dc8f7d4..2d681e1d3 100644 --- a/api/iceberg/puffin.h +++ b/api/iceberg/puffin.h @@ -22,9 +22,11 @@ #include #include +#include "iceberg/visibility.h" + namespace iceberg { -class Puffin { +class ICEBERG_EXPORT Puffin { public: virtual ~Puffin() = default; virtual std::string_view print() const = 0; diff --git a/api/iceberg/table.h b/api/iceberg/table.h index f06e336b5..9b4af7374 100644 --- a/api/iceberg/table.h +++ b/api/iceberg/table.h @@ -22,9 +22,11 @@ #include #include +#include "iceberg/visibility.h" + namespace iceberg { -class Table { +class ICEBERG_EXPORT Table { public: virtual ~Table() = default; virtual std::string_view print() const = 0; diff --git a/api/iceberg/visibility.h b/api/iceberg/visibility.h new file mode 100644 index 000000000..1bf387ddf --- /dev/null +++ b/api/iceberg/visibility.h @@ -0,0 +1,34 @@ +/* + * 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. + */ + +#pragma once + +#if defined(_WIN32) || defined(__CYGWIN__) +# ifdef ICEBERG_STATIC +# define ICEBERG_EXPORT +# else +# ifdef ICEBERG_EXPORTING +# define ICEBERG_EXPORT __declspec(dllexport) +# else +# define ICEBERG_EXPORT __declspec(dllimport) +# endif +# endif +#else +# define ICEBERG_EXPORT +#endif diff --git a/src/arrow/CMakeLists.txt b/src/arrow/CMakeLists.txt index fe0070e5b..31c3217ce 100644 --- a/src/arrow/CMakeLists.txt +++ b/src/arrow/CMakeLists.txt @@ -73,11 +73,11 @@ add_iceberg_lib(iceberg_arrow ${ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS}) if(ICEBERG_BUILD_STATIC AND WIN32) - target_compile_definitions(iceberg_arrow_static PUBLIC ICEBERG_ARROW_STATIC) + target_compile_definitions(iceberg_arrow_static PUBLIC ICEBERG_STATIC) endif() foreach(LIB_TARGET ${ICEBERG_ARROW_LIBRARIES}) - target_compile_definitions(${LIB_TARGET} PRIVATE ICEBERG_ARROW_EXPORTING) + target_compile_definitions(${LIB_TARGET} PRIVATE ICEBERG_EXPORTING) endforeach() install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/demo_arrow.h" diff --git a/src/arrow/demo_arrow.h b/src/arrow/demo_arrow.h index 8fe014a11..9e368f67d 100644 --- a/src/arrow/demo_arrow.h +++ b/src/arrow/demo_arrow.h @@ -21,23 +21,11 @@ #include -#ifdef _WIN32 -# ifdef ICEBERG_ARROW_STATIC -# define ICEBERG_ARROW_EXPORT -# else -# ifdef ICEBERG_ARROW_EXPORTING -# define ICEBERG_ARROW_EXPORT __declspec(dllexport) -# else -# define ICEBERG_ARROW_EXPORT __declspec(dllimport) -# endif -# endif -#else -# define ICEBERG_ARROW_EXPORT -#endif +#include "iceberg/visibility.h" namespace iceberg::arrow { -class ICEBERG_ARROW_EXPORT DemoArrow { +class ICEBERG_EXPORT DemoArrow { public: std::string print() const; }; diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 673258167..cde8bc165 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -21,5 +21,15 @@ set(ICEBERG_CORE_INCLUDES "${ICEBERG_API_DIR}") add_iceberg_lib(iceberg_core SOURCES ${ICEBERG_CORE_SOURCES} + OUTPUTS + ICEBERG_CORE_LIBRARIES PRIVATE_INCLUDES ${ICEBERG_CORE_INCLUDES}) + +if(ICEBERG_BUILD_STATIC AND WIN32) + target_compile_definitions(iceberg_core_static PUBLIC ICEBERG_STATIC) +endif() + +foreach(LIB_TARGET ${ICEBERG_CORE_LIBRARIES}) + target_compile_definitions(${LIB_TARGET} PRIVATE ICEBERG_EXPORTING) +endforeach() diff --git a/src/core/demo_table.h b/src/core/demo_table.h index 3a8604cf8..075bbadd1 100644 --- a/src/core/demo_table.h +++ b/src/core/demo_table.h @@ -23,7 +23,7 @@ namespace iceberg { -class DemoTable : public Table { +class ICEBERG_EXPORT DemoTable : public Table { public: DemoTable() = default; ~DemoTable() override = default; diff --git a/src/puffin/CMakeLists.txt b/src/puffin/CMakeLists.txt index 7c38e26ad..6de7fbc89 100644 --- a/src/puffin/CMakeLists.txt +++ b/src/puffin/CMakeLists.txt @@ -21,5 +21,15 @@ set(ICEBERG_PUFFIN_INCLUDES "${ICEBERG_API_DIR}") add_iceberg_lib(iceberg_puffin SOURCES ${ICEBERG_PUFFIN_SOURCES} + OUTPUTS + ICEBERG_PUFFIN_LIBRARIES PRIVATE_INCLUDES ${ICEBERG_PUFFIN_INCLUDES}) + +if(ICEBERG_BUILD_STATIC AND WIN32) + target_compile_definitions(iceberg_puffin_static PUBLIC ICEBERG_STATIC) +endif() + +foreach(LIB_TARGET ${ICEBERG_PUFFIN_LIBRARIES}) + target_compile_definitions(${LIB_TARGET} PRIVATE ICEBERG_EXPORTING) +endforeach() diff --git a/src/puffin/demo_puffin.h b/src/puffin/demo_puffin.h index a03649b60..8d93cf0f5 100644 --- a/src/puffin/demo_puffin.h +++ b/src/puffin/demo_puffin.h @@ -23,7 +23,7 @@ namespace iceberg { -class DemoPuffin : public Puffin { +class ICEBERG_EXPORT DemoPuffin : public Puffin { public: DemoPuffin() = default; ~DemoPuffin() override = default; From 3f6df87d726e0c3bc2bd83f8ee551fac4cfda748 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 1 Jan 2025 17:20:15 +0800 Subject: [PATCH 18/34] move iceberg_core location --- cmake_modules/BuildUtils.cmake | 12 +++++++++++- src/CMakeLists.txt | 16 ++++++++++++++-- src/arrow/CMakeLists.txt | 8 +------- src/core/CMakeLists.txt | 35 ---------------------------------- src/puffin/CMakeLists.txt | 8 +------- 5 files changed, 27 insertions(+), 52 deletions(-) delete mode 100644 src/core/CMakeLists.txt diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index 5390a366c..d429a2843 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -39,7 +39,7 @@ function(iceberg_install_cmake_package PACKAGE_NAME EXPORT_NAME) FILE "${TARGETS_CMAKE}") endfunction() -function(ADD_ICEBERG_LIB LIB_NAME) +function(add_iceberg_lib LIB_NAME) set(options) set(one_value_args BUILD_SHARED @@ -218,3 +218,13 @@ function(ADD_ICEBERG_LIB LIB_NAME) PARENT_SCOPE) endif() endfunction() + +function(iceberg_set_export_definitions STATIC_TARGET LIB_TARGETS) + if(ICEBERG_BUILD_STATIC AND WIN32) + target_compile_definitions(${STATIC_TARGET} PUBLIC ICEBERG_STATIC) + endif() + + foreach(LIB_TARGET ${LIB_TARGETS}) + target_compile_definitions(${LIB_TARGET} PRIVATE ICEBERG_EXPORTING) + endforeach() +endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2f4599f15..2d03d23d2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,8 +15,20 @@ # specific language governing permissions and limitations # under the License. -add_subdirectory(core) -add_subdirectory(puffin) +set(ICEBERG_CORE_SOURCES core/demo_table.cc) +set(ICEBERG_CORE_INCLUDES "${ICEBERG_API_DIR}") + +add_iceberg_lib(iceberg_core + SOURCES + ${ICEBERG_CORE_SOURCES} + OUTPUTS + ICEBERG_CORE_LIBRARIES + PRIVATE_INCLUDES + ${ICEBERG_CORE_INCLUDES}) + +iceberg_set_export_definitions(iceberg_core_static "${ICEBERG_CORE_LIBRARIES}") + add_subdirectory(arrow) +add_subdirectory(puffin) iceberg_install_cmake_package(Iceberg iceberg_targets) diff --git a/src/arrow/CMakeLists.txt b/src/arrow/CMakeLists.txt index 31c3217ce..a33983c02 100644 --- a/src/arrow/CMakeLists.txt +++ b/src/arrow/CMakeLists.txt @@ -72,13 +72,7 @@ add_iceberg_lib(iceberg_arrow SHARED_INSTALL_INTERFACE_LIBS ${ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS}) -if(ICEBERG_BUILD_STATIC AND WIN32) - target_compile_definitions(iceberg_arrow_static PUBLIC ICEBERG_STATIC) -endif() - -foreach(LIB_TARGET ${ICEBERG_ARROW_LIBRARIES}) - target_compile_definitions(${LIB_TARGET} PRIVATE ICEBERG_EXPORTING) -endforeach() +iceberg_set_export_definitions(iceberg_arrow_static "${ICEBERG_ARROW_LIBRARIES}") install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/demo_arrow.h" DESTINATION "${ICEBERG_INSTALL_INCLUDEDIR}/iceberg/arrow") diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt deleted file mode 100644 index cde8bc165..000000000 --- a/src/core/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# 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. - -set(ICEBERG_CORE_SOURCES demo_table.cc) -set(ICEBERG_CORE_INCLUDES "${ICEBERG_API_DIR}") - -add_iceberg_lib(iceberg_core - SOURCES - ${ICEBERG_CORE_SOURCES} - OUTPUTS - ICEBERG_CORE_LIBRARIES - PRIVATE_INCLUDES - ${ICEBERG_CORE_INCLUDES}) - -if(ICEBERG_BUILD_STATIC AND WIN32) - target_compile_definitions(iceberg_core_static PUBLIC ICEBERG_STATIC) -endif() - -foreach(LIB_TARGET ${ICEBERG_CORE_LIBRARIES}) - target_compile_definitions(${LIB_TARGET} PRIVATE ICEBERG_EXPORTING) -endforeach() diff --git a/src/puffin/CMakeLists.txt b/src/puffin/CMakeLists.txt index 6de7fbc89..a0f541e53 100644 --- a/src/puffin/CMakeLists.txt +++ b/src/puffin/CMakeLists.txt @@ -26,10 +26,4 @@ add_iceberg_lib(iceberg_puffin PRIVATE_INCLUDES ${ICEBERG_PUFFIN_INCLUDES}) -if(ICEBERG_BUILD_STATIC AND WIN32) - target_compile_definitions(iceberg_puffin_static PUBLIC ICEBERG_STATIC) -endif() - -foreach(LIB_TARGET ${ICEBERG_PUFFIN_LIBRARIES}) - target_compile_definitions(${LIB_TARGET} PRIVATE ICEBERG_EXPORTING) -endforeach() +iceberg_set_export_definitions(iceberg_puffin_static "${ICEBERG_PUFFIN_LIBRARIES}") From cbd661dcf7c8e839d8730d98b6938beb545dffdc Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 1 Jan 2025 17:26:53 +0800 Subject: [PATCH 19/34] link core to puffin & arrow --- src/arrow/CMakeLists.txt | 2 ++ src/puffin/CMakeLists.txt | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/arrow/CMakeLists.txt b/src/arrow/CMakeLists.txt index a33983c02..60e10c339 100644 --- a/src/arrow/CMakeLists.txt +++ b/src/arrow/CMakeLists.txt @@ -29,8 +29,10 @@ set(ICEBERG_ARROW_STATIC_INSTALL_INTERFACE_LIBS) set(ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS) list(APPEND ICEBERG_ARROW_STATIC_BUILD_INTERFACE_LIBS + "$,iceberg_core_static,iceberg_core_shared>" "$,Arrow::arrow_static,Arrow::arrow_shared>") list(APPEND ICEBERG_ARROW_SHARED_BUILD_INTERFACE_LIBS + "$,iceberg_core_shared,iceberg_core_static>" "$,Arrow::arrow_shared,Arrow::arrow_static>") if(ARROW_VENDORED) diff --git a/src/puffin/CMakeLists.txt b/src/puffin/CMakeLists.txt index a0f541e53..95574ce13 100644 --- a/src/puffin/CMakeLists.txt +++ b/src/puffin/CMakeLists.txt @@ -18,12 +18,38 @@ set(ICEBERG_PUFFIN_SOURCES demo_puffin.cc) set(ICEBERG_PUFFIN_INCLUDES "${ICEBERG_API_DIR}") +set(ICEBERG_PUFFIN_STATIC_BUILD_INTERFACE_LIBS) +set(ICEBERG_PUFFIN_SHARED_BUILD_INTERFACE_LIBS) +set(ICEBERG_PUFFIN_STATIC_INSTALL_INTERFACE_LIBS) +set(ICEBERG_PUFFIN_SHARED_INSTALL_INTERFACE_LIBS) + +list(APPEND ICEBERG_PUFFIN_STATIC_BUILD_INTERFACE_LIBS + "$,iceberg_core_static,iceberg_core_shared>") +list(APPEND ICEBERG_PUFFIN_SHARED_BUILD_INTERFACE_LIBS + "$,iceberg_core_shared,iceberg_core_static>") +list(APPEND + ICEBERG_PUFFIN_STATIC_INSTALL_INTERFACE_LIBS + "$,Iceberg::iceberg_core_static,Iceberg::iceberg_core_shared>" +) +list(APPEND + ICEBERG_PUFFIN_SHARED_INSTALL_INTERFACE_LIBS + "$,Iceberg::iceberg_core_shared,Iceberg::iceberg_core_static>" +) + add_iceberg_lib(iceberg_puffin SOURCES ${ICEBERG_PUFFIN_SOURCES} OUTPUTS ICEBERG_PUFFIN_LIBRARIES PRIVATE_INCLUDES - ${ICEBERG_PUFFIN_INCLUDES}) + ${ICEBERG_PUFFIN_INCLUDES} + SHARED_LINK_LIBS + ${ICEBERG_PUFFIN_SHARED_BUILD_INTERFACE_LIBS} + STATIC_LINK_LIBS + ${ICEBERG_PUFFIN_STATIC_BUILD_INTERFACE_LIBS} + STATIC_INSTALL_INTERFACE_LIBS + ${ICEBERG_PUFFIN_STATIC_INSTALL_INTERFACE_LIBS} + SHARED_INSTALL_INTERFACE_LIBS + ${ICEBERG_PUFFIN_SHARED_INSTALL_INTERFACE_LIBS}) iceberg_set_export_definitions(iceberg_puffin_static "${ICEBERG_PUFFIN_LIBRARIES}") From 38a9259fb7c7b6166feabdaaeedf00e879950615 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 1 Jan 2025 20:47:22 +0800 Subject: [PATCH 20/34] let iceberg_arrow to call api from iceberg_core --- example/demo_example.cc | 1 + src/arrow/CMakeLists.txt | 2 +- src/arrow/demo_arrow.cc | 4 ++++ src/arrow/demo_arrow.h | 1 + src/core/demo_table.cc | 4 +++- src/core/demo_table.h | 1 + 6 files changed, 11 insertions(+), 2 deletions(-) diff --git a/example/demo_example.cc b/example/demo_example.cc index da95e100c..9f42832c2 100644 --- a/example/demo_example.cc +++ b/example/demo_example.cc @@ -27,5 +27,6 @@ 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; + std::cout << iceberg::arrow::DemoArrow().name() << std::endl; return 0; } diff --git a/src/arrow/CMakeLists.txt b/src/arrow/CMakeLists.txt index 60e10c339..d31e5f86e 100644 --- a/src/arrow/CMakeLists.txt +++ b/src/arrow/CMakeLists.txt @@ -20,7 +20,7 @@ if(NOT ICEBERG_ARROW) endif() set(ICEBERG_ARROW_SOURCES demo_arrow.cc) -set(ICEBERG_ARROW_INCLUDES "${ICEBERG_API_DIR}") +set(ICEBERG_ARROW_INCLUDES "${ICEBERG_API_DIR}" "${CMAKE_SOURCE_DIR}/src") # Libraries to link with exported libiceberg_arrow.{so,a}. set(ICEBERG_ARROW_STATIC_BUILD_INTERFACE_LIBS) diff --git a/src/arrow/demo_arrow.cc b/src/arrow/demo_arrow.cc index ae2105be3..2f9c389e3 100644 --- a/src/arrow/demo_arrow.cc +++ b/src/arrow/demo_arrow.cc @@ -21,8 +21,12 @@ #include +#include "core/demo_table.h" + namespace iceberg::arrow { std::string DemoArrow::print() const { return ::arrow::GetBuildInfo().version_string; } +std::string_view DemoArrow::name() const { return DemoTable().name(); } + } // namespace iceberg::arrow diff --git a/src/arrow/demo_arrow.h b/src/arrow/demo_arrow.h index 9e368f67d..5a374cedb 100644 --- a/src/arrow/demo_arrow.h +++ b/src/arrow/demo_arrow.h @@ -28,6 +28,7 @@ namespace iceberg::arrow { class ICEBERG_EXPORT DemoArrow { public: std::string print() const; + std::string_view name() const; }; } // namespace iceberg::arrow diff --git a/src/core/demo_table.cc b/src/core/demo_table.cc index 5c9d52141..0b13574ec 100644 --- a/src/core/demo_table.cc +++ b/src/core/demo_table.cc @@ -21,7 +21,9 @@ namespace iceberg { -std::string_view DemoTable::print() const { return "DemoTable"; } +std::string_view DemoTable::print() const { return name(); } + +std::string_view DemoTable::name() const { return "DemoTable"; } std::unique_ptr Table::create() { return std::make_unique(); } diff --git a/src/core/demo_table.h b/src/core/demo_table.h index 075bbadd1..c51c91c9d 100644 --- a/src/core/demo_table.h +++ b/src/core/demo_table.h @@ -29,6 +29,7 @@ class ICEBERG_EXPORT DemoTable : public Table { ~DemoTable() override = default; std::string_view print() const override; + std::string_view name() const; }; } // namespace iceberg From 59bb13520b1fa8db5b4f52e8b9ee5bdfc315ef0a Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Thu, 2 Jan 2025 13:43:10 +0800 Subject: [PATCH 21/34] remove api folder --- CMakeLists.txt | 2 -- cmake_modules/BuildUtils.cmake | 25 +++++++++++++++++++++++ example/demo_example.cc | 9 ++++---- src/.DS_Store | Bin 0 -> 6148 bytes src/CMakeLists.txt | 18 +--------------- {api => src/iceberg}/CMakeLists.txt | 22 ++++++++++++++++---- src/{ => iceberg}/IcebergConfig.cmake.in | 4 ++-- src/{ => iceberg}/arrow/CMakeLists.txt | 14 ++++++------- src/{ => iceberg}/arrow/demo_arrow.cc | 11 +++++----- src/{ => iceberg}/arrow/demo_arrow.h | 8 +++++--- src/{core => iceberg}/demo_table.cc | 8 ++------ src/{core => iceberg}/demo_table.h | 3 +-- {api => src}/iceberg/puffin.h | 6 ++---- src/{ => iceberg}/puffin/CMakeLists.txt | 11 +++++----- src/{ => iceberg}/puffin/demo_puffin.cc | 10 ++++----- src/{ => iceberg}/puffin/demo_puffin.h | 7 +++---- {api => src}/iceberg/table.h | 6 ++---- {api => src}/iceberg/visibility.h | 0 18 files changed, 87 insertions(+), 77 deletions(-) create mode 100644 src/.DS_Store rename {api => src/iceberg}/CMakeLists.txt (60%) rename src/{ => iceberg}/IcebergConfig.cmake.in (97%) rename src/{ => iceberg}/arrow/CMakeLists.txt (81%) rename src/{ => iceberg}/arrow/demo_arrow.cc (80%) rename src/{ => iceberg}/arrow/demo_arrow.h (84%) rename src/{core => iceberg}/demo_table.cc (78%) rename src/{core => iceberg}/demo_table.h (93%) rename {api => src}/iceberg/puffin.h (88%) rename src/{ => iceberg}/puffin/CMakeLists.txt (81%) rename src/{ => iceberg}/puffin/demo_puffin.cc (78%) rename src/{ => iceberg}/puffin/demo_puffin.h (90%) rename {api => src}/iceberg/table.h (88%) rename {api => src}/iceberg/visibility.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a02745322..41658ef68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,6 @@ option(ICEBERG_BUILD_TESTS "Build tests" ON) option(ICEBERG_ARROW "Build Arrow" ON) 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}") @@ -56,7 +55,6 @@ include(CMakeParseArguments) include(BuildUtils) include(ThirdpartyToolchain) -add_subdirectory(api) add_subdirectory(src) if(ICEBERG_BUILD_TESTS) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index d429a2843..f025953ee 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -219,6 +219,31 @@ function(add_iceberg_lib LIB_NAME) endif() endfunction() +function(iceberg_install_all_headers PATH) + set(options) + set(one_value_args) + set(multi_value_args PATTERN) + cmake_parse_arguments(ARG + "${options}" + "${one_value_args}" + "${multi_value_args}" + ${ARGN}) + if(NOT ARG_PATTERN) + set(ARG_PATTERN "*.h" "*.hpp") + endif() + file(GLOB CURRENT_DIRECTORY_HEADERS ${ARG_PATTERN}) + + set(PUBLIC_HEADERS) + foreach(HEADER ${CURRENT_DIRECTORY_HEADERS}) + get_filename_component(HEADER_BASENAME ${HEADER} NAME) + if(HEADER_BASENAME MATCHES "internal") + continue() + endif() + list(APPEND PUBLIC_HEADERS ${HEADER}) + endforeach() + install(FILES ${PUBLIC_HEADERS} DESTINATION "${ICEBERG_INSTALL_INCLUDEDIR}/${PATH}") +endfunction() + function(iceberg_set_export_definitions STATIC_TARGET LIB_TARGETS) if(ICEBERG_BUILD_STATIC AND WIN32) target_compile_definitions(${STATIC_TARGET} PUBLIC ICEBERG_STATIC) diff --git a/example/demo_example.cc b/example/demo_example.cc index 9f42832c2..f4801f10b 100644 --- a/example/demo_example.cc +++ b/example/demo_example.cc @@ -20,13 +20,12 @@ #include #include "iceberg/arrow/demo_arrow.h" -#include "iceberg/puffin.h" -#include "iceberg/table.h" +#include "iceberg/demo_table.h" +#include "iceberg/puffin/demo_puffin.h" int main() { - std::cout << iceberg::Table::create()->print() << std::endl; - std::cout << iceberg::Puffin::create()->print() << std::endl; + std::cout << iceberg::DemoTable().print() << std::endl; + std::cout << iceberg::puffin::DemoPuffin().print() << std::endl; std::cout << iceberg::arrow::DemoArrow().print() << std::endl; - std::cout << iceberg::arrow::DemoArrow().name() << std::endl; return 0; } diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b27e8d87593a2d16f97f4c9919137ef9c9538fa4 GIT binary patch literal 6148 zcmeHKI|@QE5ZqNk!N$@uSMUZw^aNf&{2+oLDE6=NTprEYPoX^Rv`}VYGs$KrAyd44 zD`hPn3=z+wSl zO>6=YfoV{ILDg(AH0X$z%&Un_V9-Ug`Ov&svqMq89p@KM7p;LDsQ?vtR-hZpk=6e> z{7wJ=OyY_PP=UWvKzp;rY>FpkZEZcyYHfip;g)lQn_=!03|@|bUXHP_ay<5=$SXF- XeobrwosPKEf&3XTU1(I`+X~zP{NfdE literal 0 HcmV?d00001 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2d03d23d2..6ec40de28 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,20 +15,4 @@ # specific language governing permissions and limitations # under the License. -set(ICEBERG_CORE_SOURCES core/demo_table.cc) -set(ICEBERG_CORE_INCLUDES "${ICEBERG_API_DIR}") - -add_iceberg_lib(iceberg_core - SOURCES - ${ICEBERG_CORE_SOURCES} - OUTPUTS - ICEBERG_CORE_LIBRARIES - PRIVATE_INCLUDES - ${ICEBERG_CORE_INCLUDES}) - -iceberg_set_export_definitions(iceberg_core_static "${ICEBERG_CORE_LIBRARIES}") - -add_subdirectory(arrow) -add_subdirectory(puffin) - -iceberg_install_cmake_package(Iceberg iceberg_targets) +add_subdirectory(iceberg) diff --git a/api/CMakeLists.txt b/src/iceberg/CMakeLists.txt similarity index 60% rename from api/CMakeLists.txt rename to src/iceberg/CMakeLists.txt index 5a481c88f..a1f3fbced 100644 --- a/api/CMakeLists.txt +++ b/src/iceberg/CMakeLists.txt @@ -15,7 +15,21 @@ # specific language governing permissions and limitations # under the License. -install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/iceberg" - DESTINATION "${ICEBERG_INSTALL_INCLUDEDIR}" - FILES_MATCHING - PATTERN "*.h") +set(ICEBERG_SOURCES demo_table.cc) +set(ICEBERG_INCLUDES "${CMAKE_SOURCE_DIR}/src") + +add_iceberg_lib(iceberg + SOURCES + ${ICEBERG_SOURCES} + OUTPUTS + ICEBERG_LIBRARIES + PRIVATE_INCLUDES + ${ICEBERG_INCLUDES}) + +iceberg_set_export_definitions(iceberg_static "${ICEBERG_LIBRARIES}") +iceberg_install_all_headers(iceberg) + +add_subdirectory(arrow) +add_subdirectory(puffin) + +iceberg_install_cmake_package(Iceberg iceberg_targets) diff --git a/src/IcebergConfig.cmake.in b/src/iceberg/IcebergConfig.cmake.in similarity index 97% rename from src/IcebergConfig.cmake.in rename to src/iceberg/IcebergConfig.cmake.in index 6a42e31c4..e0b690d1f 100644 --- a/src/IcebergConfig.cmake.in +++ b/src/iceberg/IcebergConfig.cmake.in @@ -22,8 +22,8 @@ # # This config sets the following targets (if built) in your project:: # -# Iceberg::iceberg_core_shared -# Iceberg::iceberg_core_static +# Iceberg::iceberg_shared +# Iceberg::iceberg_static # Iceberg::iceberg_puffin_shared # Iceberg::iceberg_puffin_static # Iceberg::iceberg_arrow_shared diff --git a/src/arrow/CMakeLists.txt b/src/iceberg/arrow/CMakeLists.txt similarity index 81% rename from src/arrow/CMakeLists.txt rename to src/iceberg/arrow/CMakeLists.txt index d31e5f86e..fdff890f8 100644 --- a/src/arrow/CMakeLists.txt +++ b/src/iceberg/arrow/CMakeLists.txt @@ -20,7 +20,7 @@ if(NOT ICEBERG_ARROW) endif() set(ICEBERG_ARROW_SOURCES demo_arrow.cc) -set(ICEBERG_ARROW_INCLUDES "${ICEBERG_API_DIR}" "${CMAKE_SOURCE_DIR}/src") +set(ICEBERG_ARROW_INCLUDES "${ICEBERG_INCLUDES}") # Libraries to link with exported libiceberg_arrow.{so,a}. set(ICEBERG_ARROW_STATIC_BUILD_INTERFACE_LIBS) @@ -29,10 +29,10 @@ set(ICEBERG_ARROW_STATIC_INSTALL_INTERFACE_LIBS) set(ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS) list(APPEND ICEBERG_ARROW_STATIC_BUILD_INTERFACE_LIBS - "$,iceberg_core_static,iceberg_core_shared>" + "$,iceberg_static,iceberg_shared>" "$,Arrow::arrow_static,Arrow::arrow_shared>") list(APPEND ICEBERG_ARROW_SHARED_BUILD_INTERFACE_LIBS - "$,iceberg_core_shared,iceberg_core_static>" + "$,iceberg_shared,iceberg_static>" "$,Arrow::arrow_shared,Arrow::arrow_static>") if(ARROW_VENDORED) @@ -51,11 +51,11 @@ endif() list(APPEND ICEBERG_ARROW_STATIC_INSTALL_INTERFACE_LIBS - "$,Iceberg::iceberg_core_static,Iceberg::iceberg_core_shared>" + "$,Iceberg::iceberg_static,Iceberg::iceberg_shared>" ) list(APPEND ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS - "$,Iceberg::iceberg_core_shared,Iceberg::iceberg_core_static>" + "$,Iceberg::iceberg_shared,Iceberg::iceberg_static>" ) add_iceberg_lib(iceberg_arrow @@ -75,6 +75,4 @@ add_iceberg_lib(iceberg_arrow ${ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS}) iceberg_set_export_definitions(iceberg_arrow_static "${ICEBERG_ARROW_LIBRARIES}") - -install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/demo_arrow.h" - DESTINATION "${ICEBERG_INSTALL_INCLUDEDIR}/iceberg/arrow") +iceberg_install_all_headers(iceberg/arrow) diff --git a/src/arrow/demo_arrow.cc b/src/iceberg/arrow/demo_arrow.cc similarity index 80% rename from src/arrow/demo_arrow.cc rename to src/iceberg/arrow/demo_arrow.cc index 2f9c389e3..22c2b2a5d 100644 --- a/src/arrow/demo_arrow.cc +++ b/src/iceberg/arrow/demo_arrow.cc @@ -17,16 +17,17 @@ * under the License. */ -#include "demo_arrow.h" +#include "iceberg/arrow/demo_arrow.h" #include -#include "core/demo_table.h" +#include "iceberg/demo_table.h" namespace iceberg::arrow { -std::string DemoArrow::print() const { return ::arrow::GetBuildInfo().version_string; } - -std::string_view DemoArrow::name() const { return DemoTable().name(); } +std::string DemoArrow::print() const { + return DemoTable().print() + + ", Arrow version: " + ::arrow::GetBuildInfo().version_string; +} } // namespace iceberg::arrow diff --git a/src/arrow/demo_arrow.h b/src/iceberg/arrow/demo_arrow.h similarity index 84% rename from src/arrow/demo_arrow.h rename to src/iceberg/arrow/demo_arrow.h index 5a374cedb..274d3215d 100644 --- a/src/arrow/demo_arrow.h +++ b/src/iceberg/arrow/demo_arrow.h @@ -21,14 +21,16 @@ #include +#include "iceberg/table.h" #include "iceberg/visibility.h" namespace iceberg::arrow { -class ICEBERG_EXPORT DemoArrow { +class ICEBERG_EXPORT DemoArrow : public Table { public: - std::string print() const; - std::string_view name() const; + DemoArrow() = default; + ~DemoArrow() override = default; + std::string print() const override; }; } // namespace iceberg::arrow diff --git a/src/core/demo_table.cc b/src/iceberg/demo_table.cc similarity index 78% rename from src/core/demo_table.cc rename to src/iceberg/demo_table.cc index 0b13574ec..9e46d7ab6 100644 --- a/src/core/demo_table.cc +++ b/src/iceberg/demo_table.cc @@ -17,14 +17,10 @@ * under the License. */ -#include "demo_table.h" +#include "iceberg/demo_table.h" namespace iceberg { -std::string_view DemoTable::print() const { return name(); } - -std::string_view DemoTable::name() const { return "DemoTable"; } - -std::unique_ptr
Table::create() { return std::make_unique(); } +std::string DemoTable::print() const { return "DemoTable"; } } // namespace iceberg diff --git a/src/core/demo_table.h b/src/iceberg/demo_table.h similarity index 93% rename from src/core/demo_table.h rename to src/iceberg/demo_table.h index c51c91c9d..2dabaa5ca 100644 --- a/src/core/demo_table.h +++ b/src/iceberg/demo_table.h @@ -28,8 +28,7 @@ class ICEBERG_EXPORT DemoTable : public Table { DemoTable() = default; ~DemoTable() override = default; - std::string_view print() const override; - std::string_view name() const; + std::string print() const override; }; } // namespace iceberg diff --git a/api/iceberg/puffin.h b/src/iceberg/puffin.h similarity index 88% rename from api/iceberg/puffin.h rename to src/iceberg/puffin.h index 2d681e1d3..d33864b73 100644 --- a/api/iceberg/puffin.h +++ b/src/iceberg/puffin.h @@ -19,8 +19,7 @@ #pragma once -#include -#include +#include #include "iceberg/visibility.h" @@ -29,8 +28,7 @@ namespace iceberg { class ICEBERG_EXPORT Puffin { public: virtual ~Puffin() = default; - virtual std::string_view print() const = 0; - static std::unique_ptr create(); + virtual std::string print() const = 0; }; } // namespace iceberg diff --git a/src/puffin/CMakeLists.txt b/src/iceberg/puffin/CMakeLists.txt similarity index 81% rename from src/puffin/CMakeLists.txt rename to src/iceberg/puffin/CMakeLists.txt index 95574ce13..296122fc9 100644 --- a/src/puffin/CMakeLists.txt +++ b/src/iceberg/puffin/CMakeLists.txt @@ -16,7 +16,7 @@ # under the License. set(ICEBERG_PUFFIN_SOURCES demo_puffin.cc) -set(ICEBERG_PUFFIN_INCLUDES "${ICEBERG_API_DIR}") +set(ICEBERG_PUFFIN_INCLUDES "${ICEBERG_INCLUDES}") set(ICEBERG_PUFFIN_STATIC_BUILD_INTERFACE_LIBS) set(ICEBERG_PUFFIN_SHARED_BUILD_INTERFACE_LIBS) @@ -24,16 +24,16 @@ set(ICEBERG_PUFFIN_STATIC_INSTALL_INTERFACE_LIBS) set(ICEBERG_PUFFIN_SHARED_INSTALL_INTERFACE_LIBS) list(APPEND ICEBERG_PUFFIN_STATIC_BUILD_INTERFACE_LIBS - "$,iceberg_core_static,iceberg_core_shared>") + "$,iceberg_static,iceberg_shared>") list(APPEND ICEBERG_PUFFIN_SHARED_BUILD_INTERFACE_LIBS - "$,iceberg_core_shared,iceberg_core_static>") + "$,iceberg_shared,iceberg_static>") list(APPEND ICEBERG_PUFFIN_STATIC_INSTALL_INTERFACE_LIBS - "$,Iceberg::iceberg_core_static,Iceberg::iceberg_core_shared>" + "$,Iceberg::iceberg_static,Iceberg::iceberg_shared>" ) list(APPEND ICEBERG_PUFFIN_SHARED_INSTALL_INTERFACE_LIBS - "$,Iceberg::iceberg_core_shared,Iceberg::iceberg_core_static>" + "$,Iceberg::iceberg_shared,Iceberg::iceberg_static>" ) add_iceberg_lib(iceberg_puffin @@ -53,3 +53,4 @@ add_iceberg_lib(iceberg_puffin ${ICEBERG_PUFFIN_SHARED_INSTALL_INTERFACE_LIBS}) iceberg_set_export_definitions(iceberg_puffin_static "${ICEBERG_PUFFIN_LIBRARIES}") +iceberg_install_all_headers(iceberg/puffin) diff --git a/src/puffin/demo_puffin.cc b/src/iceberg/puffin/demo_puffin.cc similarity index 78% rename from src/puffin/demo_puffin.cc rename to src/iceberg/puffin/demo_puffin.cc index a4fe7a0d4..a3ee3ef2d 100644 --- a/src/puffin/demo_puffin.cc +++ b/src/iceberg/puffin/demo_puffin.cc @@ -17,12 +17,10 @@ * under the License. */ -#include "demo_puffin.h" +#include "iceberg/puffin/demo_puffin.h" -namespace iceberg { +namespace iceberg::puffin { -std::string_view DemoPuffin::print() const { return "DemoPuffin"; } +std::string DemoPuffin::print() const { return "DemoPuffin"; } -std::unique_ptr Puffin::create() { return std::make_unique(); } - -} // namespace iceberg +} // namespace iceberg::puffin \ No newline at end of file diff --git a/src/puffin/demo_puffin.h b/src/iceberg/puffin/demo_puffin.h similarity index 90% rename from src/puffin/demo_puffin.h rename to src/iceberg/puffin/demo_puffin.h index 8d93cf0f5..c60a8363b 100644 --- a/src/puffin/demo_puffin.h +++ b/src/iceberg/puffin/demo_puffin.h @@ -21,14 +21,13 @@ #include "iceberg/puffin.h" -namespace iceberg { +namespace iceberg::puffin { class ICEBERG_EXPORT DemoPuffin : public Puffin { public: DemoPuffin() = default; ~DemoPuffin() override = default; - - std::string_view print() const override; + std::string print() const override; }; -} // namespace iceberg +} // namespace iceberg::puffin diff --git a/api/iceberg/table.h b/src/iceberg/table.h similarity index 88% rename from api/iceberg/table.h rename to src/iceberg/table.h index 9b4af7374..884bb5e39 100644 --- a/api/iceberg/table.h +++ b/src/iceberg/table.h @@ -19,8 +19,7 @@ #pragma once -#include -#include +#include #include "iceberg/visibility.h" @@ -29,8 +28,7 @@ namespace iceberg { class ICEBERG_EXPORT Table { public: virtual ~Table() = default; - virtual std::string_view print() const = 0; - static std::unique_ptr
create(); + virtual std::string print() const = 0; }; } // namespace iceberg diff --git a/api/iceberg/visibility.h b/src/iceberg/visibility.h similarity index 100% rename from api/iceberg/visibility.h rename to src/iceberg/visibility.h From 64c8e2993c5ea2eb59c866b20d97567b4b4de753 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Thu, 2 Jan 2025 13:48:40 +0800 Subject: [PATCH 22/34] fix lint --- src/iceberg/puffin/demo_puffin.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/iceberg/puffin/demo_puffin.cc b/src/iceberg/puffin/demo_puffin.cc index a3ee3ef2d..51aa08c74 100644 --- a/src/iceberg/puffin/demo_puffin.cc +++ b/src/iceberg/puffin/demo_puffin.cc @@ -23,4 +23,4 @@ namespace iceberg::puffin { std::string DemoPuffin::print() const { return "DemoPuffin"; } -} // namespace iceberg::puffin \ No newline at end of file +} // namespace iceberg::puffin From 0d337bdc651febc257b10d16e056524ddda79075 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Thu, 2 Jan 2025 15:53:11 +0800 Subject: [PATCH 23/34] use generate_export_header --- CMakeLists.txt | 1 + cmake_modules/BuildUtils.cmake | 22 +++++++++++--------- src/iceberg/CMakeLists.txt | 8 ++++---- src/iceberg/arrow/CMakeLists.txt | 7 ++++--- src/iceberg/arrow/demo_arrow.h | 4 ++-- src/iceberg/puffin.h | 2 +- src/iceberg/puffin/CMakeLists.txt | 6 +++--- src/iceberg/puffin/demo_puffin.h | 3 ++- src/iceberg/table.h | 2 +- src/iceberg/visibility.h | 34 ------------------------------- 10 files changed, 30 insertions(+), 59 deletions(-) delete mode 100644 src/iceberg/visibility.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 41658ef68..82c6045ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ endif() include(CMakeParseArguments) include(BuildUtils) include(ThirdpartyToolchain) +include(GenerateExportHeader) add_subdirectory(src) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index f025953ee..e009c5e78 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -211,6 +211,18 @@ function(add_iceberg_lib LIB_NAME) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) endif() + # generate export header file + string(TOUPPER ${LIB_NAME} LIB_NAME_UPPER) + if(BUILD_SHARED) + generate_export_header(${LIB_NAME}_shared BASE_NAME ${LIB_NAME_UPPER}) + if(BUILD_STATIC) + set_target_properties(${LIB_NAME}_static + PROPERTIES COMPILE_FLAGS "-D${LIB_NAME_UPPER}_STATIC_DEFINE") + endif() + elseif(BUILD_STATIC) + generate_export_header(${LIB_NAME}_static BASE_NAME ${LIB_NAME_UPPER}) + endif() + # Modify variable in calling scope if(ARG_OUTPUTS) set(${ARG_OUTPUTS} @@ -243,13 +255,3 @@ function(iceberg_install_all_headers PATH) endforeach() install(FILES ${PUBLIC_HEADERS} DESTINATION "${ICEBERG_INSTALL_INCLUDEDIR}/${PATH}") endfunction() - -function(iceberg_set_export_definitions STATIC_TARGET LIB_TARGETS) - if(ICEBERG_BUILD_STATIC AND WIN32) - target_compile_definitions(${STATIC_TARGET} PUBLIC ICEBERG_STATIC) - endif() - - foreach(LIB_TARGET ${LIB_TARGETS}) - target_compile_definitions(${LIB_TARGET} PRIVATE ICEBERG_EXPORTING) - endforeach() -endfunction() diff --git a/src/iceberg/CMakeLists.txt b/src/iceberg/CMakeLists.txt index a1f3fbced..a84f3f9ca 100644 --- a/src/iceberg/CMakeLists.txt +++ b/src/iceberg/CMakeLists.txt @@ -16,19 +16,19 @@ # under the License. set(ICEBERG_SOURCES demo_table.cc) -set(ICEBERG_INCLUDES "${CMAKE_SOURCE_DIR}/src") +set(ICEBERG_INCLUDES "${CMAKE_SOURCE_DIR}/src" "${CMAKE_BINARY_DIR}/src") add_iceberg_lib(iceberg SOURCES ${ICEBERG_SOURCES} - OUTPUTS - ICEBERG_LIBRARIES PRIVATE_INCLUDES ${ICEBERG_INCLUDES}) -iceberg_set_export_definitions(iceberg_static "${ICEBERG_LIBRARIES}") iceberg_install_all_headers(iceberg) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iceberg_export.h + DESTINATION ${ICEBERG_INSTALL_INCLUDEDIR}/iceberg) + add_subdirectory(arrow) add_subdirectory(puffin) diff --git a/src/iceberg/arrow/CMakeLists.txt b/src/iceberg/arrow/CMakeLists.txt index fdff890f8..cd226e081 100644 --- a/src/iceberg/arrow/CMakeLists.txt +++ b/src/iceberg/arrow/CMakeLists.txt @@ -61,8 +61,6 @@ list(APPEND add_iceberg_lib(iceberg_arrow SOURCES ${ICEBERG_ARROW_SOURCES} - OUTPUTS - ICEBERG_ARROW_LIBRARIES PRIVATE_INCLUDES ${ICEBERG_ARROW_INCLUDES} SHARED_LINK_LIBS @@ -74,5 +72,8 @@ add_iceberg_lib(iceberg_arrow SHARED_INSTALL_INTERFACE_LIBS ${ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS}) -iceberg_set_export_definitions(iceberg_arrow_static "${ICEBERG_ARROW_LIBRARIES}") + iceberg_install_all_headers(iceberg/arrow) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iceberg_arrow_export.h + DESTINATION ${ICEBERG_INSTALL_INCLUDEDIR}/iceberg/arrow) diff --git a/src/iceberg/arrow/demo_arrow.h b/src/iceberg/arrow/demo_arrow.h index 274d3215d..61ac953c5 100644 --- a/src/iceberg/arrow/demo_arrow.h +++ b/src/iceberg/arrow/demo_arrow.h @@ -21,12 +21,12 @@ #include +#include "iceberg/arrow/iceberg_arrow_export.h" #include "iceberg/table.h" -#include "iceberg/visibility.h" namespace iceberg::arrow { -class ICEBERG_EXPORT DemoArrow : public Table { +class ICEBERG_ARROW_EXPORT DemoArrow : public Table { public: DemoArrow() = default; ~DemoArrow() override = default; diff --git a/src/iceberg/puffin.h b/src/iceberg/puffin.h index d33864b73..52514f76f 100644 --- a/src/iceberg/puffin.h +++ b/src/iceberg/puffin.h @@ -21,7 +21,7 @@ #include -#include "iceberg/visibility.h" +#include "iceberg/iceberg_export.h" namespace iceberg { diff --git a/src/iceberg/puffin/CMakeLists.txt b/src/iceberg/puffin/CMakeLists.txt index 296122fc9..5acd6bef1 100644 --- a/src/iceberg/puffin/CMakeLists.txt +++ b/src/iceberg/puffin/CMakeLists.txt @@ -39,8 +39,6 @@ list(APPEND add_iceberg_lib(iceberg_puffin SOURCES ${ICEBERG_PUFFIN_SOURCES} - OUTPUTS - ICEBERG_PUFFIN_LIBRARIES PRIVATE_INCLUDES ${ICEBERG_PUFFIN_INCLUDES} SHARED_LINK_LIBS @@ -52,5 +50,7 @@ add_iceberg_lib(iceberg_puffin SHARED_INSTALL_INTERFACE_LIBS ${ICEBERG_PUFFIN_SHARED_INSTALL_INTERFACE_LIBS}) -iceberg_set_export_definitions(iceberg_puffin_static "${ICEBERG_PUFFIN_LIBRARIES}") iceberg_install_all_headers(iceberg/puffin) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iceberg_puffin_export.h + DESTINATION ${ICEBERG_INSTALL_INCLUDEDIR}/iceberg/puffin) diff --git a/src/iceberg/puffin/demo_puffin.h b/src/iceberg/puffin/demo_puffin.h index c60a8363b..3544b7c10 100644 --- a/src/iceberg/puffin/demo_puffin.h +++ b/src/iceberg/puffin/demo_puffin.h @@ -20,10 +20,11 @@ #pragma once #include "iceberg/puffin.h" +#include "iceberg/puffin/iceberg_puffin_export.h" namespace iceberg::puffin { -class ICEBERG_EXPORT DemoPuffin : public Puffin { +class ICEBERG_PUFFIN_EXPORT DemoPuffin : public Puffin { public: DemoPuffin() = default; ~DemoPuffin() override = default; diff --git a/src/iceberg/table.h b/src/iceberg/table.h index 884bb5e39..bbdd99939 100644 --- a/src/iceberg/table.h +++ b/src/iceberg/table.h @@ -21,7 +21,7 @@ #include -#include "iceberg/visibility.h" +#include "iceberg/iceberg_export.h" namespace iceberg { diff --git a/src/iceberg/visibility.h b/src/iceberg/visibility.h deleted file mode 100644 index 1bf387ddf..000000000 --- a/src/iceberg/visibility.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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. - */ - -#pragma once - -#if defined(_WIN32) || defined(__CYGWIN__) -# ifdef ICEBERG_STATIC -# define ICEBERG_EXPORT -# else -# ifdef ICEBERG_EXPORTING -# define ICEBERG_EXPORT __declspec(dllexport) -# else -# define ICEBERG_EXPORT __declspec(dllimport) -# endif -# endif -#else -# define ICEBERG_EXPORT -#endif From 149ed2193d1e195417d72d6bae82f2cd7f60027a Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Thu, 2 Jan 2025 15:56:29 +0800 Subject: [PATCH 24/34] fix cmake lint --- src/iceberg/arrow/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/iceberg/arrow/CMakeLists.txt b/src/iceberg/arrow/CMakeLists.txt index cd226e081..792631d14 100644 --- a/src/iceberg/arrow/CMakeLists.txt +++ b/src/iceberg/arrow/CMakeLists.txt @@ -72,7 +72,6 @@ add_iceberg_lib(iceberg_arrow SHARED_INSTALL_INTERFACE_LIBS ${ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS}) - iceberg_install_all_headers(iceberg/arrow) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iceberg_arrow_export.h From 2cb3dc9d4b1a7e6e37b9a6b065daadb399773ae5 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Thu, 2 Jan 2025 16:26:55 +0800 Subject: [PATCH 25/34] add STATIC_DEFINE --- cmake_modules/BuildUtils.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index e009c5e78..805188ec3 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -217,7 +217,7 @@ function(add_iceberg_lib LIB_NAME) generate_export_header(${LIB_NAME}_shared BASE_NAME ${LIB_NAME_UPPER}) if(BUILD_STATIC) set_target_properties(${LIB_NAME}_static - PROPERTIES COMPILE_FLAGS "-D${LIB_NAME_UPPER}_STATIC_DEFINE") + PROPERTIES COMPILE_FLAGS -D${LIB_NAME_UPPER}_STATIC_DEFINE) endif() elseif(BUILD_STATIC) generate_export_header(${LIB_NAME}_static BASE_NAME ${LIB_NAME_UPPER}) From d88b5eef804f0a09cfd91a65762eff98c03e0891 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Thu, 2 Jan 2025 22:18:25 +0800 Subject: [PATCH 26/34] try to fix windows export --- cmake_modules/BuildUtils.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index 805188ec3..3b9269a2d 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -215,9 +215,10 @@ function(add_iceberg_lib LIB_NAME) string(TOUPPER ${LIB_NAME} LIB_NAME_UPPER) if(BUILD_SHARED) generate_export_header(${LIB_NAME}_shared BASE_NAME ${LIB_NAME_UPPER}) + target_compile_definitions(${LIB_NAME}_shared PRIVATE ${LIB_NAME}_EXPORTS) if(BUILD_STATIC) - set_target_properties(${LIB_NAME}_static - PROPERTIES COMPILE_FLAGS -D${LIB_NAME_UPPER}_STATIC_DEFINE) + target_compile_definitions(${LIB_NAME}_static + PRIVATE ${LIB_NAME_UPPER}_STATIC_DEFINE) endif() elseif(BUILD_STATIC) generate_export_header(${LIB_NAME}_static BASE_NAME ${LIB_NAME_UPPER}) From 79bba2350caf7988a3ca82767804c5cb046e5f47 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Thu, 2 Jan 2025 22:37:35 +0800 Subject: [PATCH 27/34] try to fix windows export --- cmake_modules/BuildUtils.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index 3b9269a2d..bc848bf9f 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -215,13 +215,18 @@ function(add_iceberg_lib LIB_NAME) string(TOUPPER ${LIB_NAME} LIB_NAME_UPPER) if(BUILD_SHARED) generate_export_header(${LIB_NAME}_shared BASE_NAME ${LIB_NAME_UPPER}) - target_compile_definitions(${LIB_NAME}_shared PRIVATE ${LIB_NAME}_EXPORTS) + target_compile_definitions(${LIB_NAME}_shared + PRIVATE ${LIB_NAME}_shared_EXPORTS + PUBLIC ${LIB_NAME_UPPER}_STATIC_DEFINE) if(BUILD_STATIC) target_compile_definitions(${LIB_NAME}_static - PRIVATE ${LIB_NAME_UPPER}_STATIC_DEFINE) + PUBLIC ${LIB_NAME_UPPER}_STATIC_DEFINE) endif() elseif(BUILD_STATIC) generate_export_header(${LIB_NAME}_static BASE_NAME ${LIB_NAME_UPPER}) + target_compile_definitions(${LIB_NAME}_static + PRIVATE ${LIB_NAME}_static_EXPORTS + PUBLIC ${LIB_NAME_UPPER}_STATIC_DEFINE) endif() # Modify variable in calling scope From be17441a135b6d02fe843579f523f53b7ca8593f Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Thu, 2 Jan 2025 23:56:07 +0800 Subject: [PATCH 28/34] try to fix windows export --- cmake_modules/BuildUtils.cmake | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index bc848bf9f..e76545998 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -215,18 +215,13 @@ function(add_iceberg_lib LIB_NAME) string(TOUPPER ${LIB_NAME} LIB_NAME_UPPER) if(BUILD_SHARED) generate_export_header(${LIB_NAME}_shared BASE_NAME ${LIB_NAME_UPPER}) - target_compile_definitions(${LIB_NAME}_shared - PRIVATE ${LIB_NAME}_shared_EXPORTS - PUBLIC ${LIB_NAME_UPPER}_STATIC_DEFINE) + target_compile_definitions(${LIB_NAME}_shared PUBLIC ${LIB_NAME}_shared_EXPORTS) if(BUILD_STATIC) target_compile_definitions(${LIB_NAME}_static PUBLIC ${LIB_NAME_UPPER}_STATIC_DEFINE) endif() elseif(BUILD_STATIC) generate_export_header(${LIB_NAME}_static BASE_NAME ${LIB_NAME_UPPER}) - target_compile_definitions(${LIB_NAME}_static - PRIVATE ${LIB_NAME}_static_EXPORTS - PUBLIC ${LIB_NAME_UPPER}_STATIC_DEFINE) endif() # Modify variable in calling scope From 254bebefc2f7611627aeeff2c01db93ecf0d499f Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Fri, 3 Jan 2025 09:14:47 +0800 Subject: [PATCH 29/34] use instead of --- cmake_modules/BuildUtils.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index e76545998..c915b3ee2 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -212,16 +212,16 @@ function(add_iceberg_lib LIB_NAME) endif() # generate export header file - string(TOUPPER ${LIB_NAME} LIB_NAME_UPPER) if(BUILD_SHARED) - generate_export_header(${LIB_NAME}_shared BASE_NAME ${LIB_NAME_UPPER}) + generate_export_header(${LIB_NAME}_shared BASE_NAME ${LIB_NAME}) target_compile_definitions(${LIB_NAME}_shared PUBLIC ${LIB_NAME}_shared_EXPORTS) if(BUILD_STATIC) + string(TOUPPER ${LIB_NAME} LIB_NAME_UPPER) target_compile_definitions(${LIB_NAME}_static PUBLIC ${LIB_NAME_UPPER}_STATIC_DEFINE) endif() elseif(BUILD_STATIC) - generate_export_header(${LIB_NAME}_static BASE_NAME ${LIB_NAME_UPPER}) + generate_export_header(${LIB_NAME}_static BASE_NAME ${LIB_NAME}) endif() # Modify variable in calling scope From 24acdacbab2b412de295925e397567285e0443bb Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Fri, 3 Jan 2025 09:20:05 +0800 Subject: [PATCH 30/34] remove definition of LIB_NAME_shared_EXPORTS --- cmake_modules/BuildUtils.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index c915b3ee2..a3e81f7be 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -214,7 +214,9 @@ function(add_iceberg_lib LIB_NAME) # generate export header file if(BUILD_SHARED) generate_export_header(${LIB_NAME}_shared BASE_NAME ${LIB_NAME}) - target_compile_definitions(${LIB_NAME}_shared PUBLIC ${LIB_NAME}_shared_EXPORTS) + # ${LIB_NAME}_shared_EXPORTS should be defined automatically. + # See https://cmake.org/cmake/help/latest/prop_tgt/DEFINE_SYMBOL.html + # target_compile_definitions(${LIB_NAME}_shared PUBLIC ${LIB_NAME}_shared_EXPORTS) if(BUILD_STATIC) string(TOUPPER ${LIB_NAME} LIB_NAME_UPPER) target_compile_definitions(${LIB_NAME}_static From e31ae789dfea900f6fdf8d42d9e52a47f69f8aa7 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Fri, 3 Jan 2025 09:36:11 +0800 Subject: [PATCH 31/34] Revert "remove definition of LIB_NAME_shared_EXPORTS" This reverts commit 24acdacbab2b412de295925e397567285e0443bb. --- cmake_modules/BuildUtils.cmake | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index a3e81f7be..c915b3ee2 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -214,9 +214,7 @@ function(add_iceberg_lib LIB_NAME) # generate export header file if(BUILD_SHARED) generate_export_header(${LIB_NAME}_shared BASE_NAME ${LIB_NAME}) - # ${LIB_NAME}_shared_EXPORTS should be defined automatically. - # See https://cmake.org/cmake/help/latest/prop_tgt/DEFINE_SYMBOL.html - # target_compile_definitions(${LIB_NAME}_shared PUBLIC ${LIB_NAME}_shared_EXPORTS) + target_compile_definitions(${LIB_NAME}_shared PUBLIC ${LIB_NAME}_shared_EXPORTS) if(BUILD_STATIC) string(TOUPPER ${LIB_NAME} LIB_NAME_UPPER) target_compile_definitions(${LIB_NAME}_static From 4553485b8ddd04d8803c5b29fd170ffd72ee0351 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Mon, 6 Jan 2025 22:52:26 +0800 Subject: [PATCH 32/34] remove shared_EXPORTS --- cmake_modules/BuildUtils.cmake | 2 +- src/iceberg/demo_table.cc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index c915b3ee2..7bdeb43f7 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -214,7 +214,7 @@ function(add_iceberg_lib LIB_NAME) # generate export header file if(BUILD_SHARED) generate_export_header(${LIB_NAME}_shared BASE_NAME ${LIB_NAME}) - target_compile_definitions(${LIB_NAME}_shared PUBLIC ${LIB_NAME}_shared_EXPORTS) + # target_compile_definitions(${LIB_NAME}_shared PRIVATE ${LIB_NAME}_shared_EXPORTS) if(BUILD_STATIC) string(TOUPPER ${LIB_NAME} LIB_NAME_UPPER) target_compile_definitions(${LIB_NAME}_static diff --git a/src/iceberg/demo_table.cc b/src/iceberg/demo_table.cc index 9e46d7ab6..d960f1ba2 100644 --- a/src/iceberg/demo_table.cc +++ b/src/iceberg/demo_table.cc @@ -18,6 +18,7 @@ */ #include "iceberg/demo_table.h" +#include "iceberg/puffin.h" namespace iceberg { From 9c065c6d78d2151188aeeda5c1e8aa278c410c85 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Mon, 6 Jan 2025 23:00:33 +0800 Subject: [PATCH 33/34] fix lint --- src/iceberg/demo_table.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/iceberg/demo_table.cc b/src/iceberg/demo_table.cc index d960f1ba2..29879b807 100644 --- a/src/iceberg/demo_table.cc +++ b/src/iceberg/demo_table.cc @@ -18,6 +18,7 @@ */ #include "iceberg/demo_table.h" + #include "iceberg/puffin.h" namespace iceberg { From 343aa9b68e8cd16abc4071f87b1869c752c93884 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Tue, 7 Jan 2025 10:28:00 +0800 Subject: [PATCH 34/34] Update cmake_modules/BuildUtils.cmake Co-authored-by: Sutou Kouhei --- cmake_modules/BuildUtils.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake_modules/BuildUtils.cmake b/cmake_modules/BuildUtils.cmake index 7bdeb43f7..8a30753e1 100644 --- a/cmake_modules/BuildUtils.cmake +++ b/cmake_modules/BuildUtils.cmake @@ -214,7 +214,6 @@ function(add_iceberg_lib LIB_NAME) # generate export header file if(BUILD_SHARED) generate_export_header(${LIB_NAME}_shared BASE_NAME ${LIB_NAME}) - # target_compile_definitions(${LIB_NAME}_shared PRIVATE ${LIB_NAME}_shared_EXPORTS) if(BUILD_STATIC) string(TOUPPER ${LIB_NAME} LIB_NAME_UPPER) target_compile_definitions(${LIB_NAME}_static