Skip to content

Commit

Permalink
(#13597) zlib: fix lib name on windows for other compilers than msvc/…
Browse files Browse the repository at this point in the history
…clang-cl/mingw

* fix lib name on windows if not cl like or mingw

* modernize a little bit more
  • Loading branch information
SpaceIm authored Oct 19, 2022
1 parent ca6b7e7 commit 5253b77
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
27 changes: 14 additions & 13 deletions recipes/zlib/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, get, load, replace_in_file, save
from conan.tools.microsoft import is_msvc
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, load, replace_in_file, save
from conan.tools.scm import Version
import os

required_conan_version = ">=1.49.0"
required_conan_version = ">=1.52.0"


class ZlibConan(ConanFile):
Expand All @@ -28,28 +27,30 @@ class ZlibConan(ConanFile):
}

@property
def _is_clang_cl(self):
return self.settings.os == "Windows" and self.settings.compiler == "clang"
def _is_mingw(self):
return self.settings.os == "Windows" and self.settings.compiler == "gcc"

def export_sources(self):
for p in self.conan_data.get("patches", {}).get(self.version, []):
copy(self, p["patch_file"], self.recipe_folder, self.export_sources_folder)
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
try:
del self.options.fPIC
except Exception:
pass
try:
del self.settings.compiler.libcxx
del self.settings.compiler.libcxx
except Exception:
pass
pass
try:
del self.settings.compiler.cppstd
del self.settings.compiler.cppstd
except Exception:
pass
pass

def layout(self):
cmake_layout(self, src_folder="src")
Expand Down Expand Up @@ -103,7 +104,7 @@ def package_info(self):
self.cpp_info.set_property("cmake_file_name", "ZLIB")
self.cpp_info.set_property("cmake_target_name", "ZLIB::ZLIB")
self.cpp_info.set_property("pkg_config_name", "zlib")
if is_msvc(self) or self._is_clang_cl:
if self.settings.os == "Windows" and not self._is_mingw:
libname = "zdll" if self.options.shared else "zlib"
else:
libname = "z"
Expand Down
2 changes: 1 addition & 1 deletion recipes/zlib/all/patches/1.2.13/0001-Fix-cmake.patch
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ index b412dc7..a5284ed 100644
endif()

-if(UNIX)
+if(MSVC)
+if(WIN32 AND NOT MINGW)
+ if(BUILD_SHARED_LIBS)
+ set_target_properties(zlib PROPERTIES ARCHIVE_OUTPUT_NAME zdll)
+ endif()
Expand Down
2 changes: 1 addition & 1 deletion recipes/zlib/all/patches/1.2.x/0001-fix-cmake.patch
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
endif()

-if(UNIX)
+if(MSVC)
+if(WIN32 AND NOT MINGW)
+ if(BUILD_SHARED_LIBS)
+ set_target_properties(zlib PROPERTIES ARCHIVE_OUTPUT_NAME zdll)
+ endif()
Expand Down
7 changes: 4 additions & 3 deletions recipes/zlib/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"

def requirements(self):
self.requires(self.tested_reference_str)
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
Expand Down

0 comments on commit 5253b77

Please sign in to comment.