1
+ import os
2
+
1
3
from conan import ConanFile
2
4
from conan .errors import ConanInvalidConfiguration
3
- from conan .tools .files import get , rmdir
5
+ from conan .tools .build import cross_building
6
+ from conan .tools .env import Environment , VirtualBuildEnv , VirtualRunEnv
7
+ from conan .tools .files import get , rmdir , export_conandata_patches , apply_conandata_patches , copy , chdir , replace_in_file , rm
8
+ from conan .tools .gnu import AutotoolsToolchain , Autotools
9
+ from conan .tools .microsoft import unix_path , is_msvc
4
10
from conan .tools .scm import Version
5
- from conans import AutoToolsBuildEnvironment , tools
6
- import contextlib
7
- import functools
8
- import os
9
11
10
12
required_conan_version = ">=1.33.0"
11
13
@@ -17,37 +19,26 @@ class LibIdnConan(ConanFile):
17
19
topics = ("libidn" , "encode" , "decode" , "internationalized" , "domain" , "name" )
18
20
license = "GPL-3.0-or-later"
19
21
url = "https://github.com/conan-io/conan-center-index"
20
- settings = "os" , "arch" , "compiler" , "build_type"
21
- options = {
22
- "shared" : [True , False ],
23
- "fPIC" : [True , False ],
24
- "threads" : [True , False ],
25
- }
26
- default_options = {
27
- "shared" : False ,
28
- "fPIC" : True ,
29
- "threads" : True ,
30
- }
31
22
32
- @property
33
- def _source_subfolder (self ):
34
- return "source_subfolder"
23
+ package_type = "library"
24
+ settings = "os" , "arch" , "compiler" , "build_type"
25
+ options = {"shared" : [True , False ], "fPIC" : [True , False ], "threads" : [True , False ]}
26
+ default_options = {"shared" : False , "fPIC" : True , "threads" : True }
35
27
36
28
@property
37
29
def _settings_build (self ):
38
30
return getattr (self , "settings_build" , self .settings )
39
31
40
32
def export_sources (self ):
41
- for patch in self .conan_data .get ("patches" , {}).get (self .version , []):
42
- self .copy (patch ["patch_file" ])
33
+ export_conandata_patches (self )
43
34
44
35
def config_options (self ):
45
36
if self .settings .os == "Windows" :
46
37
del self .options .fPIC
47
38
48
39
def configure (self ):
49
40
if self .options .shared :
50
- del self .options .fPIC
41
+ self .options .rm_safe ( " fPIC" )
51
42
del self .settings .compiler .libcxx
52
43
del self .settings .compiler .cppstd
53
44
@@ -59,87 +50,90 @@ def validate(self):
59
50
raise ConanInvalidConfiguration ("Shared libraries are not supported on Windows due to libtool limitation" )
60
51
61
52
def build_requirements (self ):
62
- if self ._settings_build .os == "Windows" and not tools .get_env ("CONAN_BASH_PATH" ):
63
- self .build_requires ("msys2/cci.latest" )
64
- if self .settings .compiler == "Visual Studio" :
65
- self .build_requires ("automake/1.16.5" )
53
+ if self ._settings_build .os == "Windows" :
54
+ self .win_bash = True
55
+ if not self .conf .get ("tools.microsoft.bash:path" , check_type = str ):
56
+ self .tool_requires ("msys2/cci.latest" )
57
+ if is_msvc (self ):
58
+ self .tool_requires ("automake/1.16.5" )
66
59
67
60
def source (self ):
68
- get (self , ** self .conan_data ["sources" ][self .version ],
69
- destination = self ._source_subfolder , strip_root = True )
70
-
71
- @contextlib .contextmanager
72
- def _build_context (self ):
73
- if self .settings .compiler == "Visual Studio" :
74
- with tools .vcvars (self ):
75
- env = {
76
- "CC" : "{} cl -nologo" .format (tools .unix_path (self .deps_user_info ["automake" ].compile )),
77
- "CXX" : "{} cl -nologo" .format (tools .unix_path (self .deps_user_info ["automake" ].compile )),
78
- "LD" : "{} link -nologo" .format (tools .unix_path (self .deps_user_info ["automake" ].compile )),
79
- "AR" : "{} lib" .format (tools .unix_path (self .deps_user_info ["automake" ].ar_lib )),
80
- }
81
- with tools .environment_append (env ):
82
- yield
83
- else :
84
- yield
85
-
86
- @functools .lru_cache (1 )
87
- def _configure_autotools (self ):
88
- autotools = AutoToolsBuildEnvironment (self , win_bash = tools .os_info .is_windows )
89
- autotools .libs = []
61
+ get (self , ** self .conan_data ["sources" ][self .version ], strip_root = True )
62
+
63
+ def generate (self ):
64
+ env = VirtualBuildEnv (self )
65
+ env .generate ()
66
+ if not cross_building (self ):
67
+ env = VirtualRunEnv (self )
68
+ env .generate (scope = "build" )
69
+ tc = AutotoolsToolchain (self )
70
+ tc .libs = []
90
71
if not self .options .shared :
91
- autotools .defines .append ("LIBIDN_STATIC" )
92
- if self . settings . compiler == "Visual Studio" :
72
+ tc .defines .append ("LIBIDN_STATIC" )
73
+ if is_msvc ( self ) :
93
74
if Version (self .settings .compiler .version ) >= "12" :
94
- autotools . flags .append ("-FS" )
95
- autotools . link_flags . extend ( "-L{}" .format (p .replace ("\\ " , "/" )) for p in self .deps_cpp_info .lib_paths )
75
+ tc . extra_cflags .append ("-FS" )
76
+ tc . extra_ldflags += [ "-L{}" .format (p .replace ("\\ " , "/" )) for p in self .deps_cpp_info .lib_paths ]
96
77
yes_no = lambda v : "yes" if v else "no"
97
- conf_args = [
98
- "--enable-shared={}" .format (yes_no (self .options .shared )),
99
- "--enable-static={}" .format (yes_no (not self .options .shared )),
78
+ tc .configure_args += [
100
79
"--enable-threads={}" .format (yes_no (self .options .threads )),
101
- "--with-libiconv-prefix={}" .format (tools . unix_path (self . deps_cpp_info ["libiconv" ].rootpath )),
80
+ "--with-libiconv-prefix={}" .format (unix_path (self , self . dependencies ["libiconv" ].cpp_info . libdirs [ 0 ] )), # FIXME
102
81
"--disable-nls" ,
103
82
"--disable-rpath" ,
104
83
]
105
- autotools .configure (args = conf_args , configure_dir = self ._source_subfolder )
106
- return autotools
107
-
108
- def build (self ):
109
- for patch in self .conan_data .get ("patches" , {}).get (self .version , []):
110
- tools .patch (** patch )
111
- if self .settings .compiler == "Visual Studio" :
84
+ tc .generate ()
85
+
86
+ if is_msvc (self ):
87
+ env = Environment ()
88
+ automake_conf = self .dependencies .build ["automake" ].conf_info
89
+ compile_wrapper = unix_path (self , automake_conf .get ("user.automake:compile-wrapper" , check_type = str ))
90
+ ar_wrapper = unix_path (self , automake_conf .get ("user.automake:lib-wrapper" , check_type = str ))
91
+ env .define ("CC" , f"{ compile_wrapper } cl -nologo" )
92
+ env .define ("CXX" , f"{ compile_wrapper } cl -nologo" )
93
+ env .define ("LD" , "link -nologo" )
94
+ env .define ("AR" , f'{ ar_wrapper } "lib -nologo"' )
95
+ env .define ("NM" , "dumpbin -symbols" )
96
+ env .define ("OBJDUMP" , ":" )
97
+ env .define ("RANLIB" , ":" )
98
+ env .define ("STRIP" , ":" )
99
+ env .vars (self ).save_script ("conanbuild_msvc" )
100
+
101
+ def _patch_sources (self ):
102
+ apply_conandata_patches (self )
103
+ if is_msvc (self ):
112
104
if self .settings .arch in ("x86_64" , "armv8" , "armv8.3" ):
113
105
ssize = "signed long long int"
114
106
else :
115
107
ssize = "signed long int"
116
- tools .replace_in_file (os .path .join (self ._source_subfolder , "lib" , "stringprep.h" ),
117
- "ssize_t" , ssize )
118
- with self ._build_context ():
119
- autotools = self ._configure_autotools ()
108
+ replace_in_file (self , os .path .join (self .source_folder , "lib" , "stringprep.h" ), "ssize_t" , ssize )
109
+
110
+ def build (self ):
111
+ self ._patch_sources ()
112
+ with chdir (self , self .source_folder ):
113
+ autotools = Autotools (self )
114
+ autotools .configure ()
120
115
autotools .make (args = ["V=1" ])
121
116
122
117
def package (self ):
123
- self . copy ("COPYING" , src = self ._source_subfolder , dst = "licenses" )
124
- with self . _build_context ( ):
125
- autotools = self . _configure_autotools ( )
118
+ copy (self , "COPYING" , dst = os . path . join ( self .package_folder , "licenses" ), src = self . source_folder )
119
+ with chdir ( self , self . source_folder ):
120
+ autotools = Autotools ( self )
126
121
autotools .install ()
127
-
128
122
rmdir (self , os .path .join (self .package_folder , "lib" , "pkgconfig" ))
129
123
rmdir (self , os .path .join (self .package_folder , "share" ))
130
- tools . remove_files_by_mask ( os .path .join (self .package_folder , "lib" ), "*.la" )
124
+ rm ( self , os .path .join (self .package_folder , "lib" ), "*.la" , recursive = True )
131
125
132
126
def package_info (self ):
133
127
self .cpp_info .libs = ["idn" ]
134
- self .cpp_info .names [ "pkg_config" ] = "libidn"
128
+ self .cpp_info .set_property ( "pkg_config_name" , "libidn" )
135
129
if self .settings .os in ["Linux" , "FreeBSD" ]:
136
130
if self .options .threads :
137
131
self .cpp_info .system_libs = ["pthread" ]
138
132
if self .settings .os == "Windows" :
139
133
if not self .options .shared :
140
134
self .cpp_info .defines = ["LIBIDN_STATIC" ]
141
135
136
+ # TODO: to remove in conan v2
142
137
bin_path = os .path .join (self .package_folder , "bin" )
143
- self .output .info ("Appending PATH environment variable: {}" . format ( bin_path ) )
138
+ self .output .info (f "Appending PATH environment variable: { bin_path } " )
144
139
self .env_info .PATH .append (bin_path )
145
-
0 commit comments