Skip to content

ORC-1689: [C++] Generate CMake config file - #1889

Closed
wgtmac wants to merge 14 commits into
apache:mainfrom
wgtmac:ORC-1689
Closed

wgtmac wants to merge 14 commits into
apache:mainfrom
wgtmac:ORC-1689

Conversation

@wgtmac

@wgtmac wgtmac commented Apr 15, 2024

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

Generate cmake config file and install it.

Why are the changes needed?

It is good for downstream projects to find ORC library.

How was this patch tested?

Test it locally.

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions github-actions Bot added the CPP label Apr 15, 2024
@wgtmac

wgtmac commented Apr 15, 2024

Copy link
Copy Markdown
Member Author

Could you help review this? I'm not sure if we need to generate orcTarget.cmake which I think is unnecesarry at the moment. @kou

Comment thread c++/orcConfig.cmake.in Resolved
@wgtmac
wgtmac force-pushed the ORC-1689 branch 2 times, most recently from 8a0eccf to c085b4c Compare April 15, 2024 16:14
@github-actions github-actions Bot added the BUILD label Apr 15, 2024

@kou kou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orcTarget.cmake is needed to link to liborc.a by target_link_libraries(downstream_library orc::orc).

Something like (with TODO...):

diff --git a/c++/CMakeLists.txt b/c++/CMakeLists.txt
index c18277b7..efe6e9a6 100644
--- a/c++/CMakeLists.txt
+++ b/c++/CMakeLists.txt
@@ -15,6 +15,9 @@
 # specific language governing permissions and limitations
 # under the License.
 
+include(GNUInstallDirs)
+set(ORC_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/orc)
+
 add_subdirectory(include)
 add_subdirectory(src)
 
@@ -23,14 +26,10 @@ if (BUILD_CPP_TESTS)
 endif ()
 
 # Generate cmake package configuration files
-include(GNUInstallDirs)
-set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}
-  CACHE PATH "Location of header files")
 include(CMakePackageConfigHelpers)
 configure_package_config_file(
   orcConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/orcConfig.cmake
-  INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/orc
-  PATH_VARS INCLUDE_INSTALL_DIR)
+  INSTALL_DESTINATION ${ORC_INSTALL_CMAKE_DIR})
 write_basic_package_version_file(
   ${CMAKE_CURRENT_BINARY_DIR}/orcConfigVersion.cmake
   VERSION ${ORC_VERSION}
diff --git a/c++/include/CMakeLists.txt b/c++/include/CMakeLists.txt
index 056d1b9f..12b88178 100644
--- a/c++/include/CMakeLists.txt
+++ b/c++/include/CMakeLists.txt
@@ -22,10 +22,10 @@ configure_file (
 
 install(FILES
   "${CMAKE_CURRENT_BINARY_DIR}/orc/orc-config.hh"
-  DESTINATION "include/orc"
+  DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/orc"
   )
 
 install(DIRECTORY
         "orc/"
-        DESTINATION "include/orc"
+        DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/orc"
         FILES_MATCHING PATTERN "*.hh")
diff --git a/c++/orcConfig.cmake.in b/c++/orcConfig.cmake.in
index f3157f62..9c95bd8f 100644
--- a/c++/orcConfig.cmake.in
+++ b/c++/orcConfig.cmake.in
@@ -19,11 +19,9 @@
 #
 #   orc_FOUND - true if orc is found on the system
 #   orc_VERSION - version of the found Orc
-#   orc_INCLUDE_DIR - where to find the Orc headers
 
 @PACKAGE_INIT@
 
-set(orc_VERSION "@ORC_VERSION@")
-set_and_check(orc_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
+include("${CMAKE_CURRENT_LIST_DIR}/orcTargets.cmake")
 
 check_required_components(orc)
diff --git a/c++/src/CMakeLists.txt b/c++/src/CMakeLists.txt
index 4847fe9c..ea645f13 100644
--- a/c++/src/CMakeLists.txt
+++ b/c++/src/CMakeLists.txt
@@ -203,22 +203,30 @@ endif(BUILD_ENABLE_AVX512)
 add_library (orc STATIC ${SOURCE_FILES})
 
 target_include_directories(orc
-  PUBLIC ${PROJECT_SOURCE_DIR}/c++/include
-  PUBLIC ${PROJECT_BINARY_DIR}/c++/include
+  INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+  PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/c++/include>
+  PUBLIC $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/c++/include>
   PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
   PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
   PRIVATE ${LIBHDFSPP_INCLUDE_DIR}
 )
 
 target_link_libraries (orc
-  orc::protobuf
-  orc::zlib
-  orc::snappy
-  orc::lz4
-  orc::zstd
-  ${LIBHDFSPP_LIBRARIES}
+  $<BUILD_INTERFACE:orc::protobuf>
+  $<BUILD_INTERFACE:orc::zlib>
+  $<BUILD_INTERFACE:orc::snappy>
+  $<BUILD_INTERFACE:orc::lz4>
+  $<BUILD_INTERFACE:orc::zstd>
+  $<BUILD_INTERFACE:${LIBHDFSPP_LIBRARIES}>
+  # TODO: We need to add $<INSTALL_INTERFACE:protobuf::libprotobuf>
+  # and so on.  Users also need to link to dependencies because
+  # liborc.a is a static library.
   )
 
 add_dependencies(orc orc-format_ep)
 
-install(TARGETS orc DESTINATION lib)
+install(TARGETS orc EXPORT orc_targets)
+install(EXPORT orc_targets
+  DESTINATION ${ORC_INSTALL_CMAKE_DIR}
+  NAMESPACE "orc::"
+  FILE "orcTargets.cmake")

Comment thread c++/CMakeLists.txt Resolved
Comment thread c++/orcConfig.cmake.in Resolved
Comment thread c++/orcConfig.cmake.in Resolved
@wgtmac

wgtmac commented Apr 16, 2024

Copy link
Copy Markdown
Member Author

I did try to generate the target file but was having a hard time to deal with the third-party libraries and make it relocatable. Let me learn it deeper and try again. Thanks @kou!

@kou

kou commented Apr 16, 2024

Copy link
Copy Markdown
Member

@wgtmac

wgtmac commented Apr 16, 2024

Copy link
Copy Markdown
Member Author

FYI: Apache Arrow creates libarrow_bundled_dependencies.a that contains all *.a built by externalproject_add()/fetchcontent:

We can use only libarrow_bundled_dependencies.a for libarrow.a: https://github.com/apache/arrow/blob/b98763ad079f20e36d82268f9e7cf0db49fdd461/cpp/src/arrow/ArrowConfig.cmake.in#L103-L119

Yes, I looked at that and it can be a separate improvement to Apache ORC because Apache Arrow does not use third-party libraries built by Apache ORC.

@kou

kou commented Apr 16, 2024

Copy link
Copy Markdown
Member

It makes sense.

@wgtmac
wgtmac force-pushed the ORC-1689 branch 2 times, most recently from 39db297 to deeb434 Compare April 17, 2024 15:46
@wgtmac

wgtmac commented Apr 17, 2024

Copy link
Copy Markdown
Member Author

Does the file /tmp/orc/lib/cmake/orc/orcTargets.cmake looks right? @kou

# Generated by CMake

if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.8)
   message(FATAL_ERROR "CMake >= 2.8.0 required")
endif()
if(CMAKE_VERSION VERSION_LESS "2.8.3")
   message(FATAL_ERROR "CMake >= 2.8.3 required")
endif()
cmake_policy(PUSH)
cmake_policy(VERSION 2.8.3...3.25)
#----------------------------------------------------------------
# Generated CMake target import file.
#----------------------------------------------------------------

# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)

# Protect against multiple inclusion, which would fail when already imported targets are added once more.
set(_cmake_targets_defined "")
set(_cmake_targets_not_defined "")
set(_cmake_expected_targets "")
foreach(_cmake_expected_target IN ITEMS orc::orc)
  list(APPEND _cmake_expected_targets "${_cmake_expected_target}")
  if(TARGET "${_cmake_expected_target}")
    list(APPEND _cmake_targets_defined "${_cmake_expected_target}")
  else()
    list(APPEND _cmake_targets_not_defined "${_cmake_expected_target}")
  endif()
endforeach()
unset(_cmake_expected_target)
if(_cmake_targets_defined STREQUAL _cmake_expected_targets)
  unset(_cmake_targets_defined)
  unset(_cmake_targets_not_defined)
  unset(_cmake_expected_targets)
  unset(CMAKE_IMPORT_FILE_VERSION)
  cmake_policy(POP)
  return()
endif()
if(NOT _cmake_targets_defined STREQUAL "")
  string(REPLACE ";" ", " _cmake_targets_defined_text "${_cmake_targets_defined}")
  string(REPLACE ";" ", " _cmake_targets_not_defined_text "${_cmake_targets_not_defined}")
  message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_cmake_targets_defined_text}\nTargets not yet defined: ${_cmake_targets_not_defined_text}\n")
endif()
unset(_cmake_targets_defined)
unset(_cmake_targets_not_defined)
unset(_cmake_expected_targets)


# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
  set(_IMPORT_PREFIX "")
endif()

# Create imported target orc::orc
add_library(orc::orc STATIC IMPORTED)

set_target_properties(orc::orc PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "ENABLE_METRICS=0"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "protobuf::libprotobuf;ZLIB::ZLIB;Snappy::snappy;\$<TARGET_NAME_IF_EXISTS:LZ4::lz4_static>;\$<TARGET_NAME_IF_EXISTS:LZ4::lz4_shared>;\$<TARGET_NAME_IF_EXISTS:zstd::libzstd_static>;\$<TARGET_NAME_IF_EXISTS:zstd::libzstd_shared>"
)

if(CMAKE_VERSION VERSION_LESS 2.8.12)
  message(FATAL_ERROR "This file relies on consumers using CMake 2.8.12 or greater.")
endif()

# Load information for each installed configuration.
file(GLOB _cmake_config_files "${CMAKE_CURRENT_LIST_DIR}/orcTargets-*.cmake")
foreach(_cmake_config_file IN LISTS _cmake_config_files)
  include("${_cmake_config_file}")
endforeach()
unset(_cmake_config_file)
unset(_cmake_config_files)

# Cleanup temporary variables.
set(_IMPORT_PREFIX)

# Loop over all imported files and verify that they actually exist
foreach(_cmake_target IN LISTS _cmake_import_check_targets)
  foreach(_cmake_file IN LISTS "_cmake_import_check_files_for_${_cmake_target}")
    if(NOT EXISTS "${_cmake_file}")
      message(FATAL_ERROR "The imported target \"${_cmake_target}\" references the file
   \"${_cmake_file}\"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   \"${CMAKE_CURRENT_LIST_FILE}\"
but not all the files it references.
")
    endif()
  endforeach()
  unset(_cmake_file)
  unset("_cmake_import_check_files_for_${_cmake_target}")
endforeach()
unset(_cmake_target)
unset(_cmake_import_check_targets)

# This file does not depend on other imported targets which have
# been exported from the same project but in a separate export set.

# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)

@wgtmac
wgtmac requested a review from kou April 17, 2024 16:08
Comment thread c++/src/CMakeLists.txt Resolved
Comment thread c++/src/CMakeLists.txt Resolved
@kou

kou commented Apr 18, 2024

Copy link
Copy Markdown
Member

Yes! But we need to find dependencies such as protobuf::libprotobuf in orcConfig.cmake something like:

diff --git a/c++/orcConfig.cmake.in b/c++/orcConfig.cmake.in
index 561ea3d7..a6b16f8c 100644
--- a/c++/orcConfig.cmake.in
+++ b/c++/orcConfig.cmake.in
@@ -17,6 +17,13 @@
 
 @PACKAGE_INIT@
 
+set(ORC_SYSTEM_DEPENDENCIES "@ORC_SYSTEM_DEPENDENCIES@")
+
+include(CMakeFindDependencyMacro)
+foreach(dependency ${ORC_SYSTEM_DEPENDENCIES})
+  find_dependency(${dependency})
+endforeach()
+
 include("${CMAKE_CURRENT_LIST_DIR}/orcTargets.cmake")
 
 check_required_components(orc)
diff --git a/c++/src/CMakeLists.txt b/c++/src/CMakeLists.txt
index 958da1af..05cd34c1 100644
--- a/c++/src/CMakeLists.txt
+++ b/c++/src/CMakeLists.txt
@@ -203,13 +203,7 @@ add_library (orc STATIC ${SOURCE_FILES})
 
 target_link_libraries (orc
   INTERFACE
-    $<INSTALL_INTERFACE:protobuf::libprotobuf>
-    $<INSTALL_INTERFACE:ZLIB::ZLIB>
-    $<INSTALL_INTERFACE:Snappy::snappy>
-    $<INSTALL_INTERFACE:$<TARGET_NAME_IF_EXISTS:LZ4::lz4_static>>
-    $<INSTALL_INTERFACE:$<TARGET_NAME_IF_EXISTS:LZ4::lz4_shared>>
-    $<INSTALL_INTERFACE:$<TARGET_NAME_IF_EXISTS:zstd::libzstd_static>>
-    $<INSTALL_INTERFACE:$<TARGET_NAME_IF_EXISTS:zstd::libzstd_shared>>
+    ${ORC_INSTALL_INTERFACE_TARGETS}
   PUBLIC
     $<BUILD_INTERFACE:orc::protobuf>
     $<BUILD_INTERFACE:orc::zlib>
diff --git a/cmake_modules/ThirdpartyToolchain.cmake b/cmake_modules/ThirdpartyToolchain.cmake
index c3d414e8..3b65db36 100644
--- a/cmake_modules/ThirdpartyToolchain.cmake
+++ b/cmake_modules/ThirdpartyToolchain.cmake
@@ -15,6 +15,9 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set(ORC_SYSTEM_DEPENDENCIES)
+set(ORC_INSTALL_INTERFACE_TARGETS)
+
 set(ORC_FORMAT_VERSION "1.0.0")
 set(LZ4_VERSION "1.9.3")
 set(SNAPPY_VERSION "1.1.7")
@@ -106,9 +109,13 @@ ExternalProject_Add (orc-format_ep
 # Snappy
 if (ORC_PACKAGE_KIND STREQUAL "conan")
   find_package (Snappy REQUIRED CONFIG)
+  list (APPEND ORC_SYSTEM_DEPENDENCIES Snappy)
+  list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:Snappy::snappy>")
   add_resolved_library (orc_snappy ${Snappy_LIBRARIES} ${Snappy_INCLUDE_DIR})
 elseif (NOT "${SNAPPY_HOME}" STREQUAL "")
   find_package (Snappy REQUIRED)
+  list (APPEND ORC_SYSTEM_DEPENDENCIES Snappy)
+  list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:Snappy::snappy>")
   if (ORC_PREFER_STATIC_SNAPPY AND ${SNAPPY_STATIC_LIB})
     add_resolved_library (orc_snappy ${SNAPPY_STATIC_LIB} ${SNAPPY_INCLUDE_DIR})
   else ()
@@ -141,9 +148,13 @@ add_library (orc::snappy ALIAS orc_snappy)
 
 if (ORC_PACKAGE_KIND STREQUAL "conan")
   find_package (ZLIB REQUIRED CONFIG)
+  list (APPEND ORC_SYSTEM_DEPENDENCIES ZLIB)
+  list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:ZLIB::ZLIB>")
   add_resolved_library (orc_zlib ${ZLIB_LIBRARIES} ${ZLIB_INCLUDE_DIR})
 elseif (NOT "${ZLIB_HOME}" STREQUAL "")
   find_package (ZLIB REQUIRED)
+  list (APPEND ORC_SYSTEM_DEPENDENCIES ZLIB)
+  list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:ZLIB::ZLIB>")
   if (ORC_PREFER_STATIC_ZLIB AND ${ZLIB_STATIC_LIB})
     add_resolved_library (orc_zlib ${ZLIB_STATIC_LIB} ${ZLIB_INCLUDE_DIR})
   else ()
@@ -184,9 +195,17 @@ add_library (orc::zlib ALIAS orc_zlib)
 
 if (ORC_PACKAGE_KIND STREQUAL "conan")
   find_package (ZSTD REQUIRED CONFIG)
+  list (APPEND ORC_SYSTEM_DEPENDENCIES ZSTD)
+  list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:$<TARGET_NAME_IF_EXISTS:zstd::libzstd_static>>")
+  list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:$<TARGET_NAME_IF_EXISTS:zstd::libzstd_shared>>")
   add_resolved_library (orc_zstd ${zstd_LIBRARIES} ${zstd_INCLUDE_DIR})
 elseif (NOT "${ZSTD_HOME}" STREQUAL "")
   find_package (ZSTD REQUIRED)
+  # Zstandard uses "zstd" as its CMake package name. We don't use our
+  # FindZSTD.cmake for find_package(orc).
+  list (APPEND ORC_SYSTEM_DEPENDENCIES zstd)
+  list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:$<TARGET_NAME_IF_EXISTS:zstd::libzstd_static>>")
+  list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:$<TARGET_NAME_IF_EXISTS:zstd::libzstd_shared>>")
   if (ORC_PREFER_STATIC_ZSTD AND ${ZSTD_STATIC_LIB})
     add_resolved_library (orc_zstd ${ZSTD_STATIC_LIB} ${ZSTD_INCLUDE_DIR})
   else ()
@@ -233,9 +252,17 @@ add_library (orc::zstd ALIAS orc_zstd)
 # LZ4
 if (ORC_PACKAGE_KIND STREQUAL "conan")
   find_package (LZ4 REQUIRED CONFIG)
+  list (APPEND ORC_SYSTEM_DEPENDENCIES LZ4)
+  list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:$<TARGET_NAME_IF_EXISTS:LZ4::lz4_static>>")
+  list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:$<TARGET_NAME_IF_EXISTS:LZ4::lz4_shared>>")
   add_resolved_library (orc_lz4 ${lz4_LIBRARIES} ${lz4_INCLUDE_DIR})
 elseif (NOT "${LZ4_HOME}" STREQUAL "")
   find_package (LZ4 REQUIRED)
+  # LZ4 uses "lz4" as its CMake package name. We don't use our
+  # FindLZ4.cmake for find_package(orc).
+  list (APPEND ORC_SYSTEM_DEPENDENCIES lz4)
+  list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:$<TARGET_NAME_IF_EXISTS:LZ4::lz4_static>>")
+  list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:$<TARGET_NAME_IF_EXISTS:LZ4::lz4_shared>>")
   if (ORC_PREFER_STATIC_LZ4 AND ${LZ4_STATIC_LIB})
     add_resolved_library (orc_lz4 ${LZ4_STATIC_LIB} ${LZ4_INCLUDE_DIR})
   else ()
@@ -379,9 +406,13 @@ endif ()
 
 if (ORC_PACKAGE_KIND STREQUAL "conan")
   find_package (Protobuf REQUIRED CONFIG)
+  list (APPEND ORC_SYSTEM_DEPENDENCIES Protobuf)
+  list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:protobuf::libprotobuf>")
   add_resolved_library (orc_protobuf ${protobuf_LIBRARIES} ${protobuf_INCLUDE_DIR})
 elseif (NOT "${PROTOBUF_HOME}" STREQUAL "")
   find_package (Protobuf REQUIRED)
+  list (APPEND ORC_SYSTEM_DEPENDENCIES Protobuf)
+  list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:protobuf::libprotobuf>")
 
   if (ORC_PREFER_STATIC_PROTOBUF AND ${PROTOBUF_STATIC_LIB})
     add_resolved_library (orc_protobuf ${PROTOBUF_STATIC_LIB} ${PROTOBUF_INCLUDE_DIR})

Note that the above diff doesn't work for dependencies that are installed in custom location such as $HOME/local because we use cmake_modules/FindXXX.cmake on build but we don't use it on find_package(orc). They may find different dependencies.

@wgtmac

wgtmac commented Apr 18, 2024 •

Copy link
Copy Markdown
Member Author

Yes, I am already trying to add find_dependency to the config file. Thanks for the detail help!

@kou

kou commented Apr 18, 2024

Copy link
Copy Markdown
Member

FYI: Apache Arrow bundles their custom FindXXX.cmake and use them if they are needed: https://github.com/apache/arrow/blob/73386cb806a429875f1846b69e21beccfd339b21/cpp/cmake_modules/ThirdpartyToolchain.cmake#L236-L250

@wgtmac

wgtmac commented Apr 18, 2024

Copy link
Copy Markdown
Member Author

FYI: Apache Arrow bundles their custom FindXXX.cmake and use them if they are needed: https://github.com/apache/arrow/blob/73386cb806a429875f1846b69e21beccfd339b21/cpp/cmake_modules/ThirdpartyToolchain.cmake#L236-L250

I saw that. What I tried is to install FindXXX.cmake from Apache ORC but they are called before find_dependency in the config file, so I thought it is not a good idea to use them.

@kou

kou commented Apr 18, 2024

Copy link
Copy Markdown
Member

Apache Arrow uses FindXXXAlt.cmake when we need to use CONFIG CMake package.
e.g.: https://github.com/apache/arrow/blob/main/cpp/cmake_modules/FindSnappyAlt.cmake

@wgtmac

wgtmac commented Apr 22, 2024

Copy link
Copy Markdown
Member Author

Finally I make it work for all modes (vendored, providing XXX_HOME, or conan) and this is ready for review. Would you mind taking a look at this again? @kou

@wgtmac

wgtmac commented Apr 22, 2024 •

Copy link
Copy Markdown
Member Author

@h-vetinari @xhochy Could you help check if this breaks conda? I saw there are some patches https://github.com/conda-forge/orc-feedstock/tree/main/recipe/patches. Is it possible to add ORC_PACKAGE_KIND=conda with some code change to remove the patches?

@kou kou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

I haven't tried this but it seems that it will work. Great!

Comment thread cmake_modules/ThirdpartyToolchain.cmake Resolved
@wgtmac

wgtmac commented Apr 22, 2024

Copy link
Copy Markdown
Member Author

cc @dongjoon-hyun @stiga-huang

@deshanxiao

deshanxiao commented Apr 22, 2024 •

Copy link
Copy Markdown
Contributor

Hi @wgtmac I checked vcpkg and the previous patch can not apply any more:

-- Downloading https://github.com/wgtmac/orc/archive/ORC-1689.tar.gz -> wgtmac-orc-ORC-1689.tar.gz...
-- Extracting source /home/deshanxiao/vcpkg/downloads/wgtmac-orc-ORC-1689.tar.gz
-- Applying patch fix-cmake.patch
CMake Error at scripts/cmake/z_vcpkg_apply_patches.cmake:34 (message):
  Applying patch failed: Checking patch c++/src/CMakeLists.txt..

This will not break our existing version. Feel free to merge the PR. And I will make a new PR to remove the patch in vcpkg.

@h-vetinari

Copy link
Copy Markdown
Contributor

@h-vetinari @xhochy Could you help check if this breaks conda?

Thanks for the ping - happy to provide feedback and to try things out!

CC also @nehaljwani, who has been taking care of orc in conda-forge for much longer than I have.

I saw there are some patches https://github.com/conda-forge/orc-feedstock/tree/main/recipe/patches. Is it possible to add ORC_PACKAGE_KIND=conda with some code change to remove the patches?

I just went through the patches in the feedstock (after rebasing them on current main here):

So aside from patch Nr. 2 (if ORC insists to hardcode the STATIC bit), it should be possible to avoid the need for ORC_PACKAGE_KIND=conda in the first place, AFAICT.

@wgtmac

wgtmac commented Apr 23, 2024

Copy link
Copy Markdown
Member Author

Thanks for the check and feedback! @h-vetinari

For the 2nd patch, unfortunately it requires some additional change (not just removing STATIC keyword). The only patch on the Conan side since Apache ORC 2.0.0 is doing the similar thing: https://github.com/conan-io/conan-center-index/blob/master/recipes/orc/all/conanfile.py#L135-L137. I will try to support building shared libraries natively but for now let's still patch this.

@wgtmac

wgtmac commented Apr 23, 2024

Copy link
Copy Markdown
Member Author

@stiga-huang

On the Apache Impala side, we can remove FindOrc.cmake by doing following things:

  • Add the installed location of Apache ORC to CMAKE_PREFIX_PATH
  • find_package(orc REQUIRED CONFIG)
  • target_link_libraries(${PROJECT_NAME} PRIVATE orc::orc)

Comment thread c++/orcConfig.cmake.in

include(CMakeFindDependencyMacro)
foreach(dependency ${ORC_SYSTEM_DEPENDENCIES})
find_dependency(${dependency})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might not understand this correctly. If this file is expected to be used by downstream projects, can we add an option to skip this? Impala finds the dependencies by itself and don't need the ORC lib to do so. Got an error like this in a quick try:

CMake Error at /home/quanlong/workspace/orc/build/install/lib/cmake/orc/FindSnappy.cmake:70 (message):
  Could not find Snappy in system search paths.
Call Stack (most recent call first):
  toolchain/toolchain-packages-gcc10.4.0/cmake-3.22.2/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /home/quanlong/workspace/orc/build/install/lib/cmake/orc/orcConfig.cmake:56 (find_dependency)
  CMakeLists.txt:362 (find_package)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is required by ORC because it depends on them. You need to set Snappy_HOME (and other similar 3rd-party dependencies) to make it work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pointer! I moved forward by adding variables like SNAPPY_HOME, ZLIB_HOME, PROTOBUF_HOME. But got a strange error on protobuf though the headers and libs are all found:

-- SNAPPY_HOME: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/snappy-1.1.8/
-- Found the Snappy header: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/snappy-1.1.8/include/snappy.h
-- Found the Snappy library: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/snappy-1.1.8/lib/libsnappy.so
-- Found the Snappy static library: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/snappy-1.1.8/lib/libsnappy.a
-- ZLIB_HOME: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/zlib-1.2.13/
-- Found the ZLIB header: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/cloudflarezlib-9e601a3f37/include/zlib.h
-- Found the ZLIB library: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/cloudflarezlib-9e601a3f37/lib/libz.so
-- Found the ZLIB static library: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/cloudflarezlib-9e601a3f37/lib/libz.a
-- ZSTD_HOME: 
-- Found the zstd header: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/zstd-1.5.2/include/zstd.h
-- Found the zstd library: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/zstd-1.5.2/lib/libzstd.so
-- Found the zstd static library: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/zstd-1.5.2/lib/libzstd.a
-- LZ4_HOME: 
-- Found the LZ4 header: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/lz4-1.9.3/include/lz4.h
-- Found the LZ4 library: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/lz4-1.9.3/lib/liblz4.so
-- Found the LZ4 static library: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/lz4-1.9.3/lib/liblz4.a
-- PROTOBUF_HOME: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/protobuf-3.14.0/
-- Could NOT find Protobuf (missing: Protobuf_DIR)
-- Found the Protobuf headers: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/protobuf-3.14.0/include
-- Found the Protobuf library: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/protobuf-3.14.0/lib/libprotobuf.so
-- Found the Protoc library: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/protobuf-3.14.0/lib/libprotoc.so
-- Found the Protoc executable: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/protobuf-3.14.0/bin/protoc
-- Found the Protobuf static library: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/protobuf-3.14.0/lib/libprotobuf.a
-- Found the Protoc static library: /home/quanlong/workspace/Impala/toolchain/toolchain-packages-gcc10.4.0/protobuf-3.14.0/lib/libprotoc.a
CMake Error at CMakeLists.txt:366 (find_package):
  Found package configuration file:

    /home/quanlong/workspace/orc/build/install/lib/cmake/orc/orcConfig.cmake

  but it set orc_FOUND to FALSE so package "orc" is considered to be NOT
  FOUND.  Reason given by package:

  orc could not be found because dependency Protobuf could not be found.

Impala builds on pre-built toolchain binaries including liborc.a so it doesn't need ORC to find these libraries since no need to build ORC again. I modified orcConfig.cmake to set ORC_SYSTEM_DEPENDENCIES empty and was able to build Impala:

-set(ORC_SYSTEM_DEPENDENCIES "Snappy;ZLIB;ZSTD;LZ4;Protobuf")
+set(ORC_SYSTEM_DEPENDENCIES "")

Note that the regular process to build Impala is

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message means that it tried to read Protobuf_FOUND but we set PROTOBUF_FOUND. This is fixed now. Would you mind trying it again?

BTW, we do not build ORC again when find_package(orc) is called. Instead, it simply tries to find linked interface libraries and sets the correct library installed location to them.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have also added XXX_ROOT env and variables, which aligns with what currently Impala does.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing these issues! Just verified, the build of Impala succeeds now.

It seems ORC can still build without these fixes. Just curious, is it possible to add tests for this file, or it can only be tested by external systems?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This target file will be adopted by Apache Arrow once released. I can also add a test to make sure it works (perhaps with vendored third-party libraries only). Let me think about it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to add the tests in a separate PR.

Comment thread c++/orcConfig.cmake.in Resolved
Comment thread c++/CMakeLists.txt Resolved
Comment thread c++/orcConfig.cmake.in Resolved

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this effort.

Comment thread c++/orcConfig.cmake.in Outdated
# specific language governing permissions and limitations
# under the License.
#
# This config sets the following variables in your project::

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there are duplicated colons at the end "::"

Comment thread c++/orcConfig.cmake.in Outdated
# orc_VERSION - version of the found ORC
# orc_FOUND - true if ORC found on the system
#
# This config sets the following targets in your project::

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: also have duplicated colons here

Comment thread c++/orcConfig.cmake.in

include(CMakeFindDependencyMacro)
foreach(dependency ${ORC_SYSTEM_DEPENDENCIES})
find_dependency(${dependency})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to add the tests in a separate PR.

Comment thread c++/orcConfig.cmake.in Resolved
Comment thread c++/orcConfig.cmake.in Resolved
@wgtmac wgtmac closed this in 3bf6ea9 Apr 27, 2024
@wgtmac

wgtmac commented Apr 27, 2024

Copy link
Copy Markdown
Member Author

I have just merged it. Thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants