1
- from conan import ConanFile , Version
2
- from conan .tools .files import apply_conandata_patches , copy , export_conandata_patches , get , rm , rmdir
3
- from conan .tools .gnu import Autotools , AutotoolsToolchain , PkgConfigDeps
4
- from conan .tools .microsoft import MSBuild , MSBuildToolchain , is_msvc , vs_layout
5
- from conan .tools .layout import basic_layout
1
+ from conan import ConanFile
6
2
from conan .errors import ConanInvalidConfiguration
3
+ from conan .tools .apple import fix_apple_shared_install_name
4
+ from conan .tools .build import cross_building
5
+ from conan .tools .env import VirtualBuildEnv , VirtualRunEnv
6
+ from conan .tools .files import apply_conandata_patches , copy , export_conandata_patches , get , replace_in_file , rm , rmdir
7
+ from conan .tools .gnu import Autotools , AutotoolsToolchain , AutotoolsDeps
8
+ from conan .tools .layout import basic_layout
9
+ from conan .tools .microsoft import is_msvc , MSBuild , MSBuildToolchain
7
10
import os
8
11
9
- required_conan_version = ">=1.52 .0"
12
+ required_conan_version = ">=1.54 .0"
10
13
11
14
12
15
class LibmicrohttpdConan (ConanFile ):
@@ -42,12 +45,13 @@ class LibmicrohttpdConan(ConanFile):
42
45
def _settings_build (self ):
43
46
return getattr (self , "settings_build" , self .settings )
44
47
48
+ def export_sources (self ):
49
+ export_conandata_patches (self )
50
+
45
51
def config_options (self ):
52
+ if self .settings .os == "Windows" :
53
+ del self .options .fPIC
46
54
if self .settings .os != "Linux" :
47
- try :
48
- del self .options .fPIC
49
- except Exception :
50
- pass
51
55
del self .options .epoll
52
56
if is_msvc (self ):
53
57
del self .options .with_https
@@ -58,62 +62,45 @@ def config_options(self):
58
62
59
63
def configure (self ):
60
64
if self .options .shared :
61
- try :
62
- del self .options .fPIC
63
- except Exception :
64
- pass
65
- try :
66
- del self .settings .compiler .libcxx
67
- except Exception :
68
- pass
69
- try :
70
- del self .settings .compiler .cppstd
71
- except Exception :
72
- pass
65
+ self .options .rm_safe ("fPIC" )
66
+ self .settings .rm_safe ("compiler.cppstd" )
67
+ self .settings .rm_safe ("compiler.libcxx" )
73
68
74
- def validate (self ):
75
- if is_msvc (self ):
76
- if self .info .settings .arch not in ("x86" , "x86_64" ):
77
- raise ConanInvalidConfiguration ("Unsupported architecture (only x86 and x86_64 are supported)" )
78
- if self .info .settings .build_type not in ("Release" , "Debug" ):
79
- raise ConanInvalidConfiguration ("Unsupported build type (only Release and Debug are supported)" )
69
+ def layout (self ):
70
+ basic_layout (self , src_folder = "src" )
80
71
81
72
def requirements (self ):
82
- if self .options .get_safe ("with_zlib" , False ):
73
+ if self .options .get_safe ("with_zlib" ):
83
74
self .requires ("zlib/1.2.13" )
84
- if self .options .get_safe ("with_https" , False ):
75
+
76
+ def validate (self ):
77
+ if is_msvc (self ) and self .settings .arch not in ("x86" , "x86_64" ):
78
+ raise ConanInvalidConfiguration ("Unsupported architecture (only x86 and x86_64 are supported)" )
79
+ if self .options .get_safe ("with_https" ):
85
80
raise ConanInvalidConfiguration ("gnutls is not (yet) available in cci" )
86
81
87
82
def build_requirements (self ):
88
83
if self ._settings_build .os == "Windows" and not is_msvc (self ):
89
84
self .win_bash = True
90
- if not self .conf .get ("tools.microsoft.bash:path" , default = False , check_type = str ):
85
+ if not self .conf .get ("tools.microsoft.bash:path" , check_type = str ):
91
86
self .tool_requires ("msys2/cci.latest" )
92
87
93
88
def source (self ):
94
- get (self , ** self .conan_data ["sources" ][self .version ],
95
- destination = self .source_folder , strip_root = True )
96
-
97
- def export_sources (self ):
98
- export_conandata_patches (self )
99
-
100
- def layout (self ):
101
- if is_msvc (self ):
102
- vs_layout (self )
103
- else :
104
- basic_layout (self )
89
+ get (self , ** self .conan_data ["sources" ][self .version ], strip_root = True )
105
90
106
91
def generate (self ):
107
92
if is_msvc (self ):
108
93
tc = MSBuildToolchain (self )
109
94
tc .configuration = self ._msvc_configuration
95
+ tc .properties ["WholeProgramOptimization" ] = "false"
110
96
tc .generate ()
111
97
else :
98
+ VirtualBuildEnv (self ).generate ()
99
+ if not cross_building (self ):
100
+ VirtualRunEnv (self ).generate (scope = "build" )
101
+ tc = AutotoolsToolchain (self )
112
102
yes_no = lambda v : "yes" if v else "no"
113
- pkg = PkgConfigDeps (self )
114
- pkg .generate ()
115
- autotools = AutotoolsToolchain (self )
116
- autotools .configure_args .extend ([
103
+ tc .configure_args .extend ([
117
104
f"--enable-shared={ yes_no (self .options .shared )} " ,
118
105
f"--enable-static={ yes_no (not self .options .shared )} " ,
119
106
f"--enable-https={ yes_no (self .options .with_https )} " ,
@@ -125,67 +112,67 @@ def generate(self):
125
112
"--disable-examples" ,
126
113
"--disable-curl" ,
127
114
])
128
- if self .settings .os == "Windows" :
129
- if self .options .with_zlib :
130
- # This fixes libtool refusing to build a shared library when it sees `-lz`
131
- libdir = self .deps_cpp_info ["zlib" ].lib_paths [0 ]
132
- autotools .extra_ldflags .extend ([os .path .join (libdir , lib ).replace ("\\ " , "/" ) for lib in os .listdir (libdir )])
133
- autotools .generate ()
115
+ tc .generate ()
116
+ AutotoolsDeps (self ).generate ()
134
117
135
118
@property
136
119
def _msvc_configuration (self ):
137
- return f"{ self .settings .build_type } -{ 'dll' if self .options .shared else 'static' } "
120
+ prefix = "Debug" if self .settings .build_type == "Debug" else "Release"
121
+ suffix = "dll" if self .options .shared else "static"
122
+ return f"{ prefix } -{ suffix } "
138
123
139
124
@property
140
125
def _msvc_sln_folder (self ):
141
- if self .settings .compiler == "Visual Studio" :
142
- if Version (self .settings .compiler .version ) >= 16 :
143
- subdir = "VS-Any-Version"
144
- else :
145
- subdir = "VS2017"
146
- else :
147
- subdir = "VS-Any-Version"
148
- return os .path .join ("w32" , subdir )
149
-
150
- @property
151
- def _msvc_platform (self ):
152
- return {
153
- "x86" : "Win32" ,
154
- "x86_64" : "x64" ,
155
- }[str (self .settings .arch )]
156
-
157
- def _patch_sources (self ):
158
- apply_conandata_patches (self )
126
+ # TODO: use VS-Any-Version folder once https://github.com/conan-io/conan/pull/12817 available in conan client
127
+ return os .path .join (self .source_folder , "w32" , "VS2022" )
159
128
160
129
def build (self ):
161
- self . _patch_sources ( )
130
+ apply_conandata_patches ( self )
162
131
if is_msvc (self ):
132
+ #==============================
133
+ # TODO: to remove once https://github.com/conan-io/conan/pull/12817 available in conan client
134
+ vcxproj_file = os .path .join (self ._msvc_sln_folder , "libmicrohttpd.vcxproj" )
135
+ replace_in_file (
136
+ self , vcxproj_file ,
137
+ "<WholeProgramOptimization Condition=\" ! $(Configuration.StartsWith('Debug'))\" >true</WholeProgramOptimization>" ,
138
+ "" ,
139
+ )
140
+ toolset = MSBuildToolchain (self ).toolset
141
+ replace_in_file (
142
+ self , vcxproj_file ,
143
+ "<PlatformToolset>v143</PlatformToolset>" ,
144
+ f"<PlatformToolset>{ toolset } </PlatformToolset>" ,
145
+ )
146
+ conantoolchain_props = os .path .join (self .generators_folder , MSBuildToolchain .filename )
147
+ replace_in_file (
148
+ self , vcxproj_file ,
149
+ "<Import Project=\" $(VCTargetsPath)\\ Microsoft.Cpp.targets\" />" ,
150
+ f"<Import Project=\" { conantoolchain_props } \" /><Import Project=\" $(VCTargetsPath)\\ Microsoft.Cpp.targets\" />" ,
151
+ )
152
+ #==============================
153
+
163
154
msbuild = MSBuild (self )
164
155
msbuild .build_type = self ._msvc_configuration
165
- msbuild .platform = self ._msvc_platform
156
+ msbuild .platform = "Win32" if self .settings . arch == "x86" else msbuild . platform
166
157
msbuild .build (sln = os .path .join (self ._msvc_sln_folder , "libmicrohttpd.sln" ), targets = ["libmicrohttpd" ])
167
158
else :
168
159
autotools = Autotools (self )
169
160
autotools .configure ()
170
161
autotools .make ()
171
162
172
163
def package (self ):
173
- copy (self , "COPYING" , os . path . join ( self .source_folder ), os .path .join (self .package_folder , "licenses" ))
164
+ copy (self , "COPYING" , src = self .source_folder , dst = os .path .join (self .package_folder , "licenses" ))
174
165
if is_msvc (self ):
175
- # 32-bit (x86) libraries are stored in the root
176
- output_dir = os .path .join (self .build_folder , self ._msvc_sln_folder , "Output" )
177
- if self .settings .arch in ("x86_64" , ):
178
- # 64-bit (x64) libraries are stored in a subfolder
179
- output_dir = os .path .join (output_dir , self ._msvc_platform )
180
- copy (self , "*.lib" , output_dir , os .path .join (self .package_folder , "lib" ))
181
- copy (self , "*.dll" , output_dir , os .path .join (self .package_folder , "bin" ))
182
- copy (self , "*.h" , output_dir , os .path .join (self .package_folder , "include" ))
166
+ output_dir = os .path .join (self ._msvc_sln_folder , "Output" )
167
+ copy (self , "*.lib" , src = output_dir , dst = os .path .join (self .package_folder , "lib" ), keep_path = False )
168
+ copy (self , "*.dll" , src = output_dir , dst = os .path .join (self .package_folder , "bin" ), keep_path = False )
169
+ copy (self , "*.h" , src = output_dir , dst = os .path .join (self .package_folder , "include" ), keep_path = False )
183
170
else :
184
171
autotools = Autotools (self )
185
172
autotools .install ()
186
-
187
173
rm (self , "*.la" , os .path .join (self .package_folder , "lib" ))
188
174
rmdir (self , os .path .join (self .package_folder , "lib" , "pkgconfig" ))
175
+ fix_apple_shared_install_name (self )
189
176
190
177
def package_info (self ):
191
178
self .cpp_info .set_property ("pkg_config_name" , "libmicrohttps" )
0 commit comments