1
1
import os
2
2
3
3
from conan import ConanFile
4
- from conan .errors import ConanInvalidConfiguration
5
4
from conan .tools .build import cross_building
6
- from conan .tools .env import VirtualBuildEnv , VirtualRunEnv
7
- from conan .tools .files import get , rmdir , export_conandata_patches , apply_conandata_patches , copy , chdir , replace_in_file , rm
5
+ from conan .tools .env import VirtualBuildEnv , VirtualRunEnv , Environment
6
+ from conan .tools .files import get , rmdir , export_conandata_patches , apply_conandata_patches , copy , replace_in_file , rm , save
8
7
from conan .tools .gnu import AutotoolsToolchain , Autotools , AutotoolsDeps
9
8
from conan .tools .layout import basic_layout
10
- from conan .tools .microsoft import unix_path , is_msvc , check_min_vs
9
+ from conan .tools .microsoft import unix_path , is_msvc
11
10
12
- required_conan_version = ">=1.33 .0"
11
+ required_conan_version = ">=1.53 .0"
13
12
14
13
15
14
class LibIdnConan (ConanFile ):
@@ -56,37 +55,28 @@ def layout(self):
56
55
def requirements (self ):
57
56
self .requires ("libiconv/1.17" )
58
57
59
- def validate (self ):
60
- if self .settings .os == "Windows" and self .options .shared :
61
- raise ConanInvalidConfiguration ("Shared libraries are not supported on Windows due to libtool limitation" )
62
-
63
58
def build_requirements (self ):
64
59
if self ._settings_build .os == "Windows" :
65
60
self .win_bash = True
66
61
if not self .conf .get ("tools.microsoft.bash:path" , check_type = str ):
67
62
self .tool_requires ("msys2/cci.latest" )
68
63
if is_msvc (self ):
69
- self .tool_requires ("cccl /1.3 " )
64
+ self .tool_requires ("automake /1.16.5 " )
70
65
71
66
def source (self ):
72
67
get (self , ** self .conan_data ["sources" ][self .version ], strip_root = True )
73
68
74
69
def generate (self ):
75
70
env = VirtualBuildEnv (self )
76
71
env .generate ()
72
+
77
73
if not cross_building (self ):
78
74
env = VirtualRunEnv (self )
79
75
env .generate (scope = "build" )
76
+
80
77
tc = AutotoolsToolchain (self )
81
78
if not self .options .shared :
82
- tc .defines .append ("LIBIDN_STATIC" )
83
- env = tc .environment ()
84
- if is_msvc (self ):
85
- env .define ("CC" , "cccl" )
86
- env .define ("CXX" , "cccl" )
87
- env .define ("LD" , "cccl" )
88
- if check_min_vs (self , 180 , raise_invalid = False ):
89
- tc .extra_cflags .append ("-FS" )
79
+ tc .extra_defines .append ("LIBIDN_STATIC" )
90
80
yes_no = lambda v : "yes" if v else "no"
91
81
tc .configure_args += [
92
82
"--enable-threads={}" .format (yes_no (self .options .threads )),
@@ -95,18 +85,48 @@ def generate(self):
95
85
"--disable-nls" ,
96
86
"--disable-rpath" ,
97
87
]
98
- tc .generate (env )
99
- deps = AutotoolsDeps (self )
100
- deps .generate ()
88
+ if is_msvc (self ):
89
+ tc .extra_cxxflags .append ("-FS" )
90
+ tc .generate ()
91
+
92
+ if is_msvc (self ):
93
+ env = Environment ()
94
+ dep_info = self .dependencies ["libiconv" ].cpp_info .aggregated_components ()
95
+ env .append ("CPPFLAGS" , [f"-I{ unix_path (self , p )} " for p in dep_info .includedirs ] + [f"-D{ d } " for d in dep_info .defines ])
96
+ env .append ("_LINK_" , [lib if lib .endswith (".lib" ) else f"{ lib } .lib" for lib in (dep_info .libs + dep_info .system_libs )])
97
+ env .append ("LDFLAGS" , [f"-L{ unix_path (self , p )} " for p in dep_info .libdirs ] + dep_info .sharedlinkflags + dep_info .exelinkflags )
98
+ env .append ("CFLAGS" , dep_info .cflags )
99
+ env .vars (self ).save_script ("conanautotoolsdeps_cl_workaround" )
100
+ else :
101
+ deps = AutotoolsDeps (self )
102
+ deps .generate ()
103
+
104
+ if is_msvc (self ):
105
+ env = Environment ()
106
+ automake_conf = self .dependencies .build ["automake" ].conf_info
107
+ compile_wrapper = unix_path (self , automake_conf .get ("user.automake:compile-wrapper" , check_type = str ))
108
+ ar_wrapper = unix_path (self , automake_conf .get ("user.automake:lib-wrapper" , check_type = str ))
109
+ # Workaround for iconv.lib not being found due to linker flag order
110
+ libiconv_libdir = unix_path (self , self .dependencies ["libiconv" ].cpp_info .aggregated_components ().libdir )
111
+ env .define ("CC" , f"{ compile_wrapper } cl -nologo -L{ libiconv_libdir } " )
112
+ env .define ("CXX" , f"{ compile_wrapper } cl -nologo" )
113
+ env .define ("LD" , "link -nologo" )
114
+ env .define ("AR" , f'{ ar_wrapper } lib' )
115
+ env .vars (self ).save_script ("conanbuild_msvc" )
101
116
102
117
def _patch_sources (self ):
103
118
apply_conandata_patches (self )
119
+ # Disable examples and tests
120
+ for subdir in ["examples" , "tests" , "fuzz" , "gltests" , os .path .join ("lib" , "gltests" ), "doc" ]:
121
+ save (self , os .path .join (self .source_folder , subdir , "Makefile.in" ), "all:\n install:\n " )
122
+
104
123
if is_msvc (self ):
105
124
if self .settings .arch in ("x86_64" , "armv8" , "armv8.3" ):
106
125
ssize = "signed long long int"
107
126
else :
108
127
ssize = "signed long int"
109
128
replace_in_file (self , os .path .join (self .source_folder , "lib" , "stringprep.h" ), "ssize_t" , ssize )
129
+
110
130
if self .settings .os == "Windows" :
111
131
# Otherwise tries to create a symlink from GNUmakefile to itself, which fails on Windows
112
132
replace_in_file (self , os .path .join (self .source_folder , "configure" ),
@@ -116,22 +136,27 @@ def _patch_sources(self):
116
136
117
137
def build (self ):
118
138
self ._patch_sources ()
119
- with chdir (self , self .source_folder ):
120
- autotools = Autotools (self )
121
- autotools .configure ()
122
- autotools .make (args = ["V=1" ])
139
+ autotools = Autotools (self )
140
+ autotools .configure ()
141
+ autotools .make ()
123
142
124
143
def package (self ):
125
- copy (self , "COPYING" , dst = os .path .join (self .package_folder , "licenses" ), src = self .source_folder )
126
- with chdir (self , self .source_folder ):
127
- autotools = Autotools (self )
128
- autotools .install ()
144
+ copy (self , "COPYING" , self .source_folder , os .path .join (self .package_folder , "licenses" ))
145
+ autotools = Autotools (self )
146
+ autotools .install ()
129
147
rmdir (self , os .path .join (self .package_folder , "lib" , "pkgconfig" ))
130
148
rmdir (self , os .path .join (self .package_folder , "share" ))
131
149
rm (self , "*.la" , os .path .join (self .package_folder , "lib" ), recursive = True )
132
150
151
+ if is_msvc (self ) and self .options .shared :
152
+ os .rename (os .path .join (self .package_folder , "lib" , "idn.dll.lib" ),
153
+ os .path .join (self .package_folder , "lib" , "idn-12.lib" ))
154
+
133
155
def package_info (self ):
134
- self .cpp_info .libs = ["idn" ]
156
+ if is_msvc (self ) and self .options .shared :
157
+ self .cpp_info .libs = ["idn-12" ]
158
+ else :
159
+ self .cpp_info .libs = ["idn" ]
135
160
self .cpp_info .set_property ("pkg_config_name" , "libidn" )
136
161
if self .settings .os in ["Linux" , "FreeBSD" ]:
137
162
if self .options .threads :
0 commit comments