diff --git a/recipes/mpir/all/conanfile.py b/recipes/mpir/all/conanfile.py index 433a25ab49631..7d860cd312531 100644 --- a/recipes/mpir/all/conanfile.py +++ b/recipes/mpir/all/conanfile.py @@ -1,11 +1,12 @@ +from conan.tools.microsoft import msvc_runtime_flag from conans import ConanFile, tools, AutoToolsBuildEnvironment, MSBuild from conans.errors import ConanInvalidConfiguration import contextlib 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" \ @@ -14,18 +15,21 @@ 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" + + provides = [] + + 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 @@ -34,6 +38,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 @@ -41,19 +53,21 @@ 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 + if self.options.enable_gmpcompat: + self.provides.append("gmp") - @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") @@ -85,15 +99,18 @@ 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 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_{}_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) @@ -134,16 +151,18 @@ 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), self._build_context(): + # relocatable shared lib on macOS + tools.replace_in_file("configure", "-install_name \\$rpath/", "-install_name @rpath/") autotools = self._configure_autotools() autotools.make() 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)) @@ -167,7 +186,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)