-
Notifications
You must be signed in to change notification settings - Fork 947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libcpr fails to build on Windows because zlib isn't found #1085
Comments
libcpr has had some weird linking problem with zlib for as long as I remember but it seems that's a blocking problem on windows, rather than a warning like it on on Linux This is a workaround until this issue is fixed: libcpr/cpr#1085
@LunarWatcher confirmed. Thanks for reporting! |
I ran into a variant of this problem independently with liblzma in a different project. That patch was more complex because libarchive overrides the diff --git a/CMakeLists.txt b/CMakeLists.txt
index 66a064b..0b9adaf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -205,7 +205,7 @@ else()
# -DCURL_ZLIB=OFF
# * from CMake script:
if (CURL_ZLIB OR CURL_ZLIB STREQUAL AUTO OR NOT DEFINED CACHE{CURL_ZLIB})
- include(cmake/zlib_external.cmake)
+ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/zlib")
endif()
if (CPR_ENABLE_CURL_HTTP_ONLY)
diff --git a/cmake/zlib_external.cmake b/cmake/zlib/FindZLIB.cmake
similarity index 74%
rename from cmake/zlib_external.cmake
rename to cmake/zlib/FindZLIB.cmake
index 1a8eea0..e2f389f 100644
--- a/cmake/zlib_external.cmake
+++ b/cmake/zlib/FindZLIB.cmake
@@ -20,3 +20,13 @@ if(WIN32 AND BUILD_SHARED_LIBS)
set_target_properties(zlib PROPERTIES DEBUG_POSTFIX "")
set_target_properties(zlib PROPERTIES SUFFIX ".dll")
endif()
+
+# Required to force in a CMake >3.4-compatible ZLIB::ZLIB target
+add_library(ZLIB::ZLIB ALIAS zlib)
+
+# Required for compatibility with the built-in FindZLIB
+set(ZLIB_FOUND TRUE)
+set(ZLIB_INCLUDE_DIRS ${zlib_SOURCE_DIR})
+set(ZLIB_LIBRARY zlib)
+set(ZLIB_LIBARARIES ${ZLIB_LIBARY})
+
Note that the subfolder isn't required, it was just a quick hack to avoid forcing an external zlib on dependencies by scoping it outside the default Unfortunately, it doesn't work because
A couple very quick tries with a separate This does make it correctly find the targets at least. Compiling is still blocked by install() |
Description
When building with
CURL_ZLIB=ON
, curl fails to build:This is in spite of zlib being correctly sourced: by
external_zlib.cmake
I'm not familiar with the inner workings of find_package, but I'd assume this is related to how it uses a CMake module for finding zlib rather than using the target generated by zlib-ng.
Example/How to Reproduce
-DCURL_ZLIB=ON
Possible Fix
No response
Where did you get it from?
GitHub (branch e.g. master)
Additional Context/Your Environment
Also verified with GitHub Actions, but not in a clean build of just libcpr
The text was updated successfully, but these errors were encountered: