Skip to content

Commit

Permalink
cmake: don't include non-IMPORTED ZLIB target in check_library_exists.
Browse files Browse the repository at this point in the history
check_library_exists/concat does not work well with non-imported targets. ZLIB
might not be an imported target if it is included in a parent cmake project
before including curl.
  • Loading branch information
nmoinvaz committed Aug 10, 2023
1 parent abd8f2b commit 158aca7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Expand Up @@ -175,6 +175,7 @@ endif()

# initialize CURL_LIBS
set(CURL_LIBS "")
set(CURL_DEPS "")

if(ENABLE_ARES)
set(USE_ARES 1)
Expand Down Expand Up @@ -525,7 +526,12 @@ if(ZLIB_FOUND)
# version of CMake. This allows our dependents to get our dependencies
# transitively.
if(NOT CMAKE_VERSION VERSION_LESS 3.4)
list(APPEND CURL_LIBS ZLIB::ZLIB)
get_target_property(_imported ZLIB::ZLIB IMPORTED)
if(_imported)
list(APPEND CURL_LIBS ZLIB::ZLIB)
else()
list(APPEND CURL_DEPS ZLIB::ZLIB)
endif()
else()
list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
include_directories(${ZLIB_INCLUDE_DIRS})
Expand Down
2 changes: 1 addition & 1 deletion lib/CMakeLists.txt
Expand Up @@ -60,7 +60,7 @@ if(ENABLE_CURLDEBUG)
# being applied to memdebug.c itself.
set_source_files_properties(memdebug.c PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
endif()
target_link_libraries(curlu PRIVATE ${CURL_LIBS})
target_link_libraries(curlu PRIVATE ${CURL_LIBS} ${CURL_DEPS})

transform_makefile_inc("Makefile.soname" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.soname.cmake")
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.soname.cmake)
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Expand Up @@ -107,7 +107,7 @@ include_directories(
)

#Build curl executable
target_link_libraries(${EXE_NAME} ${LIB_SELECTED_FOR_EXE} ${CURL_LIBS})
target_link_libraries(${EXE_NAME} ${LIB_SELECTED_FOR_EXE} ${CURL_LIBS} ${CURL_DEPS})

################################################################################

Expand Down
2 changes: 1 addition & 1 deletion tests/libtest/CMakeLists.txt
Expand Up @@ -44,7 +44,7 @@ function(setup_test TEST_NAME) # ARGN are the files in the test
include_directories(${CARES_INCLUDE_DIR})
endif()

target_link_libraries(${TEST_NAME} ${LIB_SELECTED} ${CURL_LIBS})
target_link_libraries(${TEST_NAME} ${LIB_SELECTED} ${CURL_LIBS} ${CURL_DEPS})

set_target_properties(${TEST_NAME}
PROPERTIES COMPILE_DEFINITIONS ${UPPER_TEST_NAME})
Expand Down
2 changes: 1 addition & 1 deletion tests/server/CMakeLists.txt
Expand Up @@ -42,7 +42,7 @@ function(SETUP_EXECUTABLE TEST_NAME) # ARGN are the files in the test
include_directories(${CARES_INCLUDE_DIR})
endif()

target_link_libraries(${TEST_NAME} ${CURL_LIBS})
target_link_libraries(${TEST_NAME} ${CURL_LIBS} ${CURL_DEPS})

# Test servers simply are standalone programs that do not use libcurl
# library. For convenience and to ease portability of these servers,
Expand Down

0 comments on commit 158aca7

Please sign in to comment.