Skip to content

Commit b1a871c

Browse files
committed
2
1 parent 2d5dbe4 commit b1a871c

File tree

1 file changed

+39
-89
lines changed

1 file changed

+39
-89
lines changed

cmake_modules/IcebergThirdpartyToolchain.cmake

Lines changed: 39 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -215,155 +215,104 @@ function(resolve_avro_dependency)
215215
endfunction()
216216

217217
# ----------------------------------------------------------------------
218-
# cURL (vendored if necessary for cpr)
218+
# Curl
219219

220220
function(resolve_curl_dependency)
221221
prepare_fetchcontent()
222222

223-
# Configuration for the vendored build case. These variables must be set
224-
# before FetchContent_MakeAvailable is called.
225-
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Crucial for -fPIC on Linux
226-
set(HTTP_ONLY
227-
ON
228-
CACHE BOOL "" FORCE)
229223
set(BUILD_CURL_EXE
230224
OFF
231225
CACHE BOOL "" FORCE)
232226
set(BUILD_TESTING
233227
OFF
234228
CACHE BOOL "" FORCE)
235-
set(CURL_DISABLE_INSTALL
236-
ON
237-
CACHE BOOL "" FORCE)
238-
set(CURL_USE_OPENSSL
239-
ON
240-
CACHE BOOL "" FORCE)
241-
set(CURL_DISABLE_LDAP
242-
ON
243-
CACHE BOOL "" FORCE)
244-
set(CURL_DISABLE_LDAPS
245-
ON
246-
CACHE BOOL "" FORCE)
247-
set(USE_LIBIDN2
248-
OFF
249-
CACHE BOOL "" FORCE)
250-
set(USE_IDN
251-
OFF
252-
CACHE BOOL "" FORCE)
253229

254-
# Using FIND_PACKAGE_ARGS, FetchContent will first try `find_package(CURL)`.
255-
# If that fails, it will proceed to download and build from the URL.
256-
if(APPLE)
257-
# 在 macOS 上,我们不信任系统 curl,总是自己构建
258-
# 所以我们不使用 FIND_PACKAGE_ARGS
259-
fetchcontent_declare(curl
260-
${FC_DECLARE_COMMON_OPTIONS}
261-
URL https://github.com/curl/curl/releases/download/curl-8_9_1/curl-8.9.1.tar.xz
262-
)
263-
else()
264-
# 在其他系统上,继续使用 find-or-fetch 策略
265-
fetchcontent_declare(curl
266-
${FC_DECLARE_COMMON_OPTIONS}
267-
URL https://github.com/curl/curl/releases/download/curl-8_9_1/curl-8.9.1.tar.xz
268-
FIND_PACKAGE_ARGS
269-
NAMES
270-
CURL
271-
7.64.0
272-
CONFIG)
273-
endif()
230+
fetchcontent_declare(curl
231+
${FC_DECLARE_COMMON_OPTIONS}
232+
GIT_REPOSITORY https://github.com/curl/curl.git
233+
GIT_TAG d755a5f7c009dd63a61b2c745180d8ba937cbfeb # Version 8.4.0
234+
FIND_PACKAGE_ARGS
235+
NAMES
236+
CURL
237+
8.4.0
238+
CONFIG)
274239

275240
fetchcontent_makeavailable(curl)
276241

277-
# Check if FetchContent actually downloaded and built the dependency.
278-
# The variable is <lowercase_name>_POPULATED.
279-
if(curl_POPULATED)
280-
message(STATUS "System curl not found. Using vendored curl.")
242+
if(curl_SOURCE_DIR)
243+
set(CURL_STATIC_LIBRARY_TARGET libcurl_static)
244+
281245
set(CURL_VENDORED TRUE)
246+
set_target_properties(${CURL_STATIC_LIBRARY_TARGET}
247+
PROPERTIES OUTPUT_NAME "iceberg_vendored_curl"
248+
POSITION_INDEPENDENT_CODE ON)
282249

