1
1
from conan import ConanFile
2
- from conan .errors import ConanInvalidConfiguration , ConanException
2
+ from conan .errors import ConanInvalidConfiguration
3
+ from conan .tools .apple import fix_apple_shared_install_name
3
4
from conan .tools .env import VirtualBuildEnv
4
- from conan .tools .files import export_conandata_patches , apply_conandata_patches , get , rmdir , copy , rm , replace_in_file
5
+ from conan .tools .files import apply_conandata_patches , copy , export_conandata_patches , get , replace_in_file , rm , rmdir
5
6
from conan .tools .gnu import Autotools , AutotoolsToolchain
6
7
from conan .tools .layout import basic_layout
7
- from conan .tools .microsoft import is_msvc , is_msvc_static_runtime , MSBuildDeps , MSBuildToolchain , MSBuild , VCVars , unix_path , msvc_runtime_flag , vs_layout
8
+ from conan .tools .microsoft import is_msvc , is_msvc_static_runtime , MSBuild , MSBuildToolchain
8
9
import os
9
10
10
- required_conan_version = ">=1.52 .0"
11
+ required_conan_version = ">=1.54 .0"
11
12
12
13
13
14
class LibsodiumConan (ConanFile ):
@@ -49,24 +50,12 @@ def config_options(self):
49
50
50
51
def configure (self ):
51
52
if self .options .shared :
52
- try :
53
- del self .options .fPIC
54
- except Exception :
55
- pass
56
- try :
57
- del self .settings .compiler .libcxx
58
- except Exception :
59
- pass
60
- try :
61
- del self .settings .compiler .cppstd
62
- except Exception :
63
- pass
53
+ self .options .rm_safe ("fPIC" )
54
+ self .settings .rm_safe ("compiler.cppstd" )
55
+ self .settings .rm_safe ("compiler.libcxx" )
64
56
65
57
def layout (self ):
66
- if is_msvc (self ):
67
- vs_layout (self )
68
- else :
69
- basic_layout (self , src_folder = "src" )
58
+ basic_layout (self , src_folder = "src" )
70
59
71
60
def validate (self ):
72
61
if self .options .shared and is_msvc (self ) and is_msvc_static_runtime (self ):
@@ -81,121 +70,107 @@ def build_requirements(self):
81
70
if not self .conf .get ("tools.microsoft.bash:path" , check_type = str ):
82
71
self .tool_requires ("msys2/cci.latest" )
83
72
73
+ def source (self ):
74
+ get (self , ** self .conan_data ["sources" ][self .version ], strip_root = True )
75
+
84
76
def generate (self ):
85
77
if is_msvc (self ):
86
78
tc = MSBuildToolchain (self )
87
79
tc .generate ()
88
- tc = MSBuildDeps (self )
89
- tc .generate ()
90
- tc = VCVars (self )
91
- tc .generate ()
92
80
else :
93
- tc = AutotoolsToolchain (self )
81
+ env = VirtualBuildEnv (self )
82
+ env .generate ()
94
83
84
+ tc = AutotoolsToolchain (self )
95
85
yes_no = lambda v : "yes" if v else "no"
96
86
tc .configure_args .append ("--enable-soname-versions={}" .format (yes_no (self .options .use_soname )))
97
87
tc .configure_args .append ("--enable-pie={}" .format (yes_no (self .options .PIE )))
98
-
99
- env = tc .environment ()
100
-
101
- # if self._is_mingw:
102
- # add libssp (gcc support library) for some missing symbols (e.g. __strcpy_chk)
103
- # FIXME how do I do this in conan v2?
104
- # autotools.libs.append("ssp")
105
-
88
+ if self ._is_mingw :
89
+ tc .extra_ldflags .append ("-lssp" )
106
90
if self .settings .os == "Emscripten" :
107
91
# FIXME: this is an old comment/test, has not been re-tested with conan2 upgrade
108
92
self .output .warn ("os=Emscripten is not tested/supported by this recipe" )
109
93
# FIXME: ./dist-build/emscripten.sh does not respect options of this recipe
110
-
111
- tc .generate (env )
112
-
113
- env = VirtualBuildEnv (self )
114
- env .generate ()
115
-
116
- def source (self ):
117
- get (self , ** self .conan_data ["sources" ][self .version ], destination = self .source_folder , strip_root = True )
94
+ tc .generate ()
118
95
119
96
@property
120
97
def _msvc_sln_folder (self ):
121
- if self . settings . compiler == "Visual Studio" :
122
- folder = {
98
+ sln_folders = {
99
+ "Visual Studio" : {
123
100
"10" : "vs2010" ,
124
101
"11" : "vs2012" ,
125
102
"12" : "vs2013" ,
126
103
"14" : "vs2015" ,
127
104
"15" : "vs2017" ,
128
105
"16" : "vs2019" ,
129
- }
130
- elif self .settings .compiler == "msvc" :
131
- folder = {
106
+ },
107
+ "msvc" : {
108
+ "170" : "vs2012" ,
109
+ "180" : "vs2013" ,
132
110
"190" : "vs2015" ,
133
111
"191" : "vs2017" ,
134
112
"192" : "vs2019" ,
135
- }
136
- else :
137
- raise ConanException ("Should not call this function with any other compiler" )
138
-
113
+ },
114
+ }
115
+ default_folder = "vs2019"
139
116
if self .version != "1.0.18" :
140
- if self .settings .compiler == "Visual Studio" :
141
- folder ["17" ] = "vs2022"
142
- else :
143
- folder ["193" ] = "vs2022"
117
+ sln_folders ["Visual Studio" ]["17" ] = "vs2022"
118
+ sln_folders ["msvc" ]["193" ] = "vs2022"
119
+ default_folder = "vs2022"
144
120
145
- return folder .get (str (self .settings .compiler . version ))
121
+ return sln_folders .get (str (self .settings .compiler ), {}). get ( str ( self . settings . compiler . version ), default_folder )
146
122
147
- @property
148
- def _msvc_platform (self ):
149
- return {
150
- "x86" : "Win32" ,
151
- "x86_64" : "x64" ,
152
- }[str (self .settings .arch )]
123
+ def _build_msvc (self ):
124
+ msvc_builds_folder = os .path .join (self .source_folder , "builds" , "msvc" )
125
+ msvc_sln_folder = os .path .join (msvc_builds_folder , self ._msvc_sln_folder )
126
+ vcxproj_path = os .path .join (msvc_sln_folder , "libsodium" , "libsodium.vcxproj" )
153
127
154
- # Method copied from xz_utils
155
- def _fix_msvc_platform_toolset (self , vcxproj_file , old_toolset ):
156
- platform_toolset = {
157
- "Visual Studio" : {
158
- "8" : "v80" ,
159
- "9" : "v90" ,
160
- "10" : "v100" ,
161
- "11" : "v110" ,
162
- "12" : "v120" ,
163
- "14" : "v140" ,
164
- "15" : "v141" ,
165
- "16" : "v142" ,
166
- "17" : "v143" ,
167
- },
168
- "msvc" : {
169
- "170" : "v110" ,
170
- "180" : "v120" ,
171
- "190" : "v140" ,
172
- "191" : "v141" ,
173
- "192" : "v142" ,
174
- "193" : "v143" ,
175
- }
176
- }.get (str (self .settings .compiler ), {}).get (str (self .settings .compiler .version ))
177
- if not platform_toolset :
178
- raise ConanException (
179
- f"Unknown platform toolset for { self .settings .compiler } { self .settings .compiler .version } " ,
128
+ # 1.0.18 only supported up to vs2019. Add support for newer toolsets.
129
+ if self .version == "1.0.18" and self ._msvc_sln_folder == "vs2019" :
130
+ toolset = MSBuildToolchain (self ).toolset
131
+ replace_in_file (
132
+ self , vcxproj_path ,
133
+ "<PlatformToolset>v142</PlatformToolset>" ,
134
+ f"<PlatformToolset>{ toolset } </PlatformToolset>" ,
180
135
)
136
+
137
+ # FIXME: There is currently no guarantee from new MSBuild helper that props files
138
+ # generated by MSBuildToolchain and MSBuildDeps have precedence over custom values of project.
139
+ # Therefore conantoolchain.props is injected manually before Microsoft.Cpp.Default.props like it was done
140
+ # with /p:ForceImportBeforeCppTargets in legacy MSBuild helper.
141
+ # see:
142
+ # - https://learn.microsoft.com/en-us/cpp/build/modify-project-properties-without-changing-project-file
143
+ # - https://github.com/conan-io/conan/issues/12155
144
+ conantoolchain_props = os .path .join (self .generators_folder , "conantoolchain.props" )
181
145
replace_in_file (
182
- self ,
183
- vcxproj_file ,
184
- f"<PlatformToolset>{ old_toolset } </PlatformToolset>" ,
185
- f"<PlatformToolset>{ platform_toolset } </PlatformToolset>" ,
146
+ self , vcxproj_path ,
147
+ "<Import Project=\" $(VCTargetsPath)\\ Microsoft.Cpp.Default.props\" />" ,
148
+ f"<Import Project=\" { conantoolchain_props } \" />\n <Import Project=\" $(VCTargetsPath)\\ Microsoft.Cpp.Default.props\" />" ,
186
149
)
187
150
188
- def _build_msvc (self ):
189
- msvc_ver_subfolder = self ._msvc_sln_folder or ("vs2022" if self .version != "1.0.18" else "vs2019" )
190
- msvc_sln_folder = os .path .join (self .build_folder , self .source_folder , "builds" , "msvc" , msvc_ver_subfolder )
191
-
192
- msvc_sln_path = os .path .join (msvc_sln_folder , "libsodium.sln" )
193
-
194
- # 1.0.18 only supported up to vs2019. Add support for newer toolsets.
195
- if self .version == "1.0.18" and msvc_ver_subfolder == "vs2019" :
196
- vcxproj_path = os .path .join (msvc_sln_folder , "libsodium" , "libsodium.vcxproj" )
197
- self ._fix_msvc_platform_toolset (vcxproj_path , "v142" )
151
+ # Honor runtime library from profile
152
+ runtime_library = MSBuildToolchain (self ).runtime_library
153
+ for prop_file , runtime_library_old in [
154
+ ("DebugDEXE.props" , "MultiThreadedDebugDLL" ),
155
+ ("DebugDLL.props" , "MultiThreadedDebugDLL" ),
156
+ ("DebugLEXE.props" , "MultiThreadedDebug" ),
157
+ ("DebugLIB.props" , "MultiThreadedDebug" ),
158
+ ("DebugLTCG.props" , "MultiThreadedDebug" ),
159
+ ("DebugSEXE.props" , "MultiThreadedDebug" ),
160
+ ("ReleaseDEXE.props" , "MultiThreadedDLL" ),
161
+ ("ReleaseDLL.props" , "MultiThreadedDLL" ),
162
+ ("ReleaseLEXE.props" , "MultiThreaded" ),
163
+ ("ReleaseLIB.props" , "MultiThreaded" ),
164
+ ("ReleaseLTCG.props" , "MultiThreaded" ),
165
+ ("ReleaseSEXE.props" , "MultiThreaded" ),
166
+ ]:
167
+ replace_in_file (
168
+ self , os .path .join (msvc_builds_folder , "properties" , prop_file ),
169
+ f"<RuntimeLibrary>{ runtime_library_old } </RuntimeLibrary>" ,
170
+ f"<RuntimeLibrary>{ runtime_library } </RuntimeLibrary>" ,
171
+ )
198
172
173
+ msbuild = MSBuild (self )
199
174
build_type = "{}{}" .format (
200
175
"Dyn" if self .options .shared else "Static" ,
201
176
"Debug" if self .settings .build_type == "Debug" else "Release" ,
@@ -206,34 +181,34 @@ def _build_msvc(self):
206
181
"x86_64" : "x64" ,
207
182
}[str (self .settings .arch )]
208
183
209
- msbuild = MSBuild (self )
210
184
msbuild .build_type = build_type
211
185
msbuild .platform = platform
212
- msbuild .build (msvc_sln_path )
213
-
186
+ msbuild .build (os .path .join (msvc_sln_folder , "libsodium.sln" ))
214
187
215
188
def build (self ):
216
189
apply_conandata_patches (self )
217
190
if is_msvc (self ):
218
191
self ._build_msvc ()
219
192
else :
220
193
autotools = Autotools (self )
194
+ if self ._is_mingw :
195
+ autotools .autoreconf ()
221
196
autotools .configure ()
222
197
autotools .make ()
223
198
224
199
def package (self ):
225
- copy (self , "*LICENSE" , src = self .source_folder , dst = os .path .join (self .package_folder , "licenses" ), keep_path = False )
200
+ copy (self , "*LICENSE" , src = self .source_folder , dst = os .path .join (self .package_folder , "licenses" ))
226
201
if is_msvc (self ):
227
202
copy (self , "*.lib" , src = self .source_folder , dst = os .path .join (self .package_folder , "lib" ), keep_path = False )
228
203
copy (self , "*.dll" , src = self .source_folder , dst = os .path .join (self .package_folder , "bin" ), keep_path = False )
229
- inc_src = os .path .join (self .source_folder , "src" , self . name , "include" )
230
- copy (self , "*.h" , src = inc_src , dst = os .path .join (self .package_folder , "include" ), keep_path = True , excludes = ("*/private/*" ))
204
+ inc_src = os .path .join (self .source_folder , "src" , "libsodium" , "include" )
205
+ copy (self , "*.h" , src = inc_src , dst = os .path .join (self .package_folder , "include" ), excludes = ("*/private/*" ))
231
206
else :
232
207
autotools = Autotools (self )
233
- # TODO: replace by autotools.install() once https://github.com/conan-io/conan/issues/12153 fixed
234
- autotools .install (args = [f"DESTDIR={ unix_path (self , self .package_folder )} " ])
208
+ autotools .install ()
235
209
rmdir (self , os .path .join (self .package_folder , "lib" , "pkgconfig" ))
236
210
rm (self , "*.la" , os .path .join (self .package_folder , "lib" ))
211
+ fix_apple_shared_install_name (self )
237
212
238
213
def package_info (self ):
239
214
self .cpp_info .set_property ("pkg_config_name" , "libsodium" )
0 commit comments