Skip to content

Commit 3762152

Browse files
author
Martin Valgur
committed
libidn: fix MSVC build, WIP
1 parent 745377f commit 3762152

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

recipes/libidn/all/conanfile.py

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from conan import ConanFile
44
from conan.errors import ConanInvalidConfiguration
55
from conan.tools.build import cross_building
6-
from conan.tools.env import Environment, VirtualBuildEnv, VirtualRunEnv
6+
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv
77
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
10-
from conan.tools.scm import Version
8+
from conan.tools.gnu import AutotoolsToolchain, Autotools, AutotoolsDeps
9+
from conan.tools.layout import basic_layout
10+
from conan.tools.microsoft import unix_path, is_msvc, check_min_vs
1111

1212
required_conan_version = ">=1.33.0"
1313

@@ -22,8 +22,16 @@ class LibIdnConan(ConanFile):
2222

2323
package_type = "library"
2424
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}
25+
options = {
26+
"shared": [True, False],
27+
"fPIC": [True, False],
28+
"threads": [True, False],
29+
}
30+
default_options = {
31+
"shared": False,
32+
"fPIC": True,
33+
"threads": True,
34+
}
2735

2836
@property
2937
def _settings_build(self):
@@ -39,8 +47,11 @@ def config_options(self):
3947
def configure(self):
4048
if self.options.shared:
4149
self.options.rm_safe("fPIC")
42-
del self.settings.compiler.libcxx
43-
del self.settings.compiler.cppstd
50+
self.settings.rm_safe("compiler.libcxx")
51+
self.settings.rm_safe("compiler.cppstd")
52+
53+
def layout(self):
54+
basic_layout(self, src_folder="src")
4455

4556
def requirements(self):
4657
self.requires("libiconv/1.17")
@@ -55,7 +66,7 @@ def build_requirements(self):
5566
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
5667
self.tool_requires("msys2/cci.latest")
5768
if is_msvc(self):
58-
self.tool_requires("automake/1.16.5")
69+
self.tool_requires("cccl/1.3")
5970

6071
def source(self):
6172
get(self, **self.conan_data["sources"][self.version], strip_root=True)
@@ -67,36 +78,25 @@ def generate(self):
6778
env = VirtualRunEnv(self)
6879
env.generate(scope="build")
6980
tc = AutotoolsToolchain(self)
70-
tc.libs = []
7181
if not self.options.shared:
7282
tc.defines.append("LIBIDN_STATIC")
83+
env = tc.environment()
7384
if is_msvc(self):
74-
if Version(self.settings.compiler.version) >= "12":
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):
7589
tc.extra_cflags.append("-FS")
76-
tc.extra_ldflags += ["-L{}".format(p.replace("\\", "/")) for p in self.deps_cpp_info.lib_paths]
7790
yes_no = lambda v: "yes" if v else "no"
7891
tc.configure_args += [
7992
"--enable-threads={}".format(yes_no(self.options.threads)),
80-
"--with-libiconv-prefix={}".format(unix_path(self, self.dependencies["libiconv"].cpp_info.libdirs[0])), # FIXME
93+
"--with-libiconv-prefix={}".format(unix_path(self, self.dependencies["libiconv"].package_folder)),
8194
"--disable-nls",
8295
"--disable-rpath",
8396
]
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")
97+
tc.generate(env)
98+
deps = AutotoolsDeps(self)
99+
deps.generate()
100100

101101
def _patch_sources(self):
102102
apply_conandata_patches(self)
@@ -106,6 +106,12 @@ def _patch_sources(self):
106106
else:
107107
ssize = "signed long int"
108108
replace_in_file(self, os.path.join(self.source_folder, "lib", "stringprep.h"), "ssize_t", ssize)
109+
if self.settings.os == "Windows":
110+
# Otherwise tries to create a symlink from GNUmakefile to itself, which fails on Windows
111+
replace_in_file(self, os.path.join(self.source_folder, "configure"),
112+
'"$GNUmakefile") CONFIG_LINKS="$CONFIG_LINKS $GNUmakefile:$GNUmakefile" ;;', "")
113+
replace_in_file(self, os.path.join(self.source_folder, "configure"),
114+
'ac_config_links="$ac_config_links $GNUmakefile:$GNUmakefile"', "")
109115

110116
def build(self):
111117
self._patch_sources()

0 commit comments

Comments
 (0)