cmake: fix potential curl linking problems

Signed-off-by: Konstantin Podshumok <kpp.live+signed@gmail.com>
This commit is contained in:
Konstantin Podshumok 2020-08-22 01:20:18 +03:00
parent 68a921cdea
commit e296997b6c
No known key found for this signature in database
GPG Key ID: 7EA5D4784D5BB847
3 changed files with 208 additions and 191 deletions

View File

@ -413,6 +413,7 @@ include (cmake/find/grpc.cmake)
include (cmake/find/pdqsort.cmake) include (cmake/find/pdqsort.cmake)
include (cmake/find/hdfs3.cmake) # uses protobuf include (cmake/find/hdfs3.cmake) # uses protobuf
include (cmake/find/poco.cmake) include (cmake/find/poco.cmake)
include (cmake/find/curl.cmake)
include (cmake/find/s3.cmake) include (cmake/find/s3.cmake)
include (cmake/find/base64.cmake) include (cmake/find/base64.cmake)
include (cmake/find/parquet.cmake) include (cmake/find/parquet.cmake)

37
cmake/find/curl.cmake Normal file
View File

@ -0,0 +1,37 @@
option (ENABLE_CURL "Enable curl" ${ENABLE_LIBRARIES})
if (NOT ENABLE_CURL)
if (USE_INTERNAL_CURL)
message (${RECONFIGURE_MESSAGE_LEVEL} "Can't use internal curl with ENABLE_CURL=OFF")
endif()
return()
endif()
option (USE_INTERNAL_CURL "Use internal curl library" ${NOT_UNBUNDLED})
if (NOT USE_INTERNAL_CURL)
find_package (CURL)
if (NOT CURL_FOUND)
message (${RECONFIGURE_MESSAGE_LEVEL} "Can't find system curl")
endif()
endif()
if (NOT CURL_FOUND)
set (USE_INTERNAL_CURL 1)
set (CURL_LIBRARY_DIR "${ClickHouse_SOURCE_DIR}/contrib/curl")
# find_package(CURL) compatibility for the following packages that uses
# find_package(CURL)/include(FindCURL):
# - mariadb-connector-c
# - aws-s3-cmake
# - sentry-native
set (CURL_FOUND ON CACHE BOOL "")
set (CURL_ROOT_DIR ${CURL_LIBRARY_DIR} CACHE PATH "")
set (CURL_INCLUDE_DIR ${CURL_LIBRARY_DIR}/include CACHE PATH "")
set (CURL_INCLUDE_DIRS ${CURL_LIBRARY_DIR}/include CACHE PATH "")
set (CURL_LIBRARY curl CACHE STRING "")
set (CURL_LIBRARIES ${CURL_LIBRARY} CACHE STRING "")
set (CURL_VERSION_STRING 7.67.0 CACHE STRING "")
endif ()
message (STATUS "Using curl: ${CURL_INCLUDE_DIRS} : ${CURL_LIBRARIES}")

View File

@ -1,26 +1,10 @@
option (ENABLE_CURL "Enable curl" ${ENABLE_LIBRARIES}) if (NOT USE_INTERNAL_CURL)
if (NOT ENABLE_CURL)
if (USE_INTERNAL_CURL)
message (${RECONFIGURE_MESSAGE_LEVEL} "Can't use internal curl with ENABLE_CURL=OFF")
endif()
return() return()
endif() endif()
option (USE_INTERNAL_CURL "Use internal curl library" ${NOT_UNBUNDLED}) set (LIBRARY_DIR "${ClickHouse_SOURCE_DIR}/contrib/curl")
if (NOT USE_INTERNAL_CURL) set (SRCS
find_package (CURL)
if (NOT CURL_FOUND)
message (${RECONFIGURE_MESSAGE_LEVEL} "Can't find system curl")
endif()
endif()
if (NOT CURL_FOUND)
set (USE_INTERNAL_CURL 1)
set (LIBRARY_DIR "${ClickHouse_SOURCE_DIR}/contrib/curl")
set (SRCS
${LIBRARY_DIR}/lib/file.c ${LIBRARY_DIR}/lib/file.c
${LIBRARY_DIR}/lib/timeval.c ${LIBRARY_DIR}/lib/timeval.c
${LIBRARY_DIR}/lib/base64.c ${LIBRARY_DIR}/lib/base64.c
@ -158,43 +142,38 @@ if (NOT CURL_FOUND)
${LIBRARY_DIR}/lib/vquic/quiche.c ${LIBRARY_DIR}/lib/vquic/quiche.c
${LIBRARY_DIR}/lib/vssh/libssh2.c ${LIBRARY_DIR}/lib/vssh/libssh2.c
${LIBRARY_DIR}/lib/vssh/libssh.c ${LIBRARY_DIR}/lib/vssh/libssh.c
) )
add_library (curl ${SRCS}) add_library (curl ${SRCS})
target_compile_definitions (curl PRIVATE target_compile_definitions (curl PRIVATE
HAVE_CONFIG_H HAVE_CONFIG_H
BUILDING_LIBCURL BUILDING_LIBCURL
CURL_HIDDEN_SYMBOLS CURL_HIDDEN_SYMBOLS
libcurl_EXPORTS libcurl_EXPORTS
OS="${CMAKE_SYSTEM_NAME}" OS="${CMAKE_SYSTEM_NAME}"
) )
target_include_directories (curl PUBLIC target_include_directories (curl PUBLIC
${LIBRARY_DIR}/include ${LIBRARY_DIR}/include
${LIBRARY_DIR}/lib ${LIBRARY_DIR}/lib
. # curl_config.h . # curl_config.h
) )
target_link_libraries (curl PRIVATE ssl) target_link_libraries (curl PRIVATE ssl)
# The library is large - avoid bloat (XXX: is it?) # The library is large - avoid bloat (XXX: is it?)
target_compile_options (curl PRIVATE -g0) target_compile_options (curl PRIVATE -g0)
# find_package(CURL) compatibility for the following packages that uses # find_package(CURL) compatibility for the following packages that uses
# find_package(CURL)/include(FindCURL): # find_package(CURL)/include(FindCURL):
# - mariadb-connector-c # - mariadb-connector-c
# - aws-s3-cmake # - aws-s3-cmake
# - sentry-native # - sentry-native
set (CURL_FOUND ON CACHE BOOL "") set (CURL_FOUND ON CACHE BOOL "")
set (CURL_ROOT_DIR ${LIBRARY_DIR} CACHE PATH "") set (CURL_ROOT_DIR ${LIBRARY_DIR} CACHE PATH "")
set (CURL_INCLUDE_DIR ${LIBRARY_DIR}/include CACHE PATH "") set (CURL_INCLUDE_DIR ${LIBRARY_DIR}/include CACHE PATH "")
set (CURL_INCLUDE_DIRS ${LIBRARY_DIR}/include CACHE PATH "") set (CURL_INCLUDE_DIRS ${LIBRARY_DIR}/include CACHE PATH "")
set (CURL_LIBRARY curl CACHE STRING "") set (CURL_LIBRARY curl CACHE STRING "")
set (CURL_LIBRARIES ${CURL_LIBRARY} CACHE STRING "") set (CURL_LIBRARIES ${CURL_LIBRARY} CACHE STRING "")
set (CURL_VERSION_STRING 7.67.0 CACHE STRING "") set (CURL_VERSION_STRING 7.67.0 CACHE STRING "")
add_library (CURL::libcurl ALIAS ${CURL_LIBRARY}) add_library (CURL::libcurl ALIAS ${CURL_LIBRARY})
set (USE_INTERNAL_CURL 1)
endif ()
message (STATUS "Using curl: ${CURL_INCLUDE_DIRS} : ${CURL_LIBRARIES}")