From 38c999c1b4a73071751ed59b7d0d5b40c4e18128 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Fri, 28 Jan 2022 21:59:10 +0100 Subject: [PATCH 1/5] modernize --- recipes/mpir/all/conanfile.py | 56 ++++++++++++---------- recipes/mpir/all/test_package/conanfile.py | 4 +- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/recipes/mpir/all/conanfile.py b/recipes/mpir/all/conanfile.py index aa3327be9108e..ed249de55700a 100644 --- a/recipes/mpir/all/conanfile.py +++ b/recipes/mpir/all/conanfile.py @@ -1,10 +1,11 @@ +from conan.tools.microsoft import msvc_runtime_flag from conans import ConanFile, tools, AutoToolsBuildEnvironment, MSBuild from conans.errors import ConanInvalidConfiguration import os -import glob required_conan_version = ">=1.33.0" + class MpirConan(ConanFile): name = "mpir" description = "MPIR is a highly optimised library for bignum arithmetic" \ @@ -13,18 +14,19 @@ class MpirConan(ConanFile): url = "https://github.com/conan-io/conan-center-index" homepage = "http://mpir.org/" license = "LGPL-3.0-or-later" - settings = "os", "compiler", "arch", "build_type" + + settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], "enable_cxx": [True, False], - "enable_gmpcompat": [True, False] + "enable_gmpcompat": [True, False], } default_options = { "shared": False, "fPIC": True, "enable_cxx": True, - "enable_gmpcompat": True + "enable_gmpcompat": True, } _autotools = None @@ -33,6 +35,14 @@ class MpirConan(ConanFile): def _source_subfolder(self): return "source_subfolder" + @property + def _settings_build(self): + return getattr(self, "settings_build", self.settings) + + @property + def _is_msvc(self): + return str(self.settings.compiler) in ["Visual Studio", "msvc"] + def config_options(self): if self.settings.os == "Windows": del self.options.fPIC @@ -40,27 +50,23 @@ def config_options(self): def configure(self): if self.options.shared: del self.options.fPIC - if self.settings.compiler == "Visual Studio" and self.options.shared: + if self._is_msvc and self.options.shared: del self.options.enable_cxx if not self.options.get_safe("enable_cxx", False): del self.settings.compiler.libcxx del self.settings.compiler.cppstd - @property - def _settings_build(self): - return getattr(self, "settings_build", self.settings) + def validate(self): + if hasattr(self, "settings_build") and tools.cross_building(self, skip_x64_x86=True): + raise ConanInvalidConfiguration("Cross-building doesn't work (yet)") def build_requirements(self): self.build_requires("yasm/1.3.0") - if self.settings.compiler != "Visual Studio": + if not self._is_msvc: self.build_requires("m4/1.4.19") if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") - def validate(self): - if hasattr(self, "settings_build") and tools.cross_building(self, skip_x64_x86=True): - raise ConanInvalidConfiguration("Cross-building doesn't work (yet)") - def source(self): tools.get(keep_permissions=True, **self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder) @@ -88,15 +94,15 @@ def _vcxproj_paths(self): return vcxproj_paths def _build_visual_studio(self): - if "MD" in self.settings.compiler.runtime and not self.options.shared: # RuntimeLibrary only defined in lib props files - props_path = os.path.join(self._source_subfolder, "build.vc", - "mpir_{}_{}.props".format(str(self.settings.build_type).lower(), self._dll_or_lib)) - if self.settings.build_type == "Debug": - tools.replace_in_file(props_path, "MultiThreadedDebug", - "MultiThreadedDebugDLL") - else: - tools.replace_in_file(props_path, "MultiThreaded", - "MultiThreadedDLL") + if "MD" in msvc_runtime_flag(self) and not self.options.shared: # RuntimeLibrary only defined in lib props files + props_path = os.path.join(self._source_subfolder, "build.vc", + "mpir_{}_{}.props".format(str(self.settings.build_type).lower(), self._dll_or_lib)) + if self.settings.build_type == "Debug": + tools.replace_in_file(props_path, "MultiThreadedDebug", + "MultiThreadedDebugDLL") + else: + tools.replace_in_file(props_path, "MultiThreaded", + "MultiThreadedDLL") msbuild = MSBuild(self) for vcxproj_path in self._vcxproj_paths: msbuild.build(vcxproj_path, platforms=self._platforms, upgrade_project=False) @@ -121,7 +127,7 @@ def _configure_autotools(self): return self._autotools def build(self): - if self.settings.compiler == "Visual Studio": + if self._is_msvc: self._build_visual_studio() else: with tools.chdir(self._source_subfolder): @@ -130,7 +136,7 @@ def build(self): def package(self): self.copy("COPYING*", dst="licenses", src=self._source_subfolder) - if self.settings.compiler == "Visual Studio": + if self._is_msvc: lib_folder = os.path.join(self._source_subfolder, self._dll_or_lib, self._platforms.get(str(self.settings.arch)), str(self.settings.build_type)) @@ -154,7 +160,7 @@ def package_info(self): if self.options.get_safe("enable_cxx"): self.cpp_info.libs.append("mpirxx") self.cpp_info.libs.append("mpir") - if self.options.enable_gmpcompat and self.settings.compiler != "Visual Studio": + if self.options.enable_gmpcompat and not self._is_msvc: if self.options.get_safe("enable_cxx"): self.cpp_info.libs.append("gmpxx") self.cpp_info.libs.append("gmp") diff --git a/recipes/mpir/all/test_package/conanfile.py b/recipes/mpir/all/test_package/conanfile.py index bd7165a553cf4..5c09494bc67c0 100644 --- a/recipes/mpir/all/test_package/conanfile.py +++ b/recipes/mpir/all/test_package/conanfile.py @@ -3,7 +3,7 @@ class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" + settings = "os", "arch", "compiler", "build_type" generators = "cmake" def build(self): @@ -12,6 +12,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self.settings): + if not tools.cross_building(self): bin_path = os.path.join("bin", "test_package") self.run(bin_path, run_environment=True) From 0accaad15fa6d0a5d70f4337a2b92f4733584341 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Fri, 28 Jan 2022 22:01:21 +0100 Subject: [PATCH 2/5] relocatable shared lib on macOS --- recipes/mpir/all/conanfile.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/recipes/mpir/all/conanfile.py b/recipes/mpir/all/conanfile.py index ed249de55700a..7922999e9348e 100644 --- a/recipes/mpir/all/conanfile.py +++ b/recipes/mpir/all/conanfile.py @@ -131,6 +131,8 @@ def build(self): self._build_visual_studio() else: with tools.chdir(self._source_subfolder): + # relocatable shared lib on macOS + tools.replace_in_file("configure", "-install_name \\$rpath/", "-install_name @rpath/") autotools = self._configure_autotools() autotools.make() From dab4b88711dda62f30dd4525d64a5f865f9b7769 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Fri, 28 Jan 2022 22:14:37 +0100 Subject: [PATCH 3/5] mpir provides gmp API if enable_gmpcompat enabled --- recipes/mpir/all/conanfile.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/recipes/mpir/all/conanfile.py b/recipes/mpir/all/conanfile.py index 7922999e9348e..c0ee05f1458a7 100644 --- a/recipes/mpir/all/conanfile.py +++ b/recipes/mpir/all/conanfile.py @@ -15,6 +15,8 @@ class MpirConan(ConanFile): homepage = "http://mpir.org/" license = "LGPL-3.0-or-later" + provides = [] + settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], @@ -55,6 +57,8 @@ def configure(self): if not self.options.get_safe("enable_cxx", False): del self.settings.compiler.libcxx del self.settings.compiler.cppstd + if self.options.enable_gmpcompat: + self.provides.append("gmp") def validate(self): if hasattr(self, "settings_build") and tools.cross_building(self, skip_x64_x86=True): From 6186e4add4540cb915016270f42d428c9ce8bc90 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Sat, 29 Jan 2022 11:03:08 +0100 Subject: [PATCH 4/5] proper runtime mapping Co-authored-by: Anonymous Maarten --- recipes/mpir/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/mpir/all/conanfile.py b/recipes/mpir/all/conanfile.py index c0ee05f1458a7..aab4906e89d3b 100644 --- a/recipes/mpir/all/conanfile.py +++ b/recipes/mpir/all/conanfile.py @@ -101,7 +101,7 @@ def _build_visual_studio(self): if "MD" in msvc_runtime_flag(self) and not self.options.shared: # RuntimeLibrary only defined in lib props files props_path = os.path.join(self._source_subfolder, "build.vc", "mpir_{}_{}.props".format(str(self.settings.build_type).lower(), self._dll_or_lib)) - if self.settings.build_type == "Debug": + if "d" in msvc_runtime_flag(self): tools.replace_in_file(props_path, "MultiThreadedDebug", "MultiThreadedDebugDLL") else: From 0ae986ec5c932ec4e8dc35cb02d6ef38a7321842 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Sat, 29 Jan 2022 11:27:40 +0100 Subject: [PATCH 5/5] improve vc runtime handling --- recipes/mpir/all/conanfile.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/recipes/mpir/all/conanfile.py b/recipes/mpir/all/conanfile.py index aab4906e89d3b..a940cb6253fb3 100644 --- a/recipes/mpir/all/conanfile.py +++ b/recipes/mpir/all/conanfile.py @@ -98,15 +98,18 @@ def _vcxproj_paths(self): return vcxproj_paths def _build_visual_studio(self): - if "MD" in msvc_runtime_flag(self) and not self.options.shared: # RuntimeLibrary only defined in lib props files + if not self.options.shared: # RuntimeLibrary only defined in lib props files + build_type = "debug" if self.settings.build_type == "Debug" else "release" props_path = os.path.join(self._source_subfolder, "build.vc", - "mpir_{}_{}.props".format(str(self.settings.build_type).lower(), self._dll_or_lib)) - if "d" in msvc_runtime_flag(self): - tools.replace_in_file(props_path, "MultiThreadedDebug", - "MultiThreadedDebugDLL") - else: - tools.replace_in_file(props_path, "MultiThreaded", - "MultiThreadedDLL") + "mpir_{}_lib.props".format(build_type)) + old_runtime = "MultiThreaded{}".format( + "Debug" if build_type == "debug" else "", + ) + new_runtime = "MultiThreaded{}{}".format( + "Debug" if "d" in msvc_runtime_flag(self) else "", + "DLL" if "MD" in msvc_runtime_flag(self) else "", + ) + tools.replace_in_file(props_path, old_runtime, new_runtime) msbuild = MSBuild(self) for vcxproj_path in self._vcxproj_paths: msbuild.build(vcxproj_path, platforms=self._platforms, upgrade_project=False)