From 62b1b383d7d0ce7754b179a998c7c2d4336b1407 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 19 Jul 2023 08:35:06 +0300 Subject: [PATCH 1/6] libidn: migrate to Conan v2 --- recipes/libidn/all/conandata.yml | 1 - recipes/libidn/all/conanfile.py | 144 +++++++++--------- .../libidn/all/test_package/CMakeLists.txt | 7 +- recipes/libidn/all/test_package/conanfile.py | 26 +++- .../libidn/all/test_v1_package/CMakeLists.txt | 8 + .../libidn/all/test_v1_package/conanfile.py | 19 +++ 6 files changed, 118 insertions(+), 87 deletions(-) create mode 100644 recipes/libidn/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/libidn/all/test_v1_package/conanfile.py diff --git a/recipes/libidn/all/conandata.yml b/recipes/libidn/all/conandata.yml index 8be8baf6f09f3..fcb454914799b 100644 --- a/recipes/libidn/all/conandata.yml +++ b/recipes/libidn/all/conandata.yml @@ -5,4 +5,3 @@ sources: patches: "1.36": - patch_file: "patches/0001-unconditional-system-stdint-h.patch" - base_path: "source_subfolder" diff --git a/recipes/libidn/all/conanfile.py b/recipes/libidn/all/conanfile.py index 49221670d5e8e..612118ad955ac 100644 --- a/recipes/libidn/all/conanfile.py +++ b/recipes/libidn/all/conanfile.py @@ -1,11 +1,13 @@ +import os + from conan import ConanFile from conan.errors import ConanInvalidConfiguration -from conan.tools.files import get, rmdir +from conan.tools.build import cross_building +from conan.tools.env import Environment, 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 conans import AutoToolsBuildEnvironment, tools -import contextlib -import functools -import os required_conan_version = ">=1.33.0" @@ -17,29 +19,18 @@ class LibIdnConan(ConanFile): topics = ("libidn", "encode", "decode", "internationalized", "domain", "name") license = "GPL-3.0-or-later" url = "https://github.com/conan-io/conan-center-index" - settings = "os", "arch", "compiler", "build_type" - options = { - "shared": [True, False], - "fPIC": [True, False], - "threads": [True, False], - } - default_options = { - "shared": False, - "fPIC": True, - "threads": True, - } - @property - def _source_subfolder(self): - return "source_subfolder" + 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} @property def _settings_build(self): return getattr(self, "settings_build", self.settings) def export_sources(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - self.copy(patch["patch_file"]) + export_conandata_patches(self) def config_options(self): if self.settings.os == "Windows": @@ -47,7 +38,7 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC + self.options.rm_safe("fPIC") del self.settings.compiler.libcxx del self.settings.compiler.cppstd @@ -59,79 +50,82 @@ def validate(self): raise ConanInvalidConfiguration("Shared libraries are not supported on Windows due to libtool limitation") def build_requirements(self): - if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"): - self.build_requires("msys2/cci.latest") - if self.settings.compiler == "Visual Studio": - self.build_requires("automake/1.16.5") + if self._settings_build.os == "Windows": + self.win_bash = True + 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") def source(self): - get(self, **self.conan_data["sources"][self.version], - destination=self._source_subfolder, strip_root=True) - - @contextlib.contextmanager - def _build_context(self): - if self.settings.compiler == "Visual Studio": - with tools.vcvars(self): - env = { - "CC": "{} cl -nologo".format(tools.unix_path(self.deps_user_info["automake"].compile)), - "CXX": "{} cl -nologo".format(tools.unix_path(self.deps_user_info["automake"].compile)), - "LD": "{} link -nologo".format(tools.unix_path(self.deps_user_info["automake"].compile)), - "AR": "{} lib".format(tools.unix_path(self.deps_user_info["automake"].ar_lib)), - } - with tools.environment_append(env): - yield - else: - yield - - @functools.lru_cache(1) - def _configure_autotools(self): - autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) - autotools.libs = [] + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + env = VirtualBuildEnv(self) + env.generate() + if not cross_building(self): + env = VirtualRunEnv(self) + env.generate(scope="build") + tc = AutotoolsToolchain(self) + tc.libs = [] if not self.options.shared: - autotools.defines.append("LIBIDN_STATIC") - if self.settings.compiler == "Visual Studio": + tc.defines.append("LIBIDN_STATIC") + if is_msvc(self): if Version(self.settings.compiler.version) >= "12": - autotools.flags.append("-FS") - autotools.link_flags.extend("-L{}".format(p.replace("\\", "/")) for p in self.deps_cpp_info.lib_paths) + 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" - conf_args = [ - "--enable-shared={}".format(yes_no(self.options.shared)), - "--enable-static={}".format(yes_no(not self.options.shared)), + tc.configure_args += [ "--enable-threads={}".format(yes_no(self.options.threads)), - "--with-libiconv-prefix={}".format(tools.unix_path(self.deps_cpp_info["libiconv"].rootpath)), + "--with-libiconv-prefix={}".format(unix_path(self, self.dependencies["libiconv"].cpp_info.libdirs[0])), # FIXME "--disable-nls", "--disable-rpath", ] - autotools.configure(args=conf_args, configure_dir=self._source_subfolder) - return autotools - - def build(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) - if self.settings.compiler == "Visual Studio": + 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") + + def _patch_sources(self): + apply_conandata_patches(self) + if is_msvc(self): if self.settings.arch in ("x86_64", "armv8", "armv8.3"): ssize = "signed long long int" else: ssize = "signed long int" - tools.replace_in_file(os.path.join(self._source_subfolder, "lib", "stringprep.h"), - "ssize_t", ssize) - with self._build_context(): - autotools = self._configure_autotools() + replace_in_file(self, os.path.join(self.source_folder, "lib", "stringprep.h"), "ssize_t", ssize) + + def build(self): + self._patch_sources() + with chdir(self, self.source_folder): + autotools = Autotools(self) + autotools.configure() autotools.make(args=["V=1"]) def package(self): - self.copy("COPYING", src=self._source_subfolder, dst="licenses") - with self._build_context(): - autotools = self._configure_autotools() + copy(self, "COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + with chdir(self, self.source_folder): + autotools = Autotools(self) autotools.install() - rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) rmdir(self, os.path.join(self.package_folder, "share")) - tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la") + rm(self, "*.la", os.path.join(self.package_folder, "lib"), recursive=True) def package_info(self): self.cpp_info.libs = ["idn"] - self.cpp_info.names["pkg_config"] = "libidn" + self.cpp_info.set_property("pkg_config_name", "libidn") if self.settings.os in ["Linux", "FreeBSD"]: if self.options.threads: self.cpp_info.system_libs = ["pthread"] @@ -139,7 +133,7 @@ def package_info(self): if not self.options.shared: self.cpp_info.defines = ["LIBIDN_STATIC"] + # TODO: to remove in conan v2 bin_path = os.path.join(self.package_folder, "bin") - self.output.info("Appending PATH environment variable: {}".format(bin_path)) + self.output.info(f"Appending PATH environment variable: {bin_path}") self.env_info.PATH.append(bin_path) - diff --git a/recipes/libidn/all/test_package/CMakeLists.txt b/recipes/libidn/all/test_package/CMakeLists.txt index 7b9b613cbb24a..3482998466c6b 100644 --- a/recipes/libidn/all/test_package/CMakeLists.txt +++ b/recipes/libidn/all/test_package/CMakeLists.txt @@ -1,8 +1,7 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.15) project(test_package C) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() +find_package(libidn REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.c) -target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) +target_link_libraries(${PROJECT_NAME} PRIVATE libidn::libidn) diff --git a/recipes/libidn/all/test_package/conanfile.py b/recipes/libidn/all/test_package/conanfile.py index 07c965844de9b..66b1cc0bafc56 100644 --- a/recipes/libidn/all/test_package/conanfile.py +++ b/recipes/libidn/all/test_package/conanfile.py @@ -1,10 +1,22 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake import os class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake" + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def build_requirements(self): + self.tool_requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) def build(self): cmake = CMake(self) @@ -12,8 +24,8 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - self.run("idn --help", run_environment=True) + if can_run(self): + self.run("idn --help") - bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True) + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/libidn/all/test_v1_package/CMakeLists.txt b/recipes/libidn/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..91630d79f4abb --- /dev/null +++ b/recipes/libidn/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/libidn/all/test_v1_package/conanfile.py b/recipes/libidn/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..3eaa9f0102538 --- /dev/null +++ b/recipes/libidn/all/test_v1_package/conanfile.py @@ -0,0 +1,19 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + self.run("idn --help", run_environment=True) + + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) From 114c770aaae5e81729590b055a5e85b8ab6fb9dc Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sun, 6 Aug 2023 01:32:12 +0300 Subject: [PATCH 2/6] libidn: fix MSVC build --- recipes/libidn/all/conanfile.py | 64 ++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/recipes/libidn/all/conanfile.py b/recipes/libidn/all/conanfile.py index 612118ad955ac..c481b77109141 100644 --- a/recipes/libidn/all/conanfile.py +++ b/recipes/libidn/all/conanfile.py @@ -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" @@ -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): @@ -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") @@ -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) @@ -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) @@ -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() From f2deda0885def4cadf927994ae7ec10cd2437cc5 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 1 Nov 2023 17:32:49 +0200 Subject: [PATCH 3/6] libidn: --disable-csharp --- recipes/libidn/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/libidn/all/conanfile.py b/recipes/libidn/all/conanfile.py index c481b77109141..f29047a3e541e 100644 --- a/recipes/libidn/all/conanfile.py +++ b/recipes/libidn/all/conanfile.py @@ -91,6 +91,7 @@ def generate(self): tc.configure_args += [ "--enable-threads={}".format(yes_no(self.options.threads)), "--with-libiconv-prefix={}".format(unix_path(self, self.dependencies["libiconv"].package_folder)), + "--disable-csharp", "--disable-nls", "--disable-rpath", ] @@ -141,5 +142,4 @@ def package_info(self): # TODO: to remove in conan v2 bin_path = os.path.join(self.package_folder, "bin") - self.output.info(f"Appending PATH environment variable: {bin_path}") self.env_info.PATH.append(bin_path) From 03ac3afb4ed46a825b07fae9607d27101a183a05 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Fri, 3 Nov 2023 14:17:57 +0200 Subject: [PATCH 4/6] libidn: fix shared lib not being found in v1 --- recipes/libidn/all/test_package/conanfile.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/recipes/libidn/all/test_package/conanfile.py b/recipes/libidn/all/test_package/conanfile.py index 66b1cc0bafc56..cb12626fbf45b 100644 --- a/recipes/libidn/all/test_package/conanfile.py +++ b/recipes/libidn/all/test_package/conanfile.py @@ -1,12 +1,14 @@ +import os + from conan import ConanFile from conan.tools.build import can_run from conan.tools.cmake import cmake_layout, CMake -import os +from conan.tools.env import VirtualRunEnv class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + generators = "CMakeDeps", "CMakeToolchain" test_type = "explicit" def requirements(self): @@ -18,6 +20,10 @@ def build_requirements(self): def layout(self): cmake_layout(self) + def generate(self): + VirtualRunEnv(self).generate(scope="build") + VirtualRunEnv(self).generate(scope="run") + def build(self): cmake = CMake(self) cmake.configure() From e834cd90fb7f8265457cb3847d4dcf9b8c2c3946 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Fri, 8 Dec 2023 14:15:41 +0200 Subject: [PATCH 5/6] libidn: fix MSVC build, add shared MSVC build support --- recipes/libidn/all/conanfile.py | 85 +++++++++++++------- recipes/libidn/all/test_package/conanfile.py | 14 +--- 2 files changed, 58 insertions(+), 41 deletions(-) diff --git a/recipes/libidn/all/conanfile.py b/recipes/libidn/all/conanfile.py index f29047a3e541e..a73c08f5c01cb 100644 --- a/recipes/libidn/all/conanfile.py +++ b/recipes/libidn/all/conanfile.py @@ -1,15 +1,14 @@ import os from conan import ConanFile -from conan.errors import ConanInvalidConfiguration from conan.tools.build import cross_building -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.env import VirtualBuildEnv, VirtualRunEnv, Environment +from conan.tools.files import get, rmdir, export_conandata_patches, apply_conandata_patches, copy, replace_in_file, rm, save 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 +from conan.tools.microsoft import unix_path, is_msvc -required_conan_version = ">=1.33.0" +required_conan_version = ">=1.53.0" class LibIdnConan(ConanFile): @@ -56,17 +55,13 @@ def layout(self): def requirements(self): self.requires("libiconv/1.17") - def validate(self): - if self.settings.os == "Windows" and self.options.shared: - raise ConanInvalidConfiguration("Shared libraries are not supported on Windows due to libtool limitation") - def build_requirements(self): if self._settings_build.os == "Windows": self.win_bash = True 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("cccl/1.3") + self.tool_requires("automake/1.16.5") def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) @@ -74,19 +69,14 @@ def source(self): def generate(self): env = VirtualBuildEnv(self) env.generate() + if not cross_building(self): env = VirtualRunEnv(self) env.generate(scope="build") + tc = AutotoolsToolchain(self) if not self.options.shared: - tc.defines.append("LIBIDN_STATIC") - env = tc.environment() - if is_msvc(self): - 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_defines.append("LIBIDN_STATIC") yes_no = lambda v: "yes" if v else "no" tc.configure_args += [ "--enable-threads={}".format(yes_no(self.options.threads)), @@ -95,18 +85,48 @@ def generate(self): "--disable-nls", "--disable-rpath", ] - tc.generate(env) - deps = AutotoolsDeps(self) - deps.generate() + if is_msvc(self): + tc.extra_cxxflags.append("-FS") + tc.generate() + + if is_msvc(self): + env = Environment() + dep_info = self.dependencies["libiconv"].cpp_info.aggregated_components() + env.append("CPPFLAGS", [f"-I{unix_path(self, p)}" for p in dep_info.includedirs] + [f"-D{d}" for d in dep_info.defines]) + env.append("_LINK_", [lib if lib.endswith(".lib") else f"{lib}.lib" for lib in (dep_info.libs + dep_info.system_libs)]) + env.append("LDFLAGS", [f"-L{unix_path(self, p)}" for p in dep_info.libdirs] + dep_info.sharedlinkflags + dep_info.exelinkflags) + env.append("CFLAGS", dep_info.cflags) + env.vars(self).save_script("conanautotoolsdeps_cl_workaround") + else: + deps = AutotoolsDeps(self) + deps.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)) + # Workaround for iconv.lib not being found due to linker flag order + libiconv_libdir = unix_path(self, self.dependencies["libiconv"].cpp_info.aggregated_components().libdir) + env.define("CC", f"{compile_wrapper} cl -nologo -L{libiconv_libdir}") + env.define("CXX", f"{compile_wrapper} cl -nologo") + env.define("LD", "link -nologo") + env.define("AR", f'{ar_wrapper} lib') + env.vars(self).save_script("conanbuild_msvc") def _patch_sources(self): apply_conandata_patches(self) + # Disable examples and tests + for subdir in ["examples", "tests", "fuzz", "gltests", os.path.join("lib", "gltests"), "doc"]: + save(self, os.path.join(self.source_folder, subdir, "Makefile.in"), "all:\ninstall:\n") + if is_msvc(self): if self.settings.arch in ("x86_64", "armv8", "armv8.3"): ssize = "signed long long int" 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"), @@ -116,22 +136,27 @@ def _patch_sources(self): def build(self): self._patch_sources() - with chdir(self, self.source_folder): - autotools = Autotools(self) - autotools.configure() - autotools.make(args=["V=1"]) + autotools = Autotools(self) + autotools.configure() + autotools.make() def package(self): - copy(self, "COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) - with chdir(self, self.source_folder): - autotools = Autotools(self) - autotools.install() + copy(self, "COPYING", self.source_folder, os.path.join(self.package_folder, "licenses")) + autotools = Autotools(self) + autotools.install() rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) rmdir(self, os.path.join(self.package_folder, "share")) rm(self, "*.la", os.path.join(self.package_folder, "lib"), recursive=True) + if is_msvc(self) and self.options.shared: + os.rename(os.path.join(self.package_folder, "lib", "idn.dll.lib"), + os.path.join(self.package_folder, "lib", "idn-12.lib")) + def package_info(self): - self.cpp_info.libs = ["idn"] + if is_msvc(self) and self.options.shared: + self.cpp_info.libs = ["idn-12"] + else: + self.cpp_info.libs = ["idn"] self.cpp_info.set_property("pkg_config_name", "libidn") if self.settings.os in ["Linux", "FreeBSD"]: if self.options.threads: diff --git a/recipes/libidn/all/test_package/conanfile.py b/recipes/libidn/all/test_package/conanfile.py index cb12626fbf45b..441cef7471a37 100644 --- a/recipes/libidn/all/test_package/conanfile.py +++ b/recipes/libidn/all/test_package/conanfile.py @@ -3,27 +3,19 @@ from conan import ConanFile from conan.tools.build import can_run from conan.tools.cmake import cmake_layout, CMake -from conan.tools.env import VirtualRunEnv class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "CMakeDeps", "CMakeToolchain" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" test_type = "explicit" def requirements(self): - self.requires(self.tested_reference_str) - - def build_requirements(self): - self.tool_requires(self.tested_reference_str) + self.requires(self.tested_reference_str, run=True) def layout(self): cmake_layout(self) - def generate(self): - VirtualRunEnv(self).generate(scope="build") - VirtualRunEnv(self).generate(scope="run") - def build(self): cmake = CMake(self) cmake.configure() @@ -31,7 +23,7 @@ def build(self): def test(self): if can_run(self): - self.run("idn --help") + self.run("idn --help", env="conanrun") bin_path = os.path.join(self.cpp.build.bindir, "test_package") self.run(bin_path, env="conanrun") From e64a60831f342417133b3cbd9d5f19df5d81bc5f Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 12 Dec 2023 15:45:19 +0200 Subject: [PATCH 6/6] libidn: tc.extra_cflags.append("-FS") --- recipes/libidn/all/conanfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/recipes/libidn/all/conanfile.py b/recipes/libidn/all/conanfile.py index a73c08f5c01cb..2512e8efab52b 100644 --- a/recipes/libidn/all/conanfile.py +++ b/recipes/libidn/all/conanfile.py @@ -86,6 +86,7 @@ def generate(self): "--disable-rpath", ] if is_msvc(self): + tc.extra_cflags.append("-FS") tc.extra_cxxflags.append("-FS") tc.generate()