1+ class ConanFile :
2+ pass
3+
4+ required_conan_version = ">=1.53.0"
5+
6+
7+ class ZlibConan (ConanFile ):
8+ name = "zlib"
9+ package_type = "library"
10+ url = "https://github.com/conan-io/conan-center-index"
11+ homepage = "https://zlib.net"
12+ license = "Zlib"
13+ description = ("A Massively Spiffy Yet Delicately Unobtrusive Compression Library "
14+ "(Also Free, Not to Mention Unencumbered by Patents)" )
15+ topics = ("zlib" , "compression" )
16+
17+ settings = "os" , "arch" , "compiler" , "build_type"
18+ options = {
19+ "shared" : [True , False ],
20+ "fPIC" : [True , False ],
21+ }
22+ default_options = {
23+ "shared" : False ,
24+ "fPIC" : True ,
25+ }
26+
27+ @property
28+ def _is_mingw (self ):
29+ return self .settings .os == "Windows" and self .settings .compiler == "gcc"
30+
31+ def export_sources (self ):
32+ export_conandata_patches (self )
33+
34+ def config_options (self ):
35+ if self .settings .os == "Windows" :
36+ del self .options .fPIC
37+
38+ def configure (self ):
39+ if self .options .shared :
40+ self .options .rm_safe ("fPIC" )
41+ self .settings .rm_safe ("compiler.libcxx" )
42+ self .settings .rm_safe ("compiler.cppstd" )
43+
44+ def layout (self ):
45+ cmake_layout (self , src_folder = "src" )
46+
47+ def source (self ):
48+ get (self , ** self .conan_data ["sources" ][self .version ],
49+ destination = self .source_folder , strip_root = True )
50+
51+ def generate (self ):
52+ tc = CMakeToolchain (self )
53+ tc .variables ["SKIP_INSTALL_ALL" ] = False
54+ tc .variables ["SKIP_INSTALL_LIBRARIES" ] = False
55+ tc .variables ["SKIP_INSTALL_HEADERS" ] = False
56+ tc .variables ["SKIP_INSTALL_FILES" ] = True
57+ # Correct for misuse of "${CMAKE_INSTALL_PREFIX}/" in CMakeLists.txt
58+ tc .variables ["INSTALL_LIB_DIR" ] = "lib"
59+ tc .variables ["INSTALL_INC_DIR" ] = "include"
60+ tc .variables ["ZLIB_BUILD_EXAMPLES" ] = False
61+ tc .generate ()
62+
63+ def _patch_sources (self ):
64+ apply_conandata_patches (self )
65+
66+ is_apple_clang12 = self .settings .compiler == "apple-clang" and Version (self .settings .compiler .version ) >= "12.0"
67+ if not is_apple_clang12 :
68+ for filename in ['zconf.h' , 'zconf.h.cmakein' , 'zconf.h.in' ]:
69+ filepath = os .path .join (self .source_folder , filename )
70+ replace_in_file (self , filepath ,
71+ '#ifdef HAVE_UNISTD_H '
72+ '/* may be set to #if 1 by ./configure */' ,
73+ '#if defined(HAVE_UNISTD_H) && (1-HAVE_UNISTD_H-1 != 0)' )
74+ replace_in_file (self , filepath ,
75+ '#ifdef HAVE_STDARG_H '
76+ '/* may be set to #if 1 by ./configure */' ,
77+ '#if defined(HAVE_STDARG_H) && (1-HAVE_STDARG_H-1 != 0)' )
78+
79+ def build (self ):
80+ self ._patch_sources ()
81+ cmake = CMake (self )
82+ cmake .configure ()
83+ cmake .build ()
84+
85+ def _extract_license (self ):
86+ tmp = load (self , os .path .join (self .source_folder , "zlib.h" ))
87+ license_contents = tmp [2 :tmp .find ("*/" , 1 )]
88+ return license_contents
89+
90+ def package (self ):
91+ save (self , os .path .join (self .package_folder , "licenses" , "LICENSE" ), self ._extract_license ())
92+ cmake = CMake (self )
93+ cmake .install ()
94+
95+ def package_info (self ):
96+ self .cpp_info .set_property ("cmake_find_mode" , "both" )
97+ self .cpp_info .set_property ("cmake_file_name" , "ZLIB" )
98+ self .cpp_info .set_property ("cmake_target_name" , "ZLIB::ZLIB" )
99+ self .cpp_info .set_property ("pkg_config_name" , "zlib" )
100+ if self .settings .os == "Windows" and not self ._is_mingw :
101+ libname = "zdll" if self .options .shared else "zlib"
102+ else :
103+ libname = "z"
104+ self .cpp_info .libs = [libname ]
105+
106+ self .cpp_info .names ["cmake_find_package" ] = "ZLIB"
107+ self .cpp_info .names ["cmake_find_package_multi" ] = "ZLIB"
0 commit comments