Skip to content

Conversation

wgtmac
Copy link
Member

@wgtmac wgtmac commented Sep 26, 2025

What changes were proposed in this pull request?

  • Rename builtin FindXXX.cmake to FindXXXAlt.cmake to not interfere with cannonical package name. These are now only used when XXX_HOME or its friends are set. This includes:
    • FindGTest.cmake -> FindGTestAlt.cmake
    • FindLZ4.cmake -> FindLZ4Alt.cmake
    • FindProtobuf.cmake -> FindProtobufAlt.cmake
    • FindSnappy.cmake -> FindSnappyAlt.cmake
    • FindZLIB.cmake -> FindZLIBAlt.cmake
    • FindZSTD.cmake -> FindZSTDAlt.cmake
  • Bump CMake minimum requirement to 3.25 to leverage FetchContent with FIND_PACKAGE_ARGS. For 3rd party dependencies now, we try to find system installed one via CONFIG mode or fallback to vendor it. This includes:
    • GTest
    • LZ4
    • Protobuf
    • Snappy
    • ZSTD
    • ZLIB: note that we use an unreleased version (1.4.0) to work around its misuse of build and install interface
    • Sparsehash: always vendor it with workaround to its CMake misuse

Why are the changes needed?

How was this patch tested?

  • Pass all CIs
  • Test it manually

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

No

@wgtmac wgtmac force-pushed the fetch_content branch 15 times, most recently from 92abe65 to fd72130 Compare September 28, 2025 02:41
@wgtmac wgtmac changed the title WIP: [C++] Bump to CMake 3.25+ to use FetchContent ORC-2013: [C++] Bump to CMake 3.25+ to use FetchContent Sep 28, 2025
@wgtmac wgtmac force-pushed the fetch_content branch 8 times, most recently from a211c31 to f08a5b2 Compare September 28, 2025 09:11
@github-actions github-actions bot added the INFRA label Sep 28, 2025
@wgtmac wgtmac marked this pull request as ready for review September 28, 2025 09:21
@wgtmac
Copy link
Member Author

wgtmac commented Sep 28, 2025

This PR is ready for review.

The two failed CIs are due to outdated CMake versions from amazonlinux23 and debian11. Should we remove them? @dongjoon-hyun

For now XXX_HOME variables are still supported and take higher priority than FetchContent call, so Apache Arrow C++ should not be affected. Is it possible for Apache Arrow to leverage this improvement? @kou @raulcd

Can conda leverage improvement from this PR, or is there any additional change that is required to add? @h-vetinari @WillAyd

list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:protobuf::libprotobuf>")
orc_provide_find_module (ProtobufAlt)
else ()
prepare_fetchcontent()
Copy link
Member

Choose a reason for hiding this comment

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

If we call this in top-level, changed variables in this context are visible after this clause.

How about using function() or block()?

function(build_protobuf)
  prepare_fetchcontent()
  ...
endfunction()
build_protobuf()

https://cmake.org/cmake/help/latest/command/block.html

block()
  prepare_fetchcontent()
  ...
endblock()

Copy link
Member Author

Choose a reason for hiding this comment

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

Good suggestion! I've switched to use blocks.

Comment on lines 305 to 306
elseif (NOT "${SNAPPY_HOME}" STREQUAL "")
find_package (Snappy REQUIRED)
find_package (SnappyAlt REQUIRED)
if (ORC_PREFER_STATIC_SNAPPY AND SNAPPY_STATIC_LIB)
orc_add_resolved_library (orc_snappy ${SNAPPY_STATIC_LIB} ${SNAPPY_INCLUDE_DIR})
else ()
orc_add_resolved_library (orc_snappy ${SNAPPY_LIBRARY} ${SNAPPY_INCLUDE_DIR})
endif ()
list (APPEND ORC_SYSTEM_DEPENDENCIES Snappy)
list (APPEND ORC_SYSTEM_DEPENDENCIES SnappyAlt)
list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:Snappy::snappy>")
orc_provide_find_module (Snappy)
orc_provide_find_module (SnappyAlt)
else ()
Copy link
Member

Choose a reason for hiding this comment

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

We may be able to remove SnappyAlt entirely by setting Snappy_ROOT:

Suggested change
elseif (NOT "${SNAPPY_HOME}" STREQUAL "")
find_package (Snappy REQUIRED)
find_package (SnappyAlt REQUIRED)
if (ORC_PREFER_STATIC_SNAPPY AND SNAPPY_STATIC_LIB)
orc_add_resolved_library (orc_snappy ${SNAPPY_STATIC_LIB} ${SNAPPY_INCLUDE_DIR})
else ()
orc_add_resolved_library (orc_snappy ${SNAPPY_LIBRARY} ${SNAPPY_INCLUDE_DIR})
endif ()
list (APPEND ORC_SYSTEM_DEPENDENCIES Snappy)
list (APPEND ORC_SYSTEM_DEPENDENCIES SnappyAlt)
list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:Snappy::snappy>")
orc_provide_find_module (Snappy)
orc_provide_find_module (SnappyAlt)
else ()
else ()
if (NOT "${SNAPPY_HOME}" STREQUAL "" AND "${Snappy_ROOT}" STREQUAL "")
set(Snappy_ROOT "${SNAPPY_HOME}")
endif()

See also: https://cmake.org/cmake/help/latest/variable/PackageName_ROOT.html

Copy link
Member Author

@wgtmac wgtmac Sep 29, 2025

Choose a reason for hiding this comment

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

Doesn't it break arrow-cpp (where SNAPPY_LIBRARY and SNAPPY_INCLUDE_DIR are explicitly provided)?

Update: I've tried to apply this change with or without CONFIG in the FIND_PACKAGE_ARGS. In both cases, system snappy is used instead of arrow vendored one.

-- Apache ORC: Found the Protobuf headers: /Users/gangwu/Projects/arrow/cpp/orc_build/protobuf_ep-install/include
-- Apache ORC: Found the Protobuf library: arrow::protobuf::libprotobuf
-- Apache ORC: Found the Protoc library: arrow::protobuf::libprotoc
-- Apache ORC: Found the Protoc executable: arrow::protobuf::protoc
-- Apache ORC: Found the Protobuf static library: /Users/gangwu/Projects/arrow/cpp/orc_build/protobuf_ep-install/lib/libprotobuf.a
-- Apache ORC: Found the Protoc static library: /Users/gangwu/Projects/arrow/cpp/orc_build/protobuf_ep-install/lib/libprotoc.a
-- Apache ORC: Providing CMake module for FindProtobufAlt as part of CMake package
-- Apache ORC: Using system snappy                     <==================
-- Apache ORC: ZLIB_HOME: /Users/gangwu/Projects/arrow/cpp/orc_build/zlib_ep/src/zlib_ep-install
-- Apache ORC: Found the ZLIB header: /Users/gangwu/Projects/arrow/cpp/orc_build/zlib_ep/src/zlib_ep-install/include/zlib.h
-- Apache ORC: Found the ZLIB library: ZLIB::ZLIB
-- Apache ORC: Found the ZLIB static library: /Users/gangwu/Projects/arrow/cpp/orc_build/zlib_ep/src/zlib_ep-install/lib/libz.a
-- Apache ORC: Providing CMake module for FindZLIBAlt as part of CMake package

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm now using CONFIG mode in the FIND_PACKAGE_ARGS so it is not compatible if we remove XXXAlt.

Comment on lines 385 to +379
elseif (NOT "${ZLIB_HOME}" STREQUAL "")
find_package (ZLIB REQUIRED)
find_package (ZLIBAlt REQUIRED)
Copy link
Member

Choose a reason for hiding this comment

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

We may be able to remove FindZLIBAlt.cmake. CMake's FindZLIB provides ZLIB_ROOT hint: https://cmake.org/cmake/help/latest/module/FindZLIB.html#hints

Comment on lines 345 to 348
install(FILES ${snappy_SOURCE_DIR}/snappy-c.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(FILES ${snappy_SOURCE_DIR}/snappy-sinksource.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(FILES ${snappy_SOURCE_DIR}/snappy.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(FILES ${snappy_BINARY_DIR}/snappy-stubs-public.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
Copy link
Member

Choose a reason for hiding this comment

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

We may not need to install header files.

ORC doesn't use Snappy in public headers, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to install it, otherwise downstream project may fail like below:

CMake Error at CMakeLists.txt:9 (target_link_libraries):
  Cannot find source file:

    /tmp/orc/include/snappy-c.h

The reason is that Snappy adds these 4 header files as install interface: https://github.com/google/snappy/blob/1.2.2/CMakeLists.txt#L266

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.

2 participants