Skip to content

CMake FetchContent with ZLIB fails (>=8.0.0) #11285

@gvne

Description

@gvne

I did this

Include curl with zlib support in my CMake project using FetchContent.
Minimal CMakeLists.txt:

cmake_minimum_required(VERSION 3.25)

project(test)

include(FetchContent)
FetchContent_Declare(zlib
  GIT_REPOSITORY https://github.com/madler/zlib.git
  GIT_TAG v1.2.13
)
FetchContent_MakeAvailable(zlib)
set(ZLIB_INCLUDE_DIRS ${zlib_SOURCE_DIR})
set(ZLIB_LIBRARY zlibstatic CACHE STRING "")
set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
set(ZLIB_FOUND 1)
add_library(ZLIB::ZLIB ALIAS zlibstatic)  # required for CMake > 3.4

FetchContent_Declare(curl
  URL https://github.com/curl/curl/releases/download/curl-8_1_2/curl-8.1.2.tar.xz
)
FetchContent_MakeAvailable(curl)

I expected the following

The CMake configuration to run smoothly

curl/libcurl version

8.1.2 (Issue started with 8.0.0)

operating system

Linux pop-os 6.2.6-76060206-generic #202303130630168375320722.04~77c1465 SMP PREEMPT_DYNAMIC Wed M x86_64 x86_64 x86_64 GNU/Linux

What I get

When configuring, I get the following error:

[cmake] -- Looking for idn2_lookup_ul in idn2;OpenSSL::SSL;OpenSSL::Crypto;ZLIB::ZLIB
[cmake] CMake Error at build/CMakeFiles/CMakeScratch/TryCompile-2M2kVT/CMakeLists.txt:25 (target_link_libraries):
[cmake]   Target "cmTC_70ab4" links to:
[cmake] 
[cmake]     ZLIB::ZLIB
[cmake] 
[cmake]   but the target was not found.  Possible reasons include:
[cmake] 
[cmake]     * There is a typo in the target name.
[cmake]     * A find_package call is missing for an IMPORTED target.
[cmake]     * An ALIAS target is missing.

When digging a little, I found something I don't understand in the CMake macro check_library_exists_concat

Do we need to concatenate the searched library with the current state of the CURL_LIBS variable when running the check_library_exists ?
Removing it fixes my issue.

Thanks !

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions