Skip to content

Commit

Permalink
libidn: fix MSVC build
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Oct 23, 2023
1 parent 8106a7a commit dab766a
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions recipes/libidn/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import cross_building
from conan.tools.env import Environment, VirtualBuildEnv, VirtualRunEnv
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv
from conan.tools.files import get, rmdir, export_conandata_patches, apply_conandata_patches, copy, chdir, replace_in_file, rm
from conan.tools.gnu import AutotoolsToolchain, Autotools
from conan.tools.microsoft import unix_path, is_msvc
from conan.tools.scm import Version
from conan.tools.gnu import AutotoolsToolchain, Autotools, AutotoolsDeps
from conan.tools.layout import basic_layout
from conan.tools.microsoft import unix_path, is_msvc, check_min_vs

required_conan_version = ">=1.33.0"

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

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False], "threads": [True, False]}
default_options = {"shared": False, "fPIC": True, "threads": True}
options = {
"shared": [True, False],
"fPIC": [True, False],
"threads": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"threads": True,
}

@property
def _settings_build(self):
Expand All @@ -39,8 +47,11 @@ def config_options(self):
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

def layout(self):
basic_layout(self, src_folder="src")

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

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
Expand All @@ -67,36 +78,25 @@ def generate(self):
env = VirtualRunEnv(self)
env.generate(scope="build")
tc = AutotoolsToolchain(self)
tc.libs = []
if not self.options.shared:
tc.defines.append("LIBIDN_STATIC")
env = tc.environment()
if is_msvc(self):
if Version(self.settings.compiler.version) >= "12":
env.define("CC", "cccl")
env.define("CXX", "cccl")
env.define("LD", "cccl")
if check_min_vs(self, 180, raise_invalid=False):
tc.extra_cflags.append("-FS")
tc.extra_ldflags += ["-L{}".format(p.replace("\\", "/")) for p in self.deps_cpp_info.lib_paths]
yes_no = lambda v: "yes" if v else "no"
tc.configure_args += [
"--enable-threads={}".format(yes_no(self.options.threads)),
"--with-libiconv-prefix={}".format(unix_path(self, self.dependencies["libiconv"].cpp_info.libdirs[0])), # FIXME
"--with-libiconv-prefix={}".format(unix_path(self, self.dependencies["libiconv"].package_folder)),
"--disable-nls",
"--disable-rpath",
]
tc.generate()

if is_msvc(self):
env = Environment()
automake_conf = self.dependencies.build["automake"].conf_info
compile_wrapper = unix_path(self, automake_conf.get("user.automake:compile-wrapper", check_type=str))
ar_wrapper = unix_path(self, automake_conf.get("user.automake:lib-wrapper", check_type=str))
env.define("CC", f"{compile_wrapper} cl -nologo")
env.define("CXX", f"{compile_wrapper} cl -nologo")
env.define("LD", "link -nologo")
env.define("AR", f'{ar_wrapper} "lib -nologo"')
env.define("NM", "dumpbin -symbols")
env.define("OBJDUMP", ":")
env.define("RANLIB", ":")
env.define("STRIP", ":")
env.vars(self).save_script("conanbuild_msvc")
tc.generate(env)
deps = AutotoolsDeps(self)
deps.generate()

def _patch_sources(self):
apply_conandata_patches(self)
Expand All @@ -106,6 +106,12 @@ def _patch_sources(self):
else:
ssize = "signed long int"
replace_in_file(self, os.path.join(self.source_folder, "lib", "stringprep.h"), "ssize_t", ssize)
if self.settings.os == "Windows":
# Otherwise tries to create a symlink from GNUmakefile to itself, which fails on Windows
replace_in_file(self, os.path.join(self.source_folder, "configure"),
'"$GNUmakefile") CONFIG_LINKS="$CONFIG_LINKS $GNUmakefile:$GNUmakefile" ;;', "")
replace_in_file(self, os.path.join(self.source_folder, "configure"),
'ac_config_links="$ac_config_links $GNUmakefile:$GNUmakefile"', "")

def build(self):
self._patch_sources()
Expand Down

0 comments on commit dab766a

Please sign in to comment.