283-
# The curl CMake build creates the 'curl-library' target for the static library.
284-
if(TARGET curl-library)
285-
set_target_properties(curl-library
286-
PROPERTIES OUTPUT_NAME "iceberg_vendored_curl"
287-
# Ensure PIC is set on the target itself for robustness
288-
POSITION_INDEPENDENT_CODE ON)
289-
install(TARGETS curl-library
290-
EXPORT iceberg_targets
291-
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
292-
endif()
250+
install(TARGETS ${CURL_STATIC_LIBRARY_TARGET}
251+
EXPORT iceberg_targets
252+
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
293253
else()
294-
message(STATUS "Found and using system curl.")
295254
set(CURL_VENDORED FALSE)
296255
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES CURL)
297256
endif()
298257

299-
set(CURL_VENDORED
300-
${CURL_VENDORED}
301-
PARENT_SCOPE)
302258
set(ICEBERG_SYSTEM_DEPENDENCIES
303259
${ICEBERG_SYSTEM_DEPENDENCIES}
304260
PARENT_SCOPE)
261+
set(CURL_VENDORED
262+
${CURL_VENDORED}
263+
PARENT_SCOPE)
305264
endfunction()
306265

307266
# ----------------------------------------------------------------------
308267
# cpr (C++ Requests)
309268

310269
function(resolve_cpr_dependency)
311-
# First, ensure the curl dependency is resolved
312-
resolve_curl_dependency()
313-
314270
prepare_fetchcontent()
315271

316-
# Always tell cpr to find an external curl. Our resolve_curl_dependency()
317-
# function has guaranteed that one is available, either from the system
318-
# or by building it from source.
319-
set(CPR_USE_SYSTEM_CURL
320-
ON
321-
CACHE BOOL "" FORCE)
322-
323272
set(CPR_BUILD_TESTS
324273
OFF
325274
CACHE BOOL "" FORCE)
326-
set(CPR_BUILD_STATIC
327-
ON
328-
CACHE BOOL "" FORCE)
329-
set(CPR_FORCE_USE_PIC
330-
ON
331-
CACHE BOOL "" FORCE)
332-
set(CPR_USE_SYSTEM_LIB_PSL
275+
set(CPR_USE_SYSTEM_CURL
333276
ON
334277
CACHE BOOL "" FORCE)
335278

336279
fetchcontent_declare(cpr
337280
${FC_DECLARE_COMMON_OPTIONS}
338281
GIT_REPOSITORY https://github.com/libcpr/cpr.git
339-
GIT_TAG "1.11.0")
282+
GIT_TAG bb01c8db702fb41e5497aee9c0559ddf4bf13749 # Version 1.11.0
283+
FIND_PACKAGE_ARGS
284+
NAMES
285+
cpr
286+
CONFIG)
340287

341288
fetchcontent_makeavailable(cpr)
342289

343290
if(cpr_SOURCE_DIR)
344-
set(CPR_VENDORED TRUE) # cpr itself is always vendored by our project
291+
292+
if(NOT TARGET cpr::cpr)
293+
add_library(cpr::cpr ALIAS cpr)
294+
endif()
295+
296+
set(CPR_VENDORED TRUE)
297+
345298
set_target_properties(cpr PROPERTIES OUTPUT_NAME "iceberg_vendored_cpr"
346299
POSITION_INDEPENDENT_CODE ON)
347-
348300
install(TARGETS cpr
349301
EXPORT iceberg_targets
350302
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
351303
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
352304
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
353305
else()
354-
# This branch is unlikely to be hit if the git repo is available,
355-
# but is kept for completeness.
356306
set(CPR_VENDORED FALSE)
357307
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES cpr)
358308
endif()
359309

360-
set(CPR_VENDORED
361-
${CPR_VENDORED}
362-
PARENT_SCOPE)
363-
# Propagate the system dependencies list, which was modified by resolve_curl_dependency
364310
set(ICEBERG_SYSTEM_DEPENDENCIES
365311
${ICEBERG_SYSTEM_DEPENDENCIES}
366312
PARENT_SCOPE)
313+
set(CPR_VENDORED
314+
${CPR_VENDORED}
315+
PARENT_SCOPE)
367316
endfunction()
368317

369318
# ----------------------------------------------------------------------
@@ -560,5 +509,6 @@ if(ICEBERG_BUILD_BUNDLE)
560509
endif()
561510

562511
if(ICEBERG_BUILD_REST_CATALOG)
512+
resolve_curl_dependency()
563513
resolve_cpr_dependency()
564514
endif()

0 commit comments

Comments
 (0)