From edfeabe4cefbec2ba3697e41664e76f8bfcee52c Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Thu, 6 Mar 2025 01:37:32 +0800 Subject: [PATCH] Add link directory to support curl 8.12 (#3272) --- exporters/otlp/CMakeLists.txt | 8 ++++++-- ext/src/http/client/curl/CMakeLists.txt | 26 +++++++++++++++++++++++-- ext/test/http/CMakeLists.txt | 15 ++++++++++++-- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index bf0ae1f35b..bccc15a8f8 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -119,8 +119,12 @@ if(WITH_OTLP_HTTP) target_link_libraries( opentelemetry_exporter_otlp_http_client PUBLIC opentelemetry_sdk opentelemetry_ext - PRIVATE opentelemetry_proto opentelemetry_http_client_curl - nlohmann_json::nlohmann_json) + # Links flags of opentelemetry_http_client_curl should be public when + # building internal components + PRIVATE opentelemetry_proto + "$" + nlohmann_json::nlohmann_json + "$") if(TARGET absl::strings) target_link_libraries(opentelemetry_exporter_otlp_http_client PUBLIC absl::strings) diff --git a/ext/src/http/client/curl/CMakeLists.txt b/ext/src/http/client/curl/CMakeLists.txt index c812fcefbf..ead02699b0 100644 --- a/ext/src/http/client/curl/CMakeLists.txt +++ b/ext/src/http/client/curl/CMakeLists.txt @@ -10,11 +10,33 @@ set_target_properties(opentelemetry_http_client_curl set_target_version(opentelemetry_http_client_curl) target_link_libraries(opentelemetry_http_client_curl PUBLIC opentelemetry_common) -if(TARGET CURL::libcurl) + +unset(CURL_IMPORTED_TARGET_NAME) + +foreach(FIND_CURL_IMPORTED_TARGET CURL::libcurl CURL::libcurl_shared + CURL::libcurl_static) + if(TARGET ${FIND_CURL_IMPORTED_TARGET}) + set(CURL_IMPORTED_TARGET_NAME ${FIND_CURL_IMPORTED_TARGET}) + break() + endif() +endforeach() + +if(TARGET ${CURL_IMPORTED_TARGET_NAME}) target_link_libraries( opentelemetry_http_client_curl PUBLIC opentelemetry_ext - PRIVATE CURL::libcurl) + PRIVATE ${CURL_IMPORTED_TARGET_NAME}) + + # Some versions of libcurl do not export the link directories, which may cause + # link errors + project_build_tools_get_imported_location(CURL_LIB_FILE_PATH + ${CURL_IMPORTED_TARGET_NAME}) + get_filename_component(CURL_LIB_DIR_PATH "${CURL_LIB_FILE_PATH}" DIRECTORY) + + if(CURL_LIB_DIR_PATH) + target_link_directories(opentelemetry_http_client_curl PUBLIC + "$") + endif() else() target_include_directories(opentelemetry_http_client_curl INTERFACE "${CURL_INCLUDE_DIRS}") diff --git a/ext/test/http/CMakeLists.txt b/ext/test/http/CMakeLists.txt index 9f5514d07b..51e0996eda 100644 --- a/ext/test/http/CMakeLists.txt +++ b/ext/test/http/CMakeLists.txt @@ -8,14 +8,25 @@ if(WITH_HTTP_CLIENT_CURL) target_link_libraries(${FILENAME} ${GMOCK_LIB} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) - if(TARGET CURL::libcurl) + unset(CURL_IMPORTED_TARGET_NAME) + + foreach(FIND_CURL_IMPORTED_TARGET CURL::libcurl CURL::libcurl_shared + CURL::libcurl_static) + if(TARGET ${FIND_CURL_IMPORTED_TARGET}) + set(CURL_IMPORTED_TARGET_NAME ${FIND_CURL_IMPORTED_TARGET}) + break() + endif() + endforeach() + + if(TARGET ${CURL_IMPORTED_TARGET_NAME}) target_link_libraries(${FILENAME} opentelemetry_http_client_curl - opentelemetry_common CURL::libcurl) + opentelemetry_common ${CURL_IMPORTED_TARGET_NAME}) else() include_directories(${CURL_INCLUDE_DIRS}) target_link_libraries(${FILENAME} ${CURL_LIBRARIES} opentelemetry_http_client_curl opentelemetry_common) endif() + gtest_add_tests( TARGET ${FILENAME} TEST_PREFIX ext.http.curl.