Skip to content

Commit 96afee0

Browse files
committed
ORC-2013: [C++] Bump to CMake 3.25+ to use FetchContent
### 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? - #2408 - #2147 - #2016 - apache/arrow#46906 ### How was this patch tested? - Pass all CIs - Test it manually ### Was this patch authored or co-authored using generative AI tooling? No Closes #2416 from wgtmac/fetch_content. Authored-by: Gang Wu <ustcwg@gmail.com> Signed-off-by: Gang Wu <ustcwg@gmail.com>
1 parent cff8877 commit 96afee0

18 files changed

+460
-423
lines changed

.github/workflows/build_and_test.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,12 @@ jobs:
269269
steps:
270270
- name: Checkout repository
271271
uses: actions/checkout@v5
272-
- name: Install dependencies
273-
run: |
274-
brew update
275-
brew install protobuf
276272
- name: Test
277273
run: |
278274
CMAKE_PREFIX_PATH=$(brew --prefix protobuf)
279275
mkdir -p build
280276
cd build
281-
cmake .. -DBUILD_JAVA=OFF -DPROTOBUF_HOME=${CMAKE_PREFIX_PATH}
277+
cmake .. -DBUILD_JAVA=OFF
282278
make package test-out
283279
284280
meson:

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
cmake_minimum_required (VERSION 3.12.0)
18+
cmake_minimum_required (VERSION 3.25.0)
1919
if (POLICY CMP0048)
2020
cmake_policy(SET CMP0048 NEW)
2121
endif ()
@@ -99,6 +99,7 @@ endif ()
9999

100100
# Set the package format
101101
SET(CPACK_GENERATOR "TGZ")
102+
SET(CPACK_SOURCE_GENERATOR "TGZ")
102103
SET(CPACK_PACKAGE_VENDOR "Apache ORC")
103104
SET(CPACK_PACKAGE_CONTACT "Apache ORC <dev@orc.apache.org>")
104105

c++/orcConfig.cmake.in

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
@PACKAGE_INIT@
3535

36-
set(ORC_VENDOR_DEPENDENCIES "@ORC_VENDOR_DEPENDENCIES@")
3736
set(ORC_SYSTEM_DEPENDENCIES "@ORC_SYSTEM_DEPENDENCIES@")
3837

3938
if(DEFINED CMAKE_MODULE_PATH)
@@ -59,30 +58,6 @@ include("${CMAKE_CURRENT_LIST_DIR}/orcTargets.cmake")
5958

6059
get_target_property(orc_static_configurations orc::orc IMPORTED_CONFIGURATIONS)
6160

62-
foreach(dependency ${ORC_VENDOR_DEPENDENCIES})
63-
string(REPLACE "|" ";" dependency_pair ${dependency})
64-
list(LENGTH dependency_pair dependency_pair_length)
65-
if(NOT dependency_pair_length EQUAL 2)
66-
message(FATAL_ERROR "Invalid vendor dependency: ${dependency}")
67-
endif()
68-
list(GET dependency_pair 0 target_name)
69-
list(GET dependency_pair 1 static_lib_name)
70-
71-
add_library("${target_name}" STATIC IMPORTED)
72-
73-
foreach(CONFIGURATION ${orc_static_configurations})
74-
string(TOUPPER "${CONFIGURATION}" CONFIGURATION)
75-
get_target_property(orc_static_location orc::orc LOCATION_${CONFIGURATION})
76-
get_filename_component(orc_lib_dir "${orc_static_location}" DIRECTORY)
77-
set_property(TARGET "${target_name}"
78-
APPEND
79-
PROPERTY IMPORTED_CONFIGURATIONS ${CONFIGURATION})
80-
set_target_properties("${target_name}"
81-
PROPERTIES IMPORTED_LOCATION_${CONFIGURATION}
82-
"${orc_lib_dir}/${static_lib_name}")
83-
endforeach()
84-
endforeach()
85-
8661
check_required_components(orc)
8762

8863
foreach(BUILD_TYPE_SUFFIX

c++/src/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ CHECK_CXX_SOURCE_RUNS("
119119
HAS_POST_2038
120120
)
121121

122-
set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
123-
set(CMAKE_REQUIRED_LIBRARIES orc_zlib)
122+
set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
123+
set(CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARIES})
124124
CHECK_CXX_SOURCE_COMPILES("
125125
#define Z_PREFIX
126126
#include<zlib.h>
@@ -205,14 +205,14 @@ add_library (orc STATIC ${SOURCE_FILES})
205205
target_link_libraries (orc
206206
INTERFACE
207207
${ORC_INSTALL_INTERFACE_TARGETS}
208-
PRIVATE
208+
PUBLIC
209209
$<BUILD_INTERFACE:orc::protobuf>
210210
$<BUILD_INTERFACE:orc::zlib>
211-
$<BUILD_INTERFACE:orc::snappy>
211+
$<BUILD_INTERFACE:orc::Snappy>
212212
$<BUILD_INTERFACE:orc::lz4>
213213
$<BUILD_INTERFACE:orc::zstd>
214214
$<BUILD_INTERFACE:${LIBHDFSPP_LIBRARIES}>
215-
$<BUILD_INTERFACE:${SPARSEHASH_LIBRARIES}>
215+
$<BUILD_INTERFACE:$<TARGET_NAME_IF_EXISTS:orc::sparsehash>>
216216
)
217217

218218
target_include_directories (orc

c++/src/wrap/orc-proto-wrapper.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
DIAGNOSTIC_IGNORE("-Warray-bounds")
2424
DIAGNOSTIC_IGNORE("-Wconversion")
2525
DIAGNOSTIC_IGNORE("-Wdeprecated")
26+
DIAGNOSTIC_IGNORE("-Wdeprecated-declarations")
2627
DIAGNOSTIC_IGNORE("-Wignored-qualifiers")
2728
DIAGNOSTIC_IGNORE("-Wpadded")
2829
DIAGNOSTIC_IGNORE("-Wsign-compare")

c++/src/wrap/orc-proto-wrapper.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ DIAGNOSTIC_PUSH
2727
#if defined(__GNUC__) || defined(__clang__)
2828
DIAGNOSTIC_IGNORE("-Wconversion")
2929
DIAGNOSTIC_IGNORE("-Wdeprecated")
30+
DIAGNOSTIC_IGNORE("-Wdeprecated-declarations")
3031
DIAGNOSTIC_IGNORE("-Wsign-conversion")
3132
DIAGNOSTIC_IGNORE("-Wunused-parameter")
3233
#endif

c++/test/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ add_executable (orc-test
6262

6363
target_link_libraries (orc-test
6464
orc
65-
orc::lz4
66-
orc::protobuf
67-
orc::snappy
68-
orc::zlib
6965
orc::gtest
7066
orc::gmock
7167
)
@@ -76,7 +72,6 @@ add_executable (create-test-files
7672

7773
target_link_libraries (create-test-files
7874
orc
79-
orc::protobuf
8075
)
8176

8277
if (TEST_VALGRIND_MEMCHECK)
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# GTEST_LIBRARY: path to libgtest
2323
# GMOCK_STATIC_LIB: is set to gmock.a static library
2424
# GTEST_STATIC_LIB: is set to gtest.a static library
25-
# GTEST_FOUND is set if GTEST is found
25+
# GTestAlt_FOUND is set if GTEST is found
2626

2727
if (NOT "${GTEST_HOME}" STREQUAL "")
2828
message (STATUS "GTEST_HOME set: ${GTEST_HOME}")
@@ -52,14 +52,14 @@ find_library (GTEST_STATIC_LIB NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_
5252
PATH_SUFFIXES "lib")
5353

5454
if (GTEST_INCLUDE_DIR AND GMOCK_LIBRARY)
55-
set (GTEST_FOUND TRUE)
55+
set (GTestAlt_FOUND TRUE)
5656
set (GTEST_HEADER_NAME gmock/gmock.h)
5757
set (GTEST_HEADER ${GTEST_INCLUDE_DIR}/${GTEST_HEADER_NAME})
5858
else ()
59-
set (GTEST_FOUND FALSE)
59+
set (GTestAlt_FOUND FALSE)
6060
endif ()
6161

62-
if (GTEST_FOUND)
62+
if (GTestAlt_FOUND)
6363
message (STATUS "Found the GTest header: ${GTEST_HEADER}")
6464
message (STATUS "Found the GTest library: ${GTEST_LIBRARY}")
6565
message (STATUS "Found the GMock library: ${GMOCK_LIBRARY}")
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# LZ4_INCLUDE_DIR: directory containing headers
2121
# LZ4_LIBRARY: path to liblz4
2222
# LZ4_STATIC_LIB: path to lz4.a
23-
# LZ4_FOUND: whether LZ4 has been found
23+
# LZ4Alt_FOUND: whether LZ4 has been found
2424

2525
if (NOT LZ4_HOME)
2626
if (DEFINED ENV{LZ4_HOME})
@@ -52,14 +52,14 @@ find_library (LZ4_STATIC_LIB NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}${LZ4_LIB_NAME}
5252
PATH_SUFFIXES "lib" "lib64")
5353

5454
if (LZ4_INCLUDE_DIR AND LZ4_LIBRARY)
55-
set (LZ4_FOUND TRUE)
55+
set (LZ4Alt_FOUND TRUE)
5656
set (LZ4_HEADER_NAME lz4.h)
5757
set (LZ4_HEADER ${LZ4_INCLUDE_DIR}/${LZ4_HEADER_NAME})
5858
else ()
59-
set (LZ4_FOUND FALSE)
59+
set (LZ4Alt_FOUND FALSE)
6060
endif ()
6161

62-
if (LZ4_FOUND)
62+
if (LZ4Alt_FOUND)
6363
message (STATUS "Found the LZ4 header: ${LZ4_HEADER}")
6464
message (STATUS "Found the LZ4 library: ${LZ4_LIBRARY}")
6565
if (LZ4_STATIC_LIB)
@@ -85,7 +85,7 @@ mark_as_advanced (
8585
LZ4_LIBRARY
8686
)
8787

88-
if(LZ4_FOUND AND NOT TARGET LZ4::lz4)
88+
if(LZ4Alt_FOUND AND NOT TARGET LZ4::lz4)
8989
add_library(LZ4::lz4 UNKNOWN IMPORTED)
9090
set_target_properties(LZ4::lz4
9191
PROPERTIES IMPORTED_LOCATION "${LZ4_LIBRARY}"
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
# PROTOBUF_HOME environmental variable is used to check for Protobuf headers and static library
1919

20-
# Protobuf_FOUND is set if Protobuf is found
20+
# ProtobufAlt_FOUND is set if Protobuf is found
2121
# PROTOBUF_INCLUDE_DIR: directory containing headers
2222
# PROTOBUF_LIBRARY: location of libprotobuf
2323
# PROTOBUF_STATIC_LIB: location of protobuf.a
@@ -54,7 +54,7 @@ if (NOT DEFINED CMAKE_STATIC_LIBRARY_SUFFIX)
5454
endif ()
5555

5656
find_package (Protobuf CONFIG)
57-
if (Protobuf_FOUND)
57+
if (ProtobufAlt_FOUND)
5858
if (TARGET protobuf::libprotobuf)
5959
set (PROTOBUF_LIBRARY protobuf::libprotobuf)
6060
set (PROTOBUF_STATIC_LIB PROTOBUF_STATIC_LIB-NOTFOUND)
@@ -127,14 +127,14 @@ else()
127127
endif ()
128128

129129
if (PROTOBUF_INCLUDE_DIR AND PROTOBUF_LIBRARY AND PROTOC_LIBRARY AND PROTOBUF_EXECUTABLE)
130-
set (Protobuf_FOUND TRUE)
130+
set (ProtobufAlt_FOUND TRUE)
131131
set (PROTOBUF_LIB_NAME protobuf)
132132
set (PROTOC_LIB_NAME protoc)
133133
else ()
134-
set (Protobuf_FOUND FALSE)
134+
set (ProtobufAlt_FOUND FALSE)
135135
endif ()
136136

137-
if (Protobuf_FOUND)
137+
if (ProtobufAlt_FOUND)
138138
message (STATUS "Found the Protobuf headers: ${PROTOBUF_INCLUDE_DIR}")
139139
message (STATUS "Found the Protobuf library: ${PROTOBUF_LIBRARY}")
140140
message (STATUS "Found the Protoc library: ${PROTOC_LIBRARY}")
@@ -167,7 +167,7 @@ mark_as_advanced (
167167
PROTOC_LIBRARY
168168
)
169169

170-
if(Protobuf_FOUND AND NOT TARGET protobuf::libprotobuf)
170+
if(ProtobufAlt_FOUND AND NOT TARGET protobuf::libprotobuf)
171171
add_library(protobuf::libprotobuf UNKNOWN IMPORTED)
172172
set_target_properties(protobuf::libprotobuf
173173
PROPERTIES IMPORTED_LOCATION "${PROTOBUF_LIBRARY}"

0 commit comments

Comments
 (0)