Skip to content

Commit edfeabe

Browse files
authored
Add link directory to support curl 8.12 (#3272)
1 parent 3c4afd0 commit edfeabe

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

exporters/otlp/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,12 @@ if(WITH_OTLP_HTTP)
119119
target_link_libraries(
120120
opentelemetry_exporter_otlp_http_client
121121
PUBLIC opentelemetry_sdk opentelemetry_ext
122-
PRIVATE opentelemetry_proto opentelemetry_http_client_curl
123-
nlohmann_json::nlohmann_json)
122+
# Links flags of opentelemetry_http_client_curl should be public when
123+
# building internal components
124+
PRIVATE opentelemetry_proto
125+
"$<BUILD_INTERFACE:opentelemetry_http_client_curl>"
126+
nlohmann_json::nlohmann_json
127+
"$<INSTALL_INTERFACE:opentelemetry_http_client_curl>")
124128
if(TARGET absl::strings)
125129
target_link_libraries(opentelemetry_exporter_otlp_http_client
126130
PUBLIC absl::strings)

ext/src/http/client/curl/CMakeLists.txt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,33 @@ set_target_properties(opentelemetry_http_client_curl
1010
set_target_version(opentelemetry_http_client_curl)
1111
target_link_libraries(opentelemetry_http_client_curl
1212
PUBLIC opentelemetry_common)
13-
if(TARGET CURL::libcurl)
13+
14+
unset(CURL_IMPORTED_TARGET_NAME)
15+
16+
foreach(FIND_CURL_IMPORTED_TARGET CURL::libcurl CURL::libcurl_shared
17+
CURL::libcurl_static)
18+
if(TARGET ${FIND_CURL_IMPORTED_TARGET})
19+
set(CURL_IMPORTED_TARGET_NAME ${FIND_CURL_IMPORTED_TARGET})
20+
break()
21+
endif()
22+
endforeach()
23+
24+
if(TARGET ${CURL_IMPORTED_TARGET_NAME})
1425
target_link_libraries(
1526
opentelemetry_http_client_curl
1627
PUBLIC opentelemetry_ext
17-
PRIVATE CURL::libcurl)
28+
PRIVATE ${CURL_IMPORTED_TARGET_NAME})
29+
30+
# Some versions of libcurl do not export the link directories, which may cause
31+
# link errors
32+
project_build_tools_get_imported_location(CURL_LIB_FILE_PATH
33+
${CURL_IMPORTED_TARGET_NAME})
34+
get_filename_component(CURL_LIB_DIR_PATH "${CURL_LIB_FILE_PATH}" DIRECTORY)
35+
36+
if(CURL_LIB_DIR_PATH)
37+
target_link_directories(opentelemetry_http_client_curl PUBLIC
38+
"$<BUILD_INTERFACE:${CURL_LIB_DIR_PATH}>")
39+
endif()
1840
else()
1941
target_include_directories(opentelemetry_http_client_curl
2042
INTERFACE "${CURL_INCLUDE_DIRS}")

ext/test/http/CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,25 @@ if(WITH_HTTP_CLIENT_CURL)
88
target_link_libraries(${FILENAME} ${GMOCK_LIB} ${GTEST_BOTH_LIBRARIES}
99
${CMAKE_THREAD_LIBS_INIT})
1010

11-
if(TARGET CURL::libcurl)
11+
unset(CURL_IMPORTED_TARGET_NAME)
12+
13+
foreach(FIND_CURL_IMPORTED_TARGET CURL::libcurl CURL::libcurl_shared
14+
CURL::libcurl_static)
15+
if(TARGET ${FIND_CURL_IMPORTED_TARGET})
16+
set(CURL_IMPORTED_TARGET_NAME ${FIND_CURL_IMPORTED_TARGET})
17+
break()
18+
endif()
19+
endforeach()
20+
21+
if(TARGET ${CURL_IMPORTED_TARGET_NAME})
1222
target_link_libraries(${FILENAME} opentelemetry_http_client_curl
13-
opentelemetry_common CURL::libcurl)
23+
opentelemetry_common ${CURL_IMPORTED_TARGET_NAME})
1424
else()
1525
include_directories(${CURL_INCLUDE_DIRS})
1626
target_link_libraries(${FILENAME} ${CURL_LIBRARIES}
1727
opentelemetry_http_client_curl opentelemetry_common)
1828
endif()
29+
1930
gtest_add_tests(
2031
TARGET ${FILENAME}
2132
TEST_PREFIX ext.http.curl.

0 commit comments

Comments
 (0